|
|
1.1 root 1: /*
2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
3:
4: Governed by the TrueCrypt License 2.4 the full text of which is contained
5: in the file License.txt included in TrueCrypt binary and source code
6: distribution packages.
7: */
8:
9: #ifndef TC_HEADER_Volume_Volume
10: #define TC_HEADER_Volume_Volume
11:
12: #include "Platform/Platform.h"
13: #include "Platform/StringConverter.h"
14: #include "EncryptionAlgorithm.h"
15: #include "EncryptionMode.h"
16: #include "Keyfile.h"
17: #include "VolumePassword.h"
18: #include "VolumeException.h"
19: #include "VolumeLayout.h"
20:
21: namespace TrueCrypt
22: {
23: class VolumePath
24: {
25: public:
26: VolumePath () { }
27: VolumePath (const wstring &path) { Data = path; }
28: VolumePath (const FilesystemPath &path) { Data = path; }
29:
30: bool operator== (const VolumePath &other) const { return Data == other.Data; }
31: bool operator!= (const VolumePath &other) const { return Data != other.Data; }
32: operator FilesystemPath () const { return FilesystemPath (Data); }
33: operator string () const { return StringConverter::ToSingle (Data); }
34: operator wstring () const { return Data; }
35:
36: bool IsDevice () const { return FilesystemPath (Data).IsBlockDevice() || FilesystemPath (Data).IsCharacterDevice(); }
37: bool IsEmpty () const { return Data.empty(); }
38:
39: protected:
40: wstring Data;
41: };
42:
43: typedef list <VolumePath> VolumePathList;
44:
45: struct VolumeProtection
46: {
47: enum Enum
48: {
49: None,
50: ReadOnly,
51: HiddenVolumeReadOnly
52: };
53: };
54:
55: class Volume
56: {
57: public:
58: Volume ();
59: virtual ~Volume ();
60:
61: void Close ();
62: shared_ptr <EncryptionAlgorithm> GetEncryptionAlgorithm () const;
63: shared_ptr <EncryptionMode> GetEncryptionMode () const;
64: shared_ptr <File> GetFile () const { return VolumeFile; }
65: uint64 GetHeaderCreationTime () const { return Header->GetHeaderCreationTime(); }
66: VolumePath GetPath () const { return VolumeFile->GetPath(); }
67: VolumeProtection::Enum GetProtectionType () const { return Protection; }
68: shared_ptr <Pkcs5Kdf> GetPkcs5Kdf () const { return Header->GetPkcs5Kdf(); }
69: uint32 GetSaltSize () const { return Header->GetSaltSize(); }
70: size_t GetSectorSize () const { return SectorSize; }
71: uint64 GetSize () const { return VolumeDataSize; }
72: uint64 GetTotalDataRead () const { return TotalDataRead; }
73: uint64 GetTotalDataWritten () const { return TotalDataWritten; }
74: VolumeType::Enum GetType () const { return Type; }
75: uint64 GetVolumeCreationTime () const { return Header->GetVolumeCreationTime(); }
76: bool IsHiddenVolumeProtectionTriggered () const { return HiddenVolumeProtectionTriggered; }
77: void Open (const VolumePath &volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown);
78: void Open (shared_ptr <File> volumeFile, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), VolumeType::Enum volumeType = VolumeType::Unknown);
79: void ReadSectors (const BufferPtr &buffer, uint64 byteOffset);
80: void ReEncryptHeader (const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf);
81: void WriteSectors (const ConstBufferPtr &buffer, uint64 byteOffset);
82:
83: protected:
84: void CheckProtectedRange (uint64 writeHostOffset, uint64 writeLength);
85: void ValidateState () const;
86:
87: shared_ptr <EncryptionAlgorithm> EA;
88: shared_ptr <VolumeHeader> Header;
89: bool HiddenVolumeProtectionTriggered;
90: shared_ptr <VolumeLayout> Layout;
91: uint64 ProtectedRangeStart;
92: uint64 ProtectedRangeEnd;
93: VolumeProtection::Enum Protection;
94: size_t SectorSize;
95: VolumeType::Enum Type;
96: shared_ptr <File> VolumeFile;
97: uint64 VolumeHostSize;
98: uint64 VolumeDataOffset;
99: uint64 VolumeDataSize;
100: uint64 TotalDataRead;
101: uint64 TotalDataWritten;
102:
103: private:
104: Volume (const Volume &);
105: Volume &operator= (const Volume &);
106: };
107: }
108:
109: #endif // TC_HEADER_Volume_Volume
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.