2011-11-16 16:53:36 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _KEY_H
|
|
|
|
#define _KEY_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <DataIO.h>
|
|
|
|
#include <Message.h>
|
|
|
|
#include <ObjectList.h>
|
|
|
|
#include <String.h>
|
|
|
|
|
|
|
|
|
2011-12-22 17:58:19 +04:00
|
|
|
enum BKeyPurpose {
|
|
|
|
B_KEY_PURPOSE_ANY,
|
|
|
|
B_KEY_PURPOSE_GENERIC,
|
2012-01-05 01:37:49 +04:00
|
|
|
B_KEY_PURPOSE_KEYRING,
|
2011-12-22 17:58:19 +04:00
|
|
|
B_KEY_PURPOSE_WEB,
|
|
|
|
B_KEY_PURPOSE_NETWORK,
|
|
|
|
B_KEY_PURPOSE_VOLUME
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum BKeyType {
|
|
|
|
B_KEY_TYPE_ANY,
|
|
|
|
B_KEY_TYPE_GENERIC,
|
|
|
|
B_KEY_TYPE_PASSWORD,
|
|
|
|
B_KEY_TYPE_CERTIFICATE
|
2011-11-16 16:53:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BKey {
|
|
|
|
public:
|
|
|
|
BKey();
|
2011-12-22 17:58:19 +04:00
|
|
|
BKey(BKeyPurpose purpose,
|
2011-11-16 16:53:36 +04:00
|
|
|
const char* identifier,
|
2011-12-22 17:58:19 +04:00
|
|
|
const char* secondaryIdentifier = NULL,
|
|
|
|
const uint8* data = NULL,
|
|
|
|
size_t length = 0);
|
2011-11-16 16:53:36 +04:00
|
|
|
BKey(BKey& other);
|
|
|
|
virtual ~BKey();
|
|
|
|
|
2011-12-22 17:58:19 +04:00
|
|
|
virtual BKeyType Type() const { return B_KEY_TYPE_GENERIC; };
|
|
|
|
|
2011-11-16 16:53:36 +04:00
|
|
|
void Unset();
|
|
|
|
|
2011-12-22 17:58:19 +04:00
|
|
|
status_t SetTo(BKeyPurpose purpose,
|
2011-11-16 16:53:36 +04:00
|
|
|
const char* identifier,
|
2011-12-22 17:58:19 +04:00
|
|
|
const char* secondaryIdentifier = NULL,
|
|
|
|
const uint8* data = NULL,
|
|
|
|
size_t length = 0);
|
2011-11-16 16:53:36 +04:00
|
|
|
|
2011-12-22 17:58:19 +04:00
|
|
|
void SetPurpose(BKeyPurpose purpose);
|
|
|
|
BKeyPurpose Purpose() const;
|
2011-11-16 16:53:36 +04:00
|
|
|
|
|
|
|
void SetIdentifier(const char* identifier);
|
|
|
|
const char* Identifier() const;
|
|
|
|
|
|
|
|
void SetSecondaryIdentifier(const char* identifier);
|
|
|
|
const char* SecondaryIdentifier() const;
|
|
|
|
|
2011-12-22 17:58:19 +04:00
|
|
|
status_t SetData(const uint8* data, size_t length);
|
|
|
|
size_t DataLength() const;
|
|
|
|
const uint8* Data() const;
|
|
|
|
status_t GetData(uint8* buffer, size_t bufferSize) const;
|
2011-11-16 16:53:36 +04:00
|
|
|
|
|
|
|
const char* Owner() const;
|
|
|
|
bigtime_t CreationTime() const;
|
2012-01-08 04:17:02 +04:00
|
|
|
|
|
|
|
virtual status_t Flatten(BMessage& message) const;
|
|
|
|
virtual status_t Unflatten(const BMessage& message);
|
2011-11-16 16:53:36 +04:00
|
|
|
|
|
|
|
BKey& operator=(const BKey& other);
|
|
|
|
|
|
|
|
bool operator==(const BKey& other) const;
|
|
|
|
bool operator!=(const BKey& other) const;
|
|
|
|
|
2012-01-04 16:57:17 +04:00
|
|
|
virtual void PrintToStream();
|
|
|
|
|
2011-11-16 16:53:36 +04:00
|
|
|
private:
|
2012-01-04 04:51:59 +04:00
|
|
|
friend class BKeyStore;
|
|
|
|
|
2011-12-22 17:58:19 +04:00
|
|
|
BKeyPurpose fPurpose;
|
2011-11-16 16:53:36 +04:00
|
|
|
BString fIdentifier;
|
|
|
|
BString fSecondaryIdentifier;
|
|
|
|
BString fOwner;
|
|
|
|
bigtime_t fCreationTime;
|
2011-12-22 17:58:19 +04:00
|
|
|
mutable BMallocIO fData;
|
2011-11-16 16:53:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-12-22 17:58:19 +04:00
|
|
|
class BPasswordKey : public BKey {
|
|
|
|
public:
|
|
|
|
BPasswordKey();
|
|
|
|
BPasswordKey(const char* password,
|
|
|
|
BKeyPurpose purpose, const char* identifier,
|
|
|
|
const char* secondaryIdentifier = NULL);
|
|
|
|
BPasswordKey(BPasswordKey& other);
|
|
|
|
virtual ~BPasswordKey();
|
|
|
|
|
|
|
|
virtual BKeyType Type() const { return B_KEY_TYPE_PASSWORD; };
|
|
|
|
|
|
|
|
status_t SetTo(const char* password,
|
|
|
|
BKeyPurpose purpose,
|
|
|
|
const char* identifier,
|
|
|
|
const char* secondaryIdentifier = NULL);
|
|
|
|
|
|
|
|
status_t SetPassword(const char* password);
|
|
|
|
const char* Password() const;
|
2012-01-04 16:57:17 +04:00
|
|
|
|
|
|
|
virtual void PrintToStream();
|
2011-12-22 17:58:19 +04:00
|
|
|
};
|
|
|
|
|
2011-11-16 16:53:36 +04:00
|
|
|
#endif // _KEY_H
|