xref: /haiku/headers/os/app/Key.h (revision 3b3884d9eec9b931efab12d5b2b47d7e33827a65)
1*3b3884d9SMichael Lotz /*
2*3b3884d9SMichael Lotz  * Copyright 2011, Haiku, Inc.
3*3b3884d9SMichael Lotz  * Distributed under the terms of the MIT License.
4*3b3884d9SMichael Lotz  */
5*3b3884d9SMichael Lotz #ifndef _KEY_H
6*3b3884d9SMichael Lotz #define _KEY_H
7*3b3884d9SMichael Lotz 
8*3b3884d9SMichael Lotz 
9*3b3884d9SMichael Lotz #include <DataIO.h>
10*3b3884d9SMichael Lotz #include <Message.h>
11*3b3884d9SMichael Lotz #include <ObjectList.h>
12*3b3884d9SMichael Lotz #include <String.h>
13*3b3884d9SMichael Lotz 
14*3b3884d9SMichael Lotz 
15*3b3884d9SMichael Lotz enum BPasswordType {
16*3b3884d9SMichael Lotz 	B_WEB_PASSWORD,
17*3b3884d9SMichael Lotz 	B_NETWORK_PASSWORD,
18*3b3884d9SMichael Lotz 	B_VOLUME_PASSWORD,
19*3b3884d9SMichael Lotz 	B_GENERIC_PASSWORD
20*3b3884d9SMichael Lotz };
21*3b3884d9SMichael Lotz 
22*3b3884d9SMichael Lotz 
23*3b3884d9SMichael Lotz class BKey {
24*3b3884d9SMichael Lotz public:
25*3b3884d9SMichael Lotz 								BKey();
26*3b3884d9SMichael Lotz 								BKey(BPasswordType type,
27*3b3884d9SMichael Lotz 									const char* identifier,
28*3b3884d9SMichael Lotz 									const char* password);
29*3b3884d9SMichael Lotz 								BKey(BPasswordType type,
30*3b3884d9SMichael Lotz 									const char* identifier,
31*3b3884d9SMichael Lotz 									const char* secondaryIdentifier,
32*3b3884d9SMichael Lotz 									const char* password);
33*3b3884d9SMichael Lotz 								BKey(BKey& other);
34*3b3884d9SMichael Lotz 	virtual						~BKey();
35*3b3884d9SMichael Lotz 
36*3b3884d9SMichael Lotz 			void				Unset();
37*3b3884d9SMichael Lotz 
38*3b3884d9SMichael Lotz 			status_t			SetTo(BPasswordType type,
39*3b3884d9SMichael Lotz 									const char* identifier,
40*3b3884d9SMichael Lotz 									const char* password);
41*3b3884d9SMichael Lotz 			status_t			SetTo(BPasswordType type,
42*3b3884d9SMichael Lotz 									const char* identifier,
43*3b3884d9SMichael Lotz 									const char* secondaryIdentifier,
44*3b3884d9SMichael Lotz 									const char* password);
45*3b3884d9SMichael Lotz 
46*3b3884d9SMichael Lotz 			status_t			SetPassword(const char* password);
47*3b3884d9SMichael Lotz 			const char*			Password() const;
48*3b3884d9SMichael Lotz 
49*3b3884d9SMichael Lotz 			status_t			SetKey(const uint8* data, size_t length);
50*3b3884d9SMichael Lotz 			size_t				KeyLength() const;
51*3b3884d9SMichael Lotz 			status_t			GetKey(uint8* buffer,
52*3b3884d9SMichael Lotz 									size_t bufferLength) const;
53*3b3884d9SMichael Lotz 
54*3b3884d9SMichael Lotz 			void				SetIdentifier(const char* identifier);
55*3b3884d9SMichael Lotz 			const char*			Identifier() const;
56*3b3884d9SMichael Lotz 
57*3b3884d9SMichael Lotz 			void				SetSecondaryIdentifier(const char* identifier);
58*3b3884d9SMichael Lotz 			const char*			SecondaryIdentifier() const;
59*3b3884d9SMichael Lotz 
60*3b3884d9SMichael Lotz 			void				SetType(BPasswordType type);
61*3b3884d9SMichael Lotz 			BPasswordType		Type() const;
62*3b3884d9SMichael Lotz 
63*3b3884d9SMichael Lotz 			void				SetData(const BMessage& data);
64*3b3884d9SMichael Lotz 			const BMessage&		Data() const;
65*3b3884d9SMichael Lotz 
66*3b3884d9SMichael Lotz 			const char*			Owner() const;
67*3b3884d9SMichael Lotz 			bigtime_t			CreationTime() const;
68*3b3884d9SMichael Lotz 			bool				IsRegistered() const;
69*3b3884d9SMichael Lotz 
70*3b3884d9SMichael Lotz // TODO: move to BKeyStore
71*3b3884d9SMichael Lotz 			status_t			GetNextApplication(uint32& cookie,
72*3b3884d9SMichael Lotz 									BString& signature) const;
73*3b3884d9SMichael Lotz 			status_t			RemoveApplication(const char* signature);
74*3b3884d9SMichael Lotz 
75*3b3884d9SMichael Lotz 			BKey&				operator=(const BKey& other);
76*3b3884d9SMichael Lotz 
77*3b3884d9SMichael Lotz 			bool				operator==(const BKey& other) const;
78*3b3884d9SMichael Lotz 			bool				operator!=(const BKey& other) const;
79*3b3884d9SMichael Lotz 
80*3b3884d9SMichael Lotz private:
81*3b3884d9SMichael Lotz 	mutable	BMallocIO			fPassword;
82*3b3884d9SMichael Lotz 			BString				fIdentifier;
83*3b3884d9SMichael Lotz 			BString				fSecondaryIdentifier;
84*3b3884d9SMichael Lotz 			BString				fOwner;
85*3b3884d9SMichael Lotz 			BMessage			fData;
86*3b3884d9SMichael Lotz 			bigtime_t			fCreationTime;
87*3b3884d9SMichael Lotz 			BPasswordType		fType;
88*3b3884d9SMichael Lotz 			BObjectList<BString> fApplications;
89*3b3884d9SMichael Lotz 			bool				fRegistered;
90*3b3884d9SMichael Lotz };
91*3b3884d9SMichael Lotz 
92*3b3884d9SMichael Lotz 
93*3b3884d9SMichael Lotz #endif	// _KEY_H
94