"Fossies" - the Fresh Open Source Software Archive

Member "src/Volume/VolumeInfo.cpp" (10 Oct 2018, 5847 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "VolumeInfo.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #include "Common/Tcdefs.h"
   14 #include "VolumeInfo.h"
   15 #include "Platform/SerializerFactory.h"
   16 
   17 namespace VeraCrypt
   18 {
   19     void VolumeInfo::Deserialize (shared_ptr <Stream> stream)
   20     {
   21         Serializer sr (stream);
   22 
   23         sr.Deserialize ("ProgramVersion", ProgramVersion);
   24         AuxMountPoint = sr.DeserializeWString ("AuxMountPoint");
   25         sr.Deserialize ("EncryptionAlgorithmBlockSize", EncryptionAlgorithmBlockSize);
   26         sr.Deserialize ("EncryptionAlgorithmKeySize", EncryptionAlgorithmKeySize);
   27         sr.Deserialize ("EncryptionAlgorithmMinBlockSize", EncryptionAlgorithmMinBlockSize);
   28         EncryptionAlgorithmName = sr.DeserializeWString ("EncryptionAlgorithmName");
   29         EncryptionModeName = sr.DeserializeWString ("EncryptionModeName");
   30         sr.Deserialize ("HeaderCreationTime", HeaderCreationTime);
   31         sr.Deserialize ("HiddenVolumeProtectionTriggered", HiddenVolumeProtectionTriggered);
   32         LoopDevice = sr.DeserializeWString ("LoopDevice");
   33 
   34         if (ProgramVersion >= 0x10b)
   35             sr.Deserialize ("MinRequiredProgramVersion", MinRequiredProgramVersion);
   36 
   37         MountPoint = sr.DeserializeWString ("MountPoint");
   38         Path = sr.DeserializeWString ("Path");
   39         sr.Deserialize ("Pkcs5IterationCount", Pkcs5IterationCount);
   40         Pkcs5PrfName = sr.DeserializeWString ("Pkcs5PrfName");
   41         Protection = static_cast <VolumeProtection::Enum> (sr.DeserializeInt32 ("Protection"));
   42         sr.Deserialize ("SerialInstanceNumber", SerialInstanceNumber);
   43         sr.Deserialize ("Size", Size);
   44         sr.Deserialize ("SlotNumber", SlotNumber);
   45 
   46         if (ProgramVersion >= 0x10b)
   47             sr.Deserialize ("SystemEncryption", SystemEncryption);
   48 
   49         if (ProgramVersion >= 0x10b)
   50             sr.Deserialize ("TopWriteOffset", TopWriteOffset);
   51 
   52         sr.Deserialize ("TotalDataRead", TotalDataRead);
   53         sr.Deserialize ("TotalDataWritten", TotalDataWritten);
   54         Type = static_cast <VolumeType::Enum> (sr.DeserializeInt32 ("Type"));
   55         VirtualDevice = sr.DeserializeWString ("VirtualDevice");
   56         sr.Deserialize ("VolumeCreationTime", VolumeCreationTime);
   57         sr.Deserialize ("TrueCryptMode", TrueCryptMode);
   58         sr.Deserialize ("Pim", Pim);
   59     }
   60 
   61     bool VolumeInfo::FirstVolumeMountedAfterSecond (shared_ptr <VolumeInfo> first, shared_ptr <VolumeInfo> second)
   62     {
   63         return first->SerialInstanceNumber > second->SerialInstanceNumber;
   64     }
   65 
   66     void VolumeInfo::Serialize (shared_ptr <Stream> stream) const
   67     {
   68         Serializable::Serialize (stream);
   69         Serializer sr (stream);
   70 
   71         const uint32 version = VERSION_NUM;
   72         sr.Serialize ("ProgramVersion", version);
   73         sr.Serialize ("AuxMountPoint", wstring (AuxMountPoint));
   74         sr.Serialize ("EncryptionAlgorithmBlockSize", EncryptionAlgorithmBlockSize);
   75         sr.Serialize ("EncryptionAlgorithmKeySize", EncryptionAlgorithmKeySize);
   76         sr.Serialize ("EncryptionAlgorithmMinBlockSize", EncryptionAlgorithmMinBlockSize);
   77         sr.Serialize ("EncryptionAlgorithmName", EncryptionAlgorithmName);
   78         sr.Serialize ("EncryptionModeName", EncryptionModeName);
   79         sr.Serialize ("HeaderCreationTime", HeaderCreationTime);
   80         sr.Serialize ("HiddenVolumeProtectionTriggered", HiddenVolumeProtectionTriggered);
   81         sr.Serialize ("LoopDevice", wstring (LoopDevice));
   82         sr.Serialize ("MinRequiredProgramVersion", MinRequiredProgramVersion);
   83         sr.Serialize ("MountPoint", wstring (MountPoint));
   84         sr.Serialize ("Path", wstring (Path));
   85         sr.Serialize ("Pkcs5IterationCount", Pkcs5IterationCount);
   86         sr.Serialize ("Pkcs5PrfName", Pkcs5PrfName);
   87         sr.Serialize ("Protection", static_cast <uint32> (Protection));
   88         sr.Serialize ("SerialInstanceNumber", SerialInstanceNumber);
   89         sr.Serialize ("Size", Size);
   90         sr.Serialize ("SlotNumber", SlotNumber);
   91         sr.Serialize ("SystemEncryption", SystemEncryption);
   92         sr.Serialize ("TopWriteOffset", TopWriteOffset);
   93         sr.Serialize ("TotalDataRead", TotalDataRead);
   94         sr.Serialize ("TotalDataWritten", TotalDataWritten);
   95         sr.Serialize ("Type", static_cast <uint32> (Type));
   96         sr.Serialize ("VirtualDevice", wstring (VirtualDevice));
   97         sr.Serialize ("VolumeCreationTime", VolumeCreationTime);
   98         sr.Serialize ("TrueCryptMode", TrueCryptMode);
   99         sr.Serialize ("Pim", Pim);
  100     }
  101 
  102     void VolumeInfo::Set (const Volume &volume)
  103     {
  104         EncryptionAlgorithmBlockSize = static_cast <uint32> (volume.GetEncryptionAlgorithm()->GetMaxBlockSize());
  105         EncryptionAlgorithmKeySize = static_cast <uint32> (volume.GetEncryptionAlgorithm()->GetKeySize());
  106         EncryptionAlgorithmMinBlockSize = static_cast <uint32> (volume.GetEncryptionAlgorithm()->GetMinBlockSize());
  107         EncryptionAlgorithmName = volume.GetEncryptionAlgorithm()->GetName();
  108         EncryptionModeName = volume.GetEncryptionMode()->GetName();
  109         HeaderCreationTime = volume.GetHeaderCreationTime();
  110         VolumeCreationTime = volume.GetVolumeCreationTime();
  111         HiddenVolumeProtectionTriggered = volume.IsHiddenVolumeProtectionTriggered();
  112         MinRequiredProgramVersion = volume.GetHeader()->GetRequiredMinProgramVersion();
  113         Path = volume.GetPath();
  114         Pkcs5IterationCount = volume.GetPkcs5Kdf()->GetIterationCount(volume.GetPim ());
  115         Pkcs5PrfName = volume.GetPkcs5Kdf()->GetName();
  116         Protection = volume.GetProtectionType();
  117         Size = volume.GetSize();
  118         SystemEncryption = volume.IsInSystemEncryptionScope();
  119         Type = volume.GetType();
  120         TopWriteOffset = volume.GetTopWriteOffset();
  121         TotalDataRead = volume.GetTotalDataRead();
  122         TotalDataWritten = volume.GetTotalDataWritten();
  123         TrueCryptMode = volume.GetTrueCryptMode();
  124         Pim = volume.GetPim ();
  125     }
  126 
  127     TC_SERIALIZER_FACTORY_ADD_CLASS (VolumeInfo);
  128 }