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 15*dc1acef8SMichael Lotz enum BKeyPurpose { 16*dc1acef8SMichael Lotz B_KEY_PURPOSE_ANY, 17*dc1acef8SMichael Lotz B_KEY_PURPOSE_GENERIC, 18*dc1acef8SMichael Lotz B_KEY_PURPOSE_WEB, 19*dc1acef8SMichael Lotz B_KEY_PURPOSE_NETWORK, 20*dc1acef8SMichael Lotz B_KEY_PURPOSE_VOLUME 21*dc1acef8SMichael Lotz }; 22*dc1acef8SMichael Lotz 23*dc1acef8SMichael Lotz 24*dc1acef8SMichael Lotz enum BKeyType { 25*dc1acef8SMichael Lotz B_KEY_TYPE_ANY, 26*dc1acef8SMichael Lotz B_KEY_TYPE_GENERIC, 27*dc1acef8SMichael Lotz B_KEY_TYPE_PASSWORD, 28*dc1acef8SMichael Lotz B_KEY_TYPE_CERTIFICATE 293b3884d9SMichael Lotz }; 303b3884d9SMichael Lotz 313b3884d9SMichael Lotz 323b3884d9SMichael Lotz class BKey { 333b3884d9SMichael Lotz public: 343b3884d9SMichael Lotz BKey(); 35*dc1acef8SMichael Lotz BKey(BKeyPurpose purpose, 363b3884d9SMichael Lotz const char* identifier, 37*dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL, 38*dc1acef8SMichael Lotz const uint8* data = NULL, 39*dc1acef8SMichael Lotz size_t length = 0); 403b3884d9SMichael Lotz BKey(BKey& other); 413b3884d9SMichael Lotz virtual ~BKey(); 423b3884d9SMichael Lotz 43*dc1acef8SMichael Lotz virtual BKeyType Type() const { return B_KEY_TYPE_GENERIC; }; 44*dc1acef8SMichael Lotz 453b3884d9SMichael Lotz void Unset(); 463b3884d9SMichael Lotz 47*dc1acef8SMichael Lotz status_t SetTo(BKeyPurpose purpose, 483b3884d9SMichael Lotz const char* identifier, 49*dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL, 50*dc1acef8SMichael Lotz const uint8* data = NULL, 51*dc1acef8SMichael Lotz size_t length = 0); 523b3884d9SMichael Lotz 53*dc1acef8SMichael Lotz void SetPurpose(BKeyPurpose purpose); 54*dc1acef8SMichael 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 62*dc1acef8SMichael Lotz status_t SetData(const uint8* data, size_t length); 63*dc1acef8SMichael Lotz size_t DataLength() const; 64*dc1acef8SMichael Lotz const uint8* Data() const; 65*dc1acef8SMichael 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 763b3884d9SMichael Lotz private: 77*dc1acef8SMichael Lotz BKeyPurpose fPurpose; 783b3884d9SMichael Lotz BString fIdentifier; 793b3884d9SMichael Lotz BString fSecondaryIdentifier; 803b3884d9SMichael Lotz BString fOwner; 813b3884d9SMichael Lotz bigtime_t fCreationTime; 82*dc1acef8SMichael Lotz mutable BMallocIO fData; 833b3884d9SMichael Lotz BObjectList<BString> fApplications; 843b3884d9SMichael Lotz bool fRegistered; 853b3884d9SMichael Lotz }; 863b3884d9SMichael Lotz 873b3884d9SMichael Lotz 88*dc1acef8SMichael Lotz class BPasswordKey : public BKey { 89*dc1acef8SMichael Lotz public: 90*dc1acef8SMichael Lotz BPasswordKey(); 91*dc1acef8SMichael Lotz BPasswordKey(const char* password, 92*dc1acef8SMichael Lotz BKeyPurpose purpose, const char* identifier, 93*dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL); 94*dc1acef8SMichael Lotz BPasswordKey(BPasswordKey& other); 95*dc1acef8SMichael Lotz virtual ~BPasswordKey(); 96*dc1acef8SMichael Lotz 97*dc1acef8SMichael Lotz virtual BKeyType Type() const { return B_KEY_TYPE_PASSWORD; }; 98*dc1acef8SMichael Lotz 99*dc1acef8SMichael Lotz status_t SetTo(const char* password, 100*dc1acef8SMichael Lotz BKeyPurpose purpose, 101*dc1acef8SMichael Lotz const char* identifier, 102*dc1acef8SMichael Lotz const char* secondaryIdentifier = NULL); 103*dc1acef8SMichael Lotz 104*dc1acef8SMichael Lotz status_t SetPassword(const char* password); 105*dc1acef8SMichael Lotz const char* Password() const; 106*dc1acef8SMichael Lotz }; 107*dc1acef8SMichael Lotz 1083b3884d9SMichael Lotz #endif // _KEY_H 109