13b3884d9SMichael Lotz /* 23b3884d9SMichael Lotz * Copyright 2011, Haiku, Inc. 33b3884d9SMichael Lotz * Distributed under the terms of the MIT License. 43b3884d9SMichael Lotz */ 53b3884d9SMichael Lotz #ifndef _KEY_H 63b3884d9SMichael Lotz #define _KEY_H 73b3884d9SMichael Lotz 83b3884d9SMichael Lotz 93b3884d9SMichael Lotz #include <DataIO.h> 103b3884d9SMichael Lotz #include <Message.h> 113b3884d9SMichael Lotz #include <ObjectList.h> 123b3884d9SMichael Lotz #include <String.h> 133b3884d9SMichael Lotz 143b3884d9SMichael Lotz 15dc1acef8SMichael Lotz enum BKeyPurpose { 16dc1acef8SMichael Lotz B_KEY_PURPOSE_ANY, 17dc1acef8SMichael Lotz B_KEY_PURPOSE_GENERIC, 18dc1acef8SMichael Lotz B_KEY_PURPOSE_WEB, 19dc1acef8SMichael Lotz B_KEY_PURPOSE_NETWORK, 20dc1acef8SMichael Lotz B_KEY_PURPOSE_VOLUME 21dc1acef8SMichael Lotz }; 22dc1acef8SMichael Lotz 23dc1acef8SMichael Lotz 24dc1acef8SMichael Lotz enum BKeyType { 25dc1acef8SMichael Lotz B_KEY_TYPE_ANY, 26dc1acef8SMichael Lotz B_KEY_TYPE_GENERIC, 27dc1acef8SMichael Lotz B_KEY_TYPE_PASSWORD, 28dc1acef8SMichael Lotz B_KEY_TYPE_CERTIFICATE 293b3884d9SMichael Lotz }; 303b3884d9SMichael Lotz 313b3884d9SMichael Lotz 323b3884d9SMichael Lotz class BKey { 333b3884d9SMichael Lotz public: 343b3884d9SMichael Lotz BKey(); 35dc1acef8SMichael Lotz BKey(BKeyPurpose purpose, 363b3884d9SMichael Lotz const char* identifier, 37dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL, 38dc1acef8SMichael Lotz const uint8* data = NULL, 39dc1acef8SMichael Lotz size_t length = 0); 403b3884d9SMichael Lotz BKey(BKey& other); 413b3884d9SMichael Lotz virtual ~BKey(); 423b3884d9SMichael Lotz 43dc1acef8SMichael Lotz virtual BKeyType Type() const { return B_KEY_TYPE_GENERIC; }; 44dc1acef8SMichael Lotz 453b3884d9SMichael Lotz void Unset(); 463b3884d9SMichael Lotz 47dc1acef8SMichael Lotz status_t SetTo(BKeyPurpose purpose, 483b3884d9SMichael Lotz const char* identifier, 49dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL, 50dc1acef8SMichael Lotz const uint8* data = NULL, 51dc1acef8SMichael Lotz size_t length = 0); 523b3884d9SMichael Lotz 53dc1acef8SMichael Lotz void SetPurpose(BKeyPurpose purpose); 54dc1acef8SMichael Lotz BKeyPurpose Purpose() const; 553b3884d9SMichael Lotz 563b3884d9SMichael Lotz void SetIdentifier(const char* identifier); 573b3884d9SMichael Lotz const char* Identifier() const; 583b3884d9SMichael Lotz 593b3884d9SMichael Lotz void SetSecondaryIdentifier(const char* identifier); 603b3884d9SMichael Lotz const char* SecondaryIdentifier() const; 613b3884d9SMichael Lotz 62dc1acef8SMichael Lotz status_t SetData(const uint8* data, size_t length); 63dc1acef8SMichael Lotz size_t DataLength() const; 64dc1acef8SMichael Lotz const uint8* Data() const; 65dc1acef8SMichael Lotz status_t GetData(uint8* buffer, size_t bufferSize) const; 663b3884d9SMichael Lotz 673b3884d9SMichael Lotz const char* Owner() const; 683b3884d9SMichael Lotz bigtime_t CreationTime() const; 693b3884d9SMichael Lotz bool IsRegistered() const; 703b3884d9SMichael Lotz 713b3884d9SMichael Lotz BKey& operator=(const BKey& other); 723b3884d9SMichael Lotz 733b3884d9SMichael Lotz bool operator==(const BKey& other) const; 743b3884d9SMichael Lotz bool operator!=(const BKey& other) const; 753b3884d9SMichael Lotz 76*1c399649SMichael Lotz protected: 77*1c399649SMichael Lotz virtual status_t _Flatten(BMessage& message) const; 78*1c399649SMichael Lotz virtual status_t _Unflatten(const BMessage& message); 79*1c399649SMichael Lotz 803b3884d9SMichael Lotz private: 81*1c399649SMichael Lotz friend class BKeyStore; 82*1c399649SMichael Lotz 83dc1acef8SMichael Lotz BKeyPurpose fPurpose; 843b3884d9SMichael Lotz BString fIdentifier; 853b3884d9SMichael Lotz BString fSecondaryIdentifier; 863b3884d9SMichael Lotz BString fOwner; 873b3884d9SMichael Lotz bigtime_t fCreationTime; 88dc1acef8SMichael Lotz mutable BMallocIO fData; 893b3884d9SMichael Lotz bool fRegistered; 903b3884d9SMichael Lotz }; 913b3884d9SMichael Lotz 923b3884d9SMichael Lotz 93dc1acef8SMichael Lotz class BPasswordKey : public BKey { 94dc1acef8SMichael Lotz public: 95dc1acef8SMichael Lotz BPasswordKey(); 96dc1acef8SMichael Lotz BPasswordKey(const char* password, 97dc1acef8SMichael Lotz BKeyPurpose purpose, const char* identifier, 98dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL); 99dc1acef8SMichael Lotz BPasswordKey(BPasswordKey& other); 100dc1acef8SMichael Lotz virtual ~BPasswordKey(); 101dc1acef8SMichael Lotz 102dc1acef8SMichael Lotz virtual BKeyType Type() const { return B_KEY_TYPE_PASSWORD; }; 103dc1acef8SMichael Lotz 104dc1acef8SMichael Lotz status_t SetTo(const char* password, 105dc1acef8SMichael Lotz BKeyPurpose purpose, 106dc1acef8SMichael Lotz const char* identifier, 107dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL); 108dc1acef8SMichael Lotz 109dc1acef8SMichael Lotz status_t SetPassword(const char* password); 110dc1acef8SMichael Lotz const char* Password() const; 111dc1acef8SMichael Lotz }; 112dc1acef8SMichael Lotz 1133b3884d9SMichael Lotz #endif // _KEY_H 114