Digital Authentication Framework  6.0.1.37
basic_key.h
Go to the documentation of this file.
1 /*
2  * (c) 2014 Good Technology Corporation. All rights reserved.
3  */
4 
10 #ifndef BASIC_KEY_H
11 #define BASIC_KEY_H
12 
14 
15 #include "basic_error.h"
16 #include "basic_metadata.h"
17 
24 class BasicKey : public DAKey
25 {
26 public:
32  : m_error(err)
33  , m_meta(m_error)
34  {}
35 
37  {
38  return m_meta;
39  }
40 
41  virtual bool encrypt(DAMessage &msg) { return _notImpl(); }
42  virtual bool decrypt(DAMessage &msg) { return _notImpl(); }
43  virtual bool sign(DAMessage &msg) { return _notImpl(); }
44  virtual bool verify(DAMessage &msg) { return _notImpl(); }
45  virtual bool setData(const DAData &data) { return _notImpl(); }
46  virtual bool getData(DAData &out) { return _notImpl(); }
47  virtual bool generateMaterial() { return _notImpl(); }
48 
49  // Class-0 and Class-1 keys can use this base method,
50  // as they provide no crypto mechanisms.
51  virtual std::vector<DAMechanism> getMechanisms()
52  {
53  std::vector<DAMechanism> out;
54  m_error.clear();
55  return out;
56  }
57 
60  void setSerial(const std::string &serial)
61  {
62  m_meta.setString(DA_SERIAL, serial);
63  }
64 
65 protected:
68  bool _notImpl() { m_error.setCode(DAError::NOT_IMPLEMENTED); return false; }
70 };
71 
79 class BasicReadonlyKey : public BasicKey
80 {
81 public:
86  BasicReadonlyKey(BasicError &err, const DAData &data)
87  : BasicKey(err)
88  , m_bytes(data)
89  {
90  m_meta.setFlag(DA_STORAGE, true);
91  }
92 
93  virtual bool getData(DAData &out)
94  {
95  out = m_bytes;
96  m_error.clear();
97  return true;
98  }
99 
100 protected:
102 };
103 
104 #endif
Main C++ interface to authentication device.
virtual bool getData(DAData &out)
Retrieve key data.
Definition: basic_key.h:46
Encapsulates a message and various (optional) crypto parameters.
Definition: DigitalAuthenticationFramework.h:369
Method is not implemented.
Definition: DigitalAuthenticationFramework.h:97
void setString(DAAttrib which, const std::string &value)
Set a string attribute.
Definition: basic_metadata.h:60
BasicError & m_error
Reference to object where this key can report errors.
Definition: basic_key.h:66
Basic implementation of DAMetaData.
virtual bool sign(DAMessage &msg)
Sign the given message Returns success = true.
Definition: basic_key.h:43
virtual bool verify(DAMessage &msg)
Verify the given message Returns success = true.
Definition: basic_key.h:44
DAData m_bytes
Data to be returned by getData()
Definition: basic_key.h:101
General metadata interface.
Definition: DigitalAuthenticationFramework.h:652
bool setCode(int e)
Set error code in error code.
Definition: basic_error.h:36
Base class for simple keys.
Definition: basic_key.h:24
virtual std::vector< DAMechanism > getMechanisms()
Return a vector of mechanisms supported by this key.
Definition: basic_key.h:51
BasicKey(BasicError &err)
Constructor.
Definition: basic_key.h:31
DAMetaData & getInfo()
get metadata object describing this key
Definition: basic_key.h:36
Simple key implementation for class-0 devices.
Definition: basic_key.h:79
BasicReadonlyKey(BasicError &err, const DAData &data)
Constructor.
Definition: basic_key.h:86
virtual bool getData(DAData &out)
Retrieve key data.
Definition: basic_key.h:93
void setSerial(const std::string &serial)
Set serial number to be returned by metadata.
Definition: basic_key.h:60
Simple implementation of DAMetaData.
Definition: basic_metadata.h:25
virtual bool encrypt(DAMessage &msg)
Encrypt the given message Returns success = true.
Definition: basic_key.h:41
virtual bool setData(const DAData &data)
Set key data.
Definition: basic_key.h:45
bool _notImpl()
Stub for not-implemented methods: sets a NOT_IMPLEMENTED error and returns false. ...
Definition: basic_key.h:68
(flag) True if GetData() and SetData() work
Definition: DigitalAuthenticationFramework.h:635
std::vector< uint8_t > DAData
A data block represented as a sequence of bytes.
Definition: DigitalAuthenticationFramework.h:28
Simple implementation of DAError.
void setFlag(DAAttrib which, bool value=true)
Set a boolean(flag) attribute.
Definition: basic_metadata.h:67
virtual bool decrypt(DAMessage &msg)
Decrypt the given message Returns success = true.
Definition: basic_key.h:42
virtual void clear()
reset the current error state.
Definition: basic_error.h:42
(string) Unique serial number of device or key
Definition: DigitalAuthenticationFramework.h:623
BasicMetaData m_meta
Metadata for this key. Subclasses can set fields within this data.
Definition: basic_key.h:67
virtual bool generateMaterial()
Generates or regenerates key material.
Definition: basic_key.h:47
Interface to Key objects.
Definition: DigitalAuthenticationFramework.h:260
Simple implementation of DAError.
Definition: basic_error.h:22