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, 18*d962e210SMichael 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 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; 703b3884d9SMichael Lotz bool IsRegistered() const; 713b3884d9SMichael Lotz 723b3884d9SMichael Lotz BKey& operator=(const BKey& other); 733b3884d9SMichael Lotz 743b3884d9SMichael Lotz bool operator==(const BKey& other) const; 753b3884d9SMichael Lotz bool operator!=(const BKey& other) const; 763b3884d9SMichael Lotz 77c494c061SMichael Lotz virtual void PrintToStream(); 78c494c061SMichael Lotz 791c399649SMichael Lotz protected: 801c399649SMichael Lotz virtual status_t _Flatten(BMessage& message) const; 811c399649SMichael Lotz virtual status_t _Unflatten(const BMessage& message); 821c399649SMichael Lotz 833b3884d9SMichael Lotz private: 841c399649SMichael Lotz friend class BKeyStore; 851c399649SMichael Lotz 86dc1acef8SMichael Lotz BKeyPurpose fPurpose; 873b3884d9SMichael Lotz BString fIdentifier; 883b3884d9SMichael Lotz BString fSecondaryIdentifier; 893b3884d9SMichael Lotz BString fOwner; 903b3884d9SMichael Lotz bigtime_t fCreationTime; 91dc1acef8SMichael Lotz mutable BMallocIO fData; 923b3884d9SMichael Lotz bool fRegistered; 933b3884d9SMichael Lotz }; 943b3884d9SMichael Lotz 953b3884d9SMichael Lotz 96dc1acef8SMichael Lotz class BPasswordKey : public BKey { 97dc1acef8SMichael Lotz public: 98dc1acef8SMichael Lotz BPasswordKey(); 99dc1acef8SMichael Lotz BPasswordKey(const char* password, 100dc1acef8SMichael Lotz BKeyPurpose purpose, const char* identifier, 101dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL); 102dc1acef8SMichael Lotz BPasswordKey(BPasswordKey& other); 103dc1acef8SMichael Lotz virtual ~BPasswordKey(); 104dc1acef8SMichael Lotz 105dc1acef8SMichael Lotz virtual BKeyType Type() const { return B_KEY_TYPE_PASSWORD; }; 106dc1acef8SMichael Lotz 107dc1acef8SMichael Lotz status_t SetTo(const char* password, 108dc1acef8SMichael Lotz BKeyPurpose purpose, 109dc1acef8SMichael Lotz const char* identifier, 110dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL); 111dc1acef8SMichael Lotz 112dc1acef8SMichael Lotz status_t SetPassword(const char* password); 113dc1acef8SMichael Lotz const char* Password() const; 114c494c061SMichael Lotz 115c494c061SMichael Lotz virtual void PrintToStream(); 116dc1acef8SMichael Lotz }; 117dc1acef8SMichael Lotz 1183b3884d9SMichael Lotz #endif // _KEY_H 119