LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
key.hpp
Go to the documentation of this file.
1
7#ifndef LOGICALACCESS_KEY_HPP
8#define LOGICALACCESS_KEY_HPP
9
12
13namespace logicalaccess
14{
15class KeyDiversification;
20class LLA_CORE_API Key : public XmlSerializable,
21 public std::enable_shared_from_this<Key>
22{
23 public:
27 Key();
28
29 virtual ~Key() = default;
30
34 virtual void clear();
35
40 virtual size_t getLength() const = 0;
41
46 virtual const unsigned char *getData() const = 0;
47
52 virtual unsigned char *getData() = 0;
53
58 virtual void setData(const unsigned char *data);
59
64 virtual void setData(const ByteVector &data, size_t offset = 0);
65
70 std::string getString(bool withSpace = true) const;
71
76 bool isEmpty() const
77 {
78 return (d_isEmpty && d_key_storage->getType() == KST_COMPUTER_MEMORY);
79 }
80
87 virtual bool fromString(const std::string &str);
88
93 void setKeyStorage(std::shared_ptr<KeyStorage> key_storage);
94
99 std::shared_ptr<KeyStorage> getKeyStorage() const;
100
106 void serialize(boost::property_tree::ptree &node) override;
107
112 void unSerialize(boost::property_tree::ptree &node) override;
113
119 virtual bool operator==(const Key &key) const;
120
126 virtual bool operator!=(const Key &key) const;
127
132 void setCipherKey(const std::string &key);
133
138 void setStoreCipheredData(bool cipher);
139
144 bool getStoreCipheredData() const;
145
146 void setKeyDiversification(std::shared_ptr<KeyDiversification> div);
147
148 std::shared_ptr<KeyDiversification> getKeyDiversification() const;
149
153 ByteVector getBytes() const;
154
155 private:
159 static const std::string secureAiKey;
160
165 void cipherKeyData(boost::property_tree::ptree &node);
166
171 void uncipherKeyData(boost::property_tree::ptree &node);
172
173 protected:
178
182 std::shared_ptr<KeyStorage> d_key_storage;
183
187 std::shared_ptr<KeyDiversification> d_key_diversification;
188
192 std::string d_cipherKey;
193
198};
199
206LLA_CORE_API std::ostream &operator<<(std::ostream &os, const Key &key);
207}
208
209#endif /* LOGICALACCESS_KEY_HPP */
A Key base class. The key object is used to describe key chip information used for authentication on ...
Definition: key.hpp:22
virtual unsigned char * getData()=0
Get the key data.
virtual const unsigned char * getData() const =0
Get the key data.
bool d_storeCipheredData
The data is stored ciphered or not.
Definition: key.hpp:197
bool isEmpty() const
Get if key data are empty.
Definition: key.hpp:76
virtual ~Key()=default
std::string d_cipherKey
The cipher key.
Definition: key.hpp:192
static const std::string secureAiKey
The default 'secure' key for ciphering.
Definition: key.hpp:159
std::shared_ptr< KeyDiversification > d_key_diversification
The key storage used for this key.
Definition: key.hpp:187
bool d_isEmpty
Checked if key data are empty.
Definition: key.hpp:177
virtual size_t getLength() const =0
Get the key length.
std::shared_ptr< KeyStorage > d_key_storage
The key storage used for this key.
Definition: key.hpp:182
A Xml Serializable base class. Add Xml serialization to a class.
Definition: xmlserializable.hpp:54
Key storage description.
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
Definition: asn1.hpp:9
LLA_CORE_API std::ostream & operator<<(std::ostream &os, const Key &key)
Output to stream operator.
Definition: key.cpp:298
@ KST_COMPUTER_MEMORY
Definition: keystorage.hpp:18