All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
key-params.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_KEY_PARAMS_HPP
24 #define NDN_KEY_PARAMS_HPP
25 
26 #include <stdint.h>
27 #include "../name.hpp"
28 #include "security-common.hpp"
29 
30 namespace ndn {
31 
36 class KeyParams {
37 public:
38  virtual
39  ~KeyParams()
40  {
41  }
42 
43  KeyType
44  getKeyType() const { return keyType_; }
45 
46  KeyIdType
47  getKeyIdType() const { return keyIdType_; }
48 
49  void
50  setKeyId(const Name::Component& keyId) { keyId_ = keyId; }
51 
52  const Name::Component&
53  getKeyId() const { return keyId_; }
54 
55 protected:
63  KeyParams(KeyType keyType, KeyIdType keyIdType);
64 
72  KeyParams(KeyType keyType, const Name::Component& keyId);
73 
74 private:
75  KeyType keyType_;
76  KeyIdType keyIdType_;
77  Name::Component keyId_;
78 };
79 
80 class RsaKeyParams : public KeyParams {
81 public:
83  (const Name::Component& keyId,
84  uint32_t size = RsaKeyParams::getDefaultSize())
85  : KeyParams(RsaKeyParams::getType(), keyId),
86  size_(size)
87  {
88  }
89 
91  (uint32_t size = RsaKeyParams::getDefaultSize(),
92  KeyIdType keyIdType = KEY_ID_TYPE_RANDOM)
93  : KeyParams(RsaKeyParams::getType(), keyIdType),
94  size_(size)
95  {
96  }
97 
98  uint32_t
99  getKeySize() const
100  {
101  return size_;
102  }
103 
104  static uint32_t
105  getDefaultSize() { return 2048; }
106 
107  static KeyType
108  getType() { return KEY_TYPE_RSA; }
109 
110 private:
111  uint32_t size_;
112 };
113 
114 class EcKeyParams : public KeyParams {
115 public:
117  (const Name::Component& keyId,
118  uint32_t size = EcKeyParams::getDefaultSize())
119  : KeyParams(EcKeyParams::getType(), keyId),
120  size_(size)
121  {
122  }
123 
125  (uint32_t size = EcKeyParams::getDefaultSize(),
126  KeyIdType keyIdType = KEY_ID_TYPE_RANDOM)
127  : KeyParams(EcKeyParams::getType(), keyIdType),
128  size_(size)
129  {
130  }
131 
132  uint32_t
133  getKeySize() const
134  {
135  return size_;
136  }
137 
138  static uint32_t
139  getDefaultSize() { return 256; }
140 
141  static KeyType
142  getType() { return KEY_TYPE_EC; }
143 
144 private:
145  uint32_t size_;
146 };
147 
148 
152 class EcdsaKeyParams : public EcKeyParams {
153 public:
155  (const Name::Component& keyId,
156  uint32_t size = EcKeyParams::getDefaultSize())
157  : EcKeyParams(keyId, size)
158  {
159  }
160 
162  (uint32_t size = EcKeyParams::getDefaultSize(),
163  KeyIdType keyIdType = KEY_ID_TYPE_RANDOM)
164  : EcKeyParams(size, keyIdType)
165  {
166  }
167 };
168 
169 class AesKeyParams : public KeyParams {
170 public:
172  (const Name::Component& keyId,
173  uint32_t size = AesKeyParams::getDefaultSize())
174  : KeyParams(AesKeyParams::getType(), keyId),
175  size_(size)
176  {
177  }
178 
180  (uint32_t size = AesKeyParams::getDefaultSize(),
181  KeyIdType keyIdType = KEY_ID_TYPE_RANDOM)
182  : KeyParams(AesKeyParams::getType(), keyIdType),
183  size_(size)
184  {
185  }
186 
187  uint32_t
188  getKeySize() const
189  {
190  return size_;
191  }
192 
193  static uint32_t
194  getDefaultSize() { return 64; }
195 
196  static KeyType
197  getType() { return KEY_TYPE_AES; }
198 
199 private:
200  uint32_t size_;
201 };
202 
203 }
204 
205 #endif
Definition: key-params.hpp:169
KeyIdType
The KeyIdType enum represents the type of a KeyId component in a key name.
Definition: security-common.hpp:30
Definition: key-params.hpp:80
RANDOM: A 64-bit random number as the key id.
Definition: security-common.hpp:45
A Name::Component holds a read-only name component value.
Definition: name.hpp:45
KeyType
Definition: security-common.hpp:50
Definition: key-params.hpp:114
KeyParams is a base class for key parameters.
Definition: key-params.hpp:36
KeyParams(KeyType keyType, KeyIdType keyIdType)
Create a key generation parameter.
Definition: key-params.cpp:30
Definition: key-params.hpp:152