"Fossies" - the Fresh Open Source Software Archive

Member "src/Volume/VolumePassword.h" (10 Oct 2018, 3301 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 "VolumePassword.h" 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 #ifndef TC_HEADER_Encryption_Password
   14 #define TC_HEADER_Encryption_Password
   15 
   16 #include "Platform/Platform.h"
   17 #include "Platform/Serializable.h"
   18 
   19 namespace VeraCrypt
   20 {
   21     class VolumePassword : public Serializable
   22     {
   23     public:
   24         VolumePassword ();
   25         VolumePassword (const byte *password, size_t size) { Set (password, size); }
   26         VolumePassword (const SecureBuffer &password) { Set (password.Ptr (), password.Size ()); }
   27         VolumePassword (const VolumePassword &password) { Set (password); }
   28         virtual ~VolumePassword ();
   29 
   30         bool operator== (const VolumePassword &other) const { return ConstBufferPtr (DataPtr(), Size()).IsDataEqual (ConstBufferPtr (other.DataPtr(), other.Size())); }
   31         bool operator!= (const VolumePassword &other) const { return !(*this == other); }
   32         VolumePassword &operator= (const VolumePassword &password) { Set (password); return *this; }
   33 
   34         operator BufferPtr () const { return BufferPtr (PasswordBuffer); }
   35 
   36         byte *DataPtr () const { return PasswordBuffer; }
   37         bool IsEmpty () const { return PasswordSize == 0; }
   38         size_t Size () const { return PasswordSize; }
   39         void Set (const byte *password, size_t size);
   40         void Set (const VolumePassword &password);
   41 
   42         TC_SERIALIZABLE (VolumePassword);
   43 
   44         static const size_t MaxSize = 64;
   45         static const size_t WarningSizeThreshold = 12;
   46 
   47     protected:
   48         void AllocateBuffer ();
   49 
   50         SecureBuffer PasswordBuffer;
   51 
   52         size_t PasswordSize;
   53     };
   54 
   55     struct PasswordException : public Exception
   56     {
   57     protected:
   58         PasswordException () { }
   59         PasswordException (const string &message) : Exception (message) { }
   60         PasswordException (const string &message, const wstring &subject) : Exception (message, subject) { }
   61     };
   62 
   63     TC_EXCEPTION_DECL (PasswordIncorrect, PasswordException);
   64     TC_EXCEPTION_DECL (PasswordKeyfilesIncorrect, PasswordIncorrect);
   65     TC_EXCEPTION_DECL (PasswordOrKeyboardLayoutIncorrect, PasswordException);
   66     TC_EXCEPTION_DECL (PasswordOrMountOptionsIncorrect, PasswordException);
   67     TC_EXCEPTION_DECL (ProtectionPasswordIncorrect, PasswordIncorrect);
   68     TC_EXCEPTION_DECL (ProtectionPasswordKeyfilesIncorrect, PasswordIncorrect);
   69 
   70 #define TC_EXCEPTION(NAME) TC_EXCEPTION_DECL(NAME,PasswordException)
   71 
   72 #undef TC_EXCEPTION_SET
   73 #define TC_EXCEPTION_SET \
   74     TC_EXCEPTION_NODECL (PasswordIncorrect); \
   75     TC_EXCEPTION_NODECL (PasswordKeyfilesIncorrect); \
   76     TC_EXCEPTION_NODECL (PasswordOrKeyboardLayoutIncorrect); \
   77     TC_EXCEPTION_NODECL (PasswordOrMountOptionsIncorrect); \
   78     TC_EXCEPTION_NODECL (ProtectionPasswordIncorrect); \
   79     TC_EXCEPTION_NODECL (ProtectionPasswordKeyfilesIncorrect); \
   80     TC_EXCEPTION (PasswordEmpty); \
   81     TC_EXCEPTION (PasswordTooLong); \
   82     TC_EXCEPTION (PasswordUTF8TooLong); \
   83     TC_EXCEPTION (PasswordUTF8Invalid); \
   84     TC_EXCEPTION (UnportablePassword);
   85 
   86     TC_EXCEPTION_SET;
   87 
   88 #undef TC_EXCEPTION
   89 }
   90 
   91 #endif // TC_HEADER_Encryption_Password