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, 18d962e210SMichael Lotz B_KEY_PURPOSE_KEYRING, 19dc1acef8SMichael Lotz B_KEY_PURPOSE_WEB, 20dc1acef8SMichael Lotz B_KEY_PURPOSE_NETWORK, 21dc1acef8SMichael Lotz B_KEY_PURPOSE_VOLUME 22dc1acef8SMichael Lotz }; 23dc1acef8SMichael Lotz 24dc1acef8SMichael Lotz 25dc1acef8SMichael Lotz enum BKeyType { 26dc1acef8SMichael Lotz B_KEY_TYPE_ANY, 27dc1acef8SMichael Lotz B_KEY_TYPE_GENERIC, 28dc1acef8SMichael Lotz B_KEY_TYPE_PASSWORD, 29dc1acef8SMichael Lotz B_KEY_TYPE_CERTIFICATE 303b3884d9SMichael Lotz }; 313b3884d9SMichael Lotz 323b3884d9SMichael Lotz 333b3884d9SMichael Lotz class BKey { 343b3884d9SMichael Lotz public: 353b3884d9SMichael Lotz BKey(); 36dc1acef8SMichael Lotz BKey(BKeyPurpose purpose, 373b3884d9SMichael Lotz const char* identifier, 38dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL, 39dc1acef8SMichael Lotz const uint8* data = NULL, 40dc1acef8SMichael Lotz size_t length = 0); 413b3884d9SMichael Lotz BKey(BKey& other); 423b3884d9SMichael Lotz virtual ~BKey(); 433b3884d9SMichael Lotz Type()44dc1acef8SMichael Lotz virtual BKeyType Type() const { return B_KEY_TYPE_GENERIC; }; 45dc1acef8SMichael Lotz 463b3884d9SMichael Lotz void Unset(); 473b3884d9SMichael Lotz 48dc1acef8SMichael Lotz status_t SetTo(BKeyPurpose purpose, 493b3884d9SMichael Lotz const char* identifier, 50dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL, 51dc1acef8SMichael Lotz const uint8* data = NULL, 52dc1acef8SMichael Lotz size_t length = 0); 533b3884d9SMichael Lotz 54dc1acef8SMichael Lotz void SetPurpose(BKeyPurpose purpose); 55dc1acef8SMichael Lotz BKeyPurpose Purpose() const; 563b3884d9SMichael Lotz 573b3884d9SMichael Lotz void SetIdentifier(const char* identifier); 583b3884d9SMichael Lotz const char* Identifier() const; 593b3884d9SMichael Lotz 603b3884d9SMichael Lotz void SetSecondaryIdentifier(const char* identifier); 613b3884d9SMichael Lotz const char* SecondaryIdentifier() const; 623b3884d9SMichael Lotz 63dc1acef8SMichael Lotz status_t SetData(const uint8* data, size_t length); 64dc1acef8SMichael Lotz size_t DataLength() const; 65dc1acef8SMichael Lotz const uint8* Data() const; 66dc1acef8SMichael Lotz status_t GetData(uint8* buffer, size_t bufferSize) const; 673b3884d9SMichael Lotz 683b3884d9SMichael Lotz const char* Owner() const; 693b3884d9SMichael Lotz bigtime_t CreationTime() const; 70*94f897deSMichael Lotz 71*94f897deSMichael Lotz virtual status_t Flatten(BMessage& message) const; 72*94f897deSMichael Lotz virtual status_t Unflatten(const BMessage& message); 733b3884d9SMichael Lotz 743b3884d9SMichael Lotz BKey& operator=(const BKey& other); 753b3884d9SMichael Lotz 763b3884d9SMichael Lotz bool operator==(const BKey& other) const; 773b3884d9SMichael Lotz bool operator!=(const BKey& other) const; 783b3884d9SMichael Lotz 79c494c061SMichael Lotz virtual void PrintToStream(); 80c494c061SMichael Lotz 813b3884d9SMichael Lotz private: 821c399649SMichael Lotz friend class BKeyStore; 831c399649SMichael Lotz 84dc1acef8SMichael Lotz BKeyPurpose fPurpose; 853b3884d9SMichael Lotz BString fIdentifier; 863b3884d9SMichael Lotz BString fSecondaryIdentifier; 873b3884d9SMichael Lotz BString fOwner; 883b3884d9SMichael Lotz bigtime_t fCreationTime; 89dc1acef8SMichael Lotz mutable BMallocIO fData; 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 Type()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; 111c494c061SMichael Lotz 112c494c061SMichael Lotz virtual void PrintToStream(); 113dc1acef8SMichael Lotz }; 114dc1acef8SMichael Lotz 1153b3884d9SMichael Lotz #endif // _KEY_H 116