"Fossies" - the Fresh Open Source Software Archive

Member "src/Core/MountOptions.cpp" (10 Oct 2018, 5850 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 "MountOptions.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 "MountOptions.h"
   14 #include "Platform/MemoryStream.h"
   15 #include "Platform/SerializerFactory.h"
   16 
   17 namespace VeraCrypt
   18 {
   19     void MountOptions::CopyFrom (const MountOptions &other)
   20     {
   21 #define TC_CLONE(NAME) NAME = other.NAME
   22 #define TC_CLONE_SHARED(TYPE,NAME) NAME = other.NAME ? make_shared <TYPE> (*other.NAME) : shared_ptr <TYPE> ()
   23 
   24         TC_CLONE (CachePassword);
   25         TC_CLONE (FilesystemOptions);
   26         TC_CLONE (FilesystemType);
   27         TC_CLONE_SHARED (KeyfileList, Keyfiles);
   28         TC_CLONE_SHARED (DirectoryPath, MountPoint);
   29         TC_CLONE (NoFilesystem);
   30         TC_CLONE (NoHardwareCrypto);
   31         TC_CLONE (NoKernelCrypto);
   32         TC_CLONE_SHARED (VolumePassword, Password);
   33         TC_CLONE (Pim);
   34         if (other.Kdf)
   35         {
   36             Kdf.reset(other.Kdf->Clone());
   37         }
   38         else
   39             Kdf.reset();
   40         TC_CLONE_SHARED (VolumePath, Path);
   41         TC_CLONE (PartitionInSystemEncryptionScope);
   42         TC_CLONE (PreserveTimestamps);
   43         TC_CLONE (Protection);
   44         TC_CLONE_SHARED (VolumePassword, ProtectionPassword);
   45         TC_CLONE (ProtectionPim);
   46         if (other.ProtectionKdf)
   47             ProtectionKdf.reset(other.ProtectionKdf->Clone());
   48         else
   49             ProtectionKdf.reset();
   50         TC_CLONE_SHARED (KeyfileList, ProtectionKeyfiles);
   51         TC_CLONE (Removable);
   52         TC_CLONE (SharedAccessAllowed);
   53         TC_CLONE (SlotNumber);
   54         TC_CLONE (UseBackupHeaders);
   55         TC_CLONE (TrueCryptMode);
   56     }
   57 
   58     void MountOptions::Deserialize (shared_ptr <Stream> stream)
   59     {
   60         Serializer sr (stream);
   61         wstring nameValue;
   62 
   63         sr.Deserialize ("CachePassword", CachePassword);
   64         sr.Deserialize ("FilesystemOptions", FilesystemOptions);
   65         sr.Deserialize ("FilesystemType", FilesystemType);
   66 
   67         Keyfiles = Keyfile::DeserializeList (stream, "Keyfiles");
   68 
   69         if (!sr.DeserializeBool ("MountPointNull"))
   70             MountPoint.reset (new DirectoryPath (sr.DeserializeWString ("MountPoint")));
   71         else
   72             MountPoint.reset();
   73 
   74         sr.Deserialize ("NoFilesystem", NoFilesystem);
   75         sr.Deserialize ("NoHardwareCrypto", NoHardwareCrypto);
   76         sr.Deserialize ("NoKernelCrypto", NoKernelCrypto);
   77 
   78         if (!sr.DeserializeBool ("PasswordNull"))
   79             Password = Serializable::DeserializeNew <VolumePassword> (stream);
   80         else
   81             Password.reset();
   82 
   83         if (!sr.DeserializeBool ("PathNull"))
   84             Path.reset (new VolumePath (sr.DeserializeWString ("Path")));
   85         else
   86             Path.reset();
   87 
   88         sr.Deserialize ("PartitionInSystemEncryptionScope", PartitionInSystemEncryptionScope);
   89         sr.Deserialize ("PreserveTimestamps", PreserveTimestamps);
   90 
   91         Protection = static_cast <VolumeProtection::Enum> (sr.DeserializeInt32 ("Protection"));
   92 
   93         if (!sr.DeserializeBool ("ProtectionPasswordNull"))
   94             ProtectionPassword = Serializable::DeserializeNew <VolumePassword> (stream);
   95         else
   96             ProtectionPassword.reset();
   97 
   98         ProtectionKeyfiles = Keyfile::DeserializeList (stream, "ProtectionKeyfiles");
   99         sr.Deserialize ("Removable", Removable);
  100         sr.Deserialize ("SharedAccessAllowed", SharedAccessAllowed);
  101         sr.Deserialize ("SlotNumber", SlotNumber);
  102         sr.Deserialize ("UseBackupHeaders", UseBackupHeaders);
  103 
  104         sr.Deserialize ("TrueCryptMode", TrueCryptMode);
  105 
  106         try
  107         {
  108             if (!sr.DeserializeBool ("KdfNull"))
  109             {
  110                 sr.Deserialize ("Kdf", nameValue);
  111                 Kdf = Pkcs5Kdf::GetAlgorithm (nameValue, TrueCryptMode);
  112             }
  113         }
  114         catch(...) {}
  115 
  116         try
  117         {
  118             if (!sr.DeserializeBool ("ProtectionKdfNull"))
  119             {
  120                 sr.Deserialize ("ProtectionKdf", nameValue);
  121                 ProtectionKdf = Pkcs5Kdf::GetAlgorithm (nameValue, TrueCryptMode);
  122             }
  123         }
  124         catch(...) {}
  125 
  126         sr.Deserialize ("Pim", Pim);
  127         sr.Deserialize ("ProtectionPim", ProtectionPim);
  128     }
  129 
  130     void MountOptions::Serialize (shared_ptr <Stream> stream) const
  131     {
  132         Serializable::Serialize (stream);
  133         Serializer sr (stream);
  134 
  135         sr.Serialize ("CachePassword", CachePassword);
  136         sr.Serialize ("FilesystemOptions", FilesystemOptions);
  137         sr.Serialize ("FilesystemType", FilesystemType);
  138         Keyfile::SerializeList (stream, "Keyfiles", Keyfiles);
  139 
  140         sr.Serialize ("MountPointNull", MountPoint == nullptr);
  141         if (MountPoint)
  142             sr.Serialize ("MountPoint", wstring (*MountPoint));
  143 
  144         sr.Serialize ("NoFilesystem", NoFilesystem);
  145         sr.Serialize ("NoHardwareCrypto", NoHardwareCrypto);
  146         sr.Serialize ("NoKernelCrypto", NoKernelCrypto);
  147 
  148         sr.Serialize ("PasswordNull", Password == nullptr);
  149         if (Password)
  150             Password->Serialize (stream);
  151 
  152         sr.Serialize ("PathNull", Path == nullptr);
  153         if (Path)
  154             sr.Serialize ("Path", wstring (*Path));
  155 
  156         sr.Serialize ("PartitionInSystemEncryptionScope", PartitionInSystemEncryptionScope);
  157         sr.Serialize ("PreserveTimestamps", PreserveTimestamps);
  158         sr.Serialize ("Protection", static_cast <uint32> (Protection));
  159 
  160         sr.Serialize ("ProtectionPasswordNull", ProtectionPassword == nullptr);
  161         if (ProtectionPassword)
  162             ProtectionPassword->Serialize (stream);
  163 
  164         Keyfile::SerializeList (stream, "ProtectionKeyfiles", ProtectionKeyfiles);
  165         sr.Serialize ("Removable", Removable);
  166         sr.Serialize ("SharedAccessAllowed", SharedAccessAllowed);
  167         sr.Serialize ("SlotNumber", SlotNumber);
  168         sr.Serialize ("UseBackupHeaders", UseBackupHeaders);
  169 
  170         sr.Serialize ("TrueCryptMode", TrueCryptMode);
  171 
  172         sr.Serialize ("KdfNull", Kdf == nullptr);
  173         if (Kdf)
  174             sr.Serialize ("Kdf", Kdf->GetName());
  175 
  176         sr.Serialize ("ProtectionKdfNull", ProtectionKdf == nullptr);
  177         if (ProtectionKdf)
  178             sr.Serialize ("ProtectionKdf", ProtectionKdf->GetName());
  179 
  180         sr.Serialize ("Pim", Pim);
  181         sr.Serialize ("ProtectionPim", ProtectionPim);
  182     }
  183 
  184     TC_SERIALIZER_FACTORY_ADD_CLASS (MountOptions);
  185 }