Digital Authentication Framework 6.0.1.33

basic_key.h

Go to the documentation of this file.
00001 /*
00002  * (c) 2014 Good Technology Corporation. All rights reserved.
00003  */
00004 
00010 #ifndef BASIC_KEY_H
00011 #define BASIC_KEY_H
00012 
00013 #include "DigitalAuthenticationFramework.h"
00014 
00015 #include "basic_error.h"
00016 #include "basic_metadata.h"
00017 
00024 class BasicKey : public DAKey
00025 {
00026 public:
00031   BasicKey(BasicError &err)
00032     : m_error(err)
00033     , m_meta(m_error)
00034   {}
00035 
00036   DAMetaData & getInfo()
00037   {
00038     return m_meta;
00039   }
00040 
00041   virtual bool encrypt(DAMessage &msg) { return _notImpl(); }
00042   virtual bool decrypt(DAMessage &msg) { return _notImpl(); }
00043   virtual bool sign(DAMessage &msg) { return _notImpl(); }
00044   virtual bool verify(DAMessage &msg) { return _notImpl(); }
00045   virtual bool setData(const DAData &data) { return _notImpl(); }
00046   virtual bool getData(DAData &out) { return _notImpl(); }
00047   virtual bool generateMaterial() { return _notImpl(); }
00048 
00049   // Class-0 and Class-1 keys can use this base method,
00050   // as they provide no crypto mechanisms.
00051   virtual std::vector<DAMechanism> getMechanisms()
00052   {
00053     std::vector<DAMechanism> out;
00054     m_error.clear();
00055     return out;
00056   }
00057     
00060   void setSerial(const std::string &serial)
00061   {
00062     m_meta.setString(DA_SERIAL, serial);
00063   }
00064 
00065 protected:
00066   BasicError &m_error;  
00067   BasicMetaData m_meta; 
00068   bool _notImpl() { m_error.setCode(DAError::NOT_IMPLEMENTED); return false; }
00070 };
00071 
00079 class BasicReadonlyKey : public BasicKey
00080 {
00081 public:
00086   BasicReadonlyKey(BasicError &err, const DAData &data)
00087     : BasicKey(err)
00088     , m_bytes(data)
00089   {
00090     m_meta.setFlag(DA_STORAGE, true);
00091   }
00092   
00093   virtual bool getData(DAData &out)
00094   {
00095     out = m_bytes;
00096     m_error.clear();
00097     return true;
00098   }
00099   
00100 protected:
00101   DAData m_bytes; 
00102 };
00103 
00104 #endif