NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
key-params.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_SECURITY_KEY_PARAMS_HPP
23 #define NDN_SECURITY_KEY_PARAMS_HPP
24 
25 #include "../common.hpp"
26 #include "security-common.hpp"
27 
28 namespace ndn {
29 
35 class KeyParams
36 {
37 public:
38  class Error : public std::runtime_error
39  {
40  public:
41  explicit
42  Error(const std::string& what)
43  : std::runtime_error(what)
44  {
45  }
46  };
47 
48  virtual
50  {
51  }
52 
53  KeyType
54  getKeyType() const
55  {
56  return m_keyType;
57  }
58 
59 protected:
60  explicit
61  KeyParams(KeyType keyType)
62  : m_keyType(keyType)
63  {
64  }
65 
66 private:
67  KeyType m_keyType;
68 };
69 
70 
73 {
74 public:
75  static KeyType
77  {
78  return KEY_TYPE_RSA;
79  }
80 
82  static uint32_t
83  checkKeySize(uint32_t size);
84 
85  static uint32_t
86  getDefaultSize();
87 };
88 
91 {
92 public:
93  static KeyType
95  {
96  return KEY_TYPE_ECDSA;
97  }
98 
100  static uint32_t
101  checkKeySize(uint32_t size);
102 
103  static uint32_t
104  getDefaultSize();
105 };
106 
107 
109 template<typename KeyParamsInfo>
111 {
112 public:
113  explicit
114  SimplePublicKeyParams(uint32_t size = KeyParamsInfo::getDefaultSize())
115  : KeyParams(KeyParamsInfo::getType())
116  {
117  setKeySize(size);
118  }
119 
120  explicit
122  : KeyParams(params)
123  , m_size(params.m_size)
124  {
125  }
126 
127  explicit
129  : KeyParams(params.getKeyType())
130  {
131  BOOST_THROW_EXCEPTION(KeyParams::Error("Incorrect key parameters (incompatible key type)"));
132  }
133 
134  uint32_t
135  getKeySize() const
136  {
137  return m_size;
138  }
139 
140 private:
141  void
142  setKeySize(uint32_t size)
143  {
144  m_size = KeyParamsInfo::checkKeySize(size);
145  }
146 
147  uint32_t
148  getDefaultKeySize() const
149  {
150  return KeyParamsInfo::getDefaultSize();
151  }
152 
153 private:
154  uint32_t m_size;
155 };
156 
159 
162 
163 
166 {
167 public:
168  static KeyType
170  {
171  return KEY_TYPE_AES;
172  }
173 
175  static uint32_t
176  checkKeySize(uint32_t size);
177 
178  static uint32_t
179  getDefaultSize();
180 };
181 
182 
184 template<typename KeyParamsInfo>
186 {
187 public:
188  explicit
189  SimpleSymmetricKeyParams(uint32_t size = KeyParamsInfo::getDefaultSize())
190  : KeyParams(KeyParamsInfo::getType())
191  {
192  setKeySize(size);
193  }
194 
195  explicit
197  : KeyParams(params)
198  , m_size(params.m_size)
199  {
200  }
201 
202  explicit
204  {
205  BOOST_THROW_EXCEPTION(KeyParams::Error("Incorrect key parameters (incompatible key type)"));
206  }
207 
208  uint32_t
209  getKeySize() const
210  {
211  return m_size;
212  }
213 
214 private:
215  void
216  setKeySize(uint32_t size)
217  {
218  m_size = KeyParamsInfo::checkKeySize(size);
219  }
220 
221  uint32_t
222  getDefaultKeySize() const
223  {
224  return KeyParamsInfo::getDefaultSize();
225  }
226 
227 private:
228  uint32_t m_size;
229 
230 };
231 
233 
234 } // namespace ndn
235 
236 #endif // NDN_SECURITY_KEY_PARAMS_HPP
SimplePublicKeyParams(const SimplePublicKeyParams &params)
Definition: key-params.hpp:121
Copyright (c) 2011-2015 Regents of the University of California.
SimpleSymmetricKeyParams is a template for symmetric keys with only one parameter: size...
Definition: key-params.hpp:185
SimplePublicKeyParams< RsaKeyParamsInfo > RsaKeyParams
RsaKeyParams carries parameters for RSA key.
Definition: key-params.hpp:158
AesKeyParamsInfo is used to initialize a SimpleSymmetricKeyParams template for AES key...
Definition: key-params.hpp:165
Error(const std::string &what)
Definition: key-params.hpp:42
SimplePublicKeyParams(uint32_t size=KeyParamsInfo::getDefaultSize())
Definition: key-params.hpp:114
KeyType getKeyType() const
Definition: key-params.hpp:54
KeyParams(KeyType keyType)
Definition: key-params.hpp:61
uint32_t getKeySize() const
Definition: key-params.hpp:135
SimpleSymmetricKeyParams(uint32_t size=KeyParamsInfo::getDefaultSize())
Definition: key-params.hpp:189
static KeyType getType()
Definition: key-params.hpp:169
STL namespace.
virtual ~KeyParams()
Definition: key-params.hpp:49
uint32_t getKeySize() const
Definition: key-params.hpp:209
RsaKeyParamInfo is used to initialize a SimplePublicKeyParams template for RSA key.
Definition: key-params.hpp:72
SimpleSymmetricKeyParams(const KeyParams &params)
Definition: key-params.hpp:203
SimpleSymmetricKeyParams(const SimpleSymmetricKeyParams &params)
Definition: key-params.hpp:196
static KeyType getType()
Definition: key-params.hpp:76
static KeyType getType()
Definition: key-params.hpp:94
SimpleSymmetricKeyParams< AesKeyParamsInfo > AesKeyParams
Definition: key-params.hpp:232
SimplePublicKeyParams< EcdsaKeyParamsInfo > EcdsaKeyParams
EcdsaKeyParams carries parameters for ECDSA key.
Definition: key-params.hpp:161
Base class of key parameters.
Definition: key-params.hpp:35
EcdsaKeyParamInfo is used to initialize a SimplePublicKeyParams template for ECDSA key...
Definition: key-params.hpp:90
SimplePublicKeyParams(const KeyParams &params)
Definition: key-params.hpp:128
SimplePublicKeyParams is a template for public keys with only one parameter: size.
Definition: key-params.hpp:110