Digital Authentication Framework  6.0.1.37
daf_auth_state.h
Go to the documentation of this file.
1 /*
2  * (c) 2014 Good Technology Corporation. All rights reserved.
3  */
4 
10 #ifndef DAF_AUTH_STATE_H
11 #define DAF_AUTH_STATE_H
12 
13 #include "daf_auth_identify.h"
14 
15 struct json_object;
16 
27 {
28 public:
30  DAAuthState();
31 
33  DAAuthState(const DAAuthState &other);
34 
36  void operator=(const DAAuthState &other);
37 
39  ~DAAuthState();
40 
42  std::string marshal() const;
43 
46  bool unmarshal(const std::string &str);
47 
48  /* --- Auth class --- */
52  bool getAuthClass(DAAuthClass &cls);
53 
55  void setAuthClass(DAAuthClass cls);
56 
57  /* --- Key serial --- */
59  void setKeySerial(const std::string &ks);
60 
62  bool hasKeySerial();
63 
66  bool getKeySerial(std::string &ks_out);
67 
68  /* --- User string --- */
69 
71  void setUserString(const std::string &us);
72 
74  bool getUserString(std::string &us_out);
75 
76  /* --- DAMessage --- */
78  void setDAMessage(const DAMessage &msg);
79 
82  bool getDAMessage(DAMessage &msg);
83 
84 private:
85  /* The underlying object. Never NULL. */
86  struct json_object *m_json;
87 
88  /* Take the given DAData contents, and make a json_object
89  * which expresses it (as a base64 encoded string) */
90  struct json_object * encodeBytes(const DAData &bytes);
91 
92  /* Take the given base64 encoded c-string, and fill in
93  * \p out with the raw string. Returns false if base64
94  * encoding is broken. */
95  bool decodeBytes(const char *b64_cstr, DAData &out);
96 
97  /* Set a simple string value in object. */
98  void setString(const char *key, const char *val);
99 
100  /* Return true if there is a mapping of \p key to anything. */
101  bool hasValue(const char *key);
102 
103  /* Retreive the string value of the mapping of \p key.
104  * Returns false if there is no mapping, or it isn't
105  * to a string. */
106  bool getString(const char *key, std::string &out);
107 };
108 
109 #endif
DAAuthState()
ctor with empty object.
Encapsulates a message and various (optional) crypto parameters.
Definition: DigitalAuthenticationFramework.h:369
Long term state for authglue library.
Definition: daf_auth_state.h:26
void setUserString(const std::string &us)
Save (opaque) data as the user string.
std::string marshal() const
Produce a string format of underlying JSON message.
bool unmarshal(const std::string &str)
Replace object by unmarshaling provided string, returning false if that string has invalid JSON encod...
DAAuthClass
Authentication device type.
Definition: daf_auth_identify.h:139
~DAAuthState()
dtor, freeing underlying message.
void setAuthClass(DAAuthClass cls)
Save the authentication class.
bool hasKeySerial()
Return true if we have a saved key serial number.
void operator=(const DAAuthState &other)
assignment by deep copy.
void setDAMessage(const DAMessage &msg)
Save the contents of the given DAMessage (all fields).
bool getKeySerial(std::string &ks_out)
Retrieve saved key serial number, returning false if there is no valid stored key serial number...
bool getUserString(std::string &us_out)
Retrieve data stored by above call.
bool getAuthClass(DAAuthClass &cls)
Get the stored authentication class, returning false if there is no valid stored class.
std::vector< uint8_t > DAData
A data block represented as a sequence of bytes.
Definition: DigitalAuthenticationFramework.h:28
bool getDAMessage(DAMessage &msg)
Retrieve saved DAMessage contents into msg, returning false if there is not one, or if it is invalid...
Identification of DAF device capabilities.
void setKeySerial(const std::string &ks)
Save the given key serial number.