vfs: check userland buffers before reading them.
[haiku.git] / headers / os / app / Key.h
blob35f166ec14c1fed64b49227ec4fe36faded1ac77
1 /*
2 * Copyright 2011, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _KEY_H
6 #define _KEY_H
9 #include <DataIO.h>
10 #include <Message.h>
11 #include <ObjectList.h>
12 #include <String.h>
15 enum BKeyPurpose {
16 B_KEY_PURPOSE_ANY,
17 B_KEY_PURPOSE_GENERIC,
18 B_KEY_PURPOSE_KEYRING,
19 B_KEY_PURPOSE_WEB,
20 B_KEY_PURPOSE_NETWORK,
21 B_KEY_PURPOSE_VOLUME
25 enum BKeyType {
26 B_KEY_TYPE_ANY,
27 B_KEY_TYPE_GENERIC,
28 B_KEY_TYPE_PASSWORD,
29 B_KEY_TYPE_CERTIFICATE
33 class BKey {
34 public:
35 BKey();
36 BKey(BKeyPurpose purpose,
37 const char* identifier,
38 const char* secondaryIdentifier = NULL,
39 const uint8* data = NULL,
40 size_t length = 0);
41 BKey(BKey& other);
42 virtual ~BKey();
44 virtual BKeyType Type() const { return B_KEY_TYPE_GENERIC; };
46 void Unset();
48 status_t SetTo(BKeyPurpose purpose,
49 const char* identifier,
50 const char* secondaryIdentifier = NULL,
51 const uint8* data = NULL,
52 size_t length = 0);
54 void SetPurpose(BKeyPurpose purpose);
55 BKeyPurpose Purpose() const;
57 void SetIdentifier(const char* identifier);
58 const char* Identifier() const;
60 void SetSecondaryIdentifier(const char* identifier);
61 const char* SecondaryIdentifier() const;
63 status_t SetData(const uint8* data, size_t length);
64 size_t DataLength() const;
65 const uint8* Data() const;
66 status_t GetData(uint8* buffer, size_t bufferSize) const;
68 const char* Owner() const;
69 bigtime_t CreationTime() const;
71 virtual status_t Flatten(BMessage& message) const;
72 virtual status_t Unflatten(const BMessage& message);
74 BKey& operator=(const BKey& other);
76 bool operator==(const BKey& other) const;
77 bool operator!=(const BKey& other) const;
79 virtual void PrintToStream();
81 private:
82 friend class BKeyStore;
84 BKeyPurpose fPurpose;
85 BString fIdentifier;
86 BString fSecondaryIdentifier;
87 BString fOwner;
88 bigtime_t fCreationTime;
89 mutable BMallocIO fData;
93 class BPasswordKey : public BKey {
94 public:
95 BPasswordKey();
96 BPasswordKey(const char* password,
97 BKeyPurpose purpose, const char* identifier,
98 const char* secondaryIdentifier = NULL);
99 BPasswordKey(BPasswordKey& other);
100 virtual ~BPasswordKey();
102 virtual BKeyType Type() const { return B_KEY_TYPE_PASSWORD; };
104 status_t SetTo(const char* password,
105 BKeyPurpose purpose,
106 const char* identifier,
107 const char* secondaryIdentifier = NULL);
109 status_t SetPassword(const char* password);
110 const char* Password() const;
112 virtual void PrintToStream();
115 #endif // _KEY_H