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 "security-common.hpp"
28 
29 namespace ndn {
30 
35 class KeyParams {
36 public:
37  virtual
38  ~KeyParams()
39  {
40  }
41 
42  KeyType
43  getKeyType() const
44  {
45  return keyType_;
46  }
47 
48 protected:
49  explicit
50  KeyParams(KeyType keyType)
51  : keyType_(keyType)
52  {
53  }
54 
55 private:
56  KeyType keyType_;
57 };
58 
59 class RsaKeyParams : public KeyParams {
60 public:
61  explicit
62  RsaKeyParams(uint32_t size = RsaKeyParams::getDefaultSize())
63  : KeyParams(RsaKeyParams::getType()), size_(size)
64  {
65  }
66 
67  uint32_t
68  getKeySize() const
69  {
70  return size_;
71  }
72 
73 private:
74  static uint32_t
75  getDefaultSize() { return 2048; }
76 
77  static KeyType
78  getType() { return KEY_TYPE_RSA; }
79 
80  uint32_t size_;
81 };
82 
83 class EcdsaKeyParams : public KeyParams {
84 public:
85  explicit
86  EcdsaKeyParams(uint32_t size = EcdsaKeyParams::getDefaultSize())
87  : KeyParams(EcdsaKeyParams::getType()), size_(size)
88  {
89  }
90 
91  uint32_t
92  getKeySize() const
93  {
94  return size_;
95  }
96 
97 private:
98  static uint32_t
99  getDefaultSize() { return 256; }
100 
101  static KeyType
102  getType() { return KEY_TYPE_ECDSA; }
103 
104  uint32_t size_;
105 };
106 
107 class AesKeyParams : public KeyParams {
108 public:
109  explicit
110  AesKeyParams(uint32_t size = AesKeyParams::getDefaultSize())
111  : KeyParams(AesKeyParams::getType()), size_(size)
112  {
113  }
114 
115  uint32_t
116  getKeySize() const
117  {
118  return size_;
119  }
120 
121 private:
122  static uint32_t
123  getDefaultSize() { return 64; }
124 
125  static KeyType
126  getType() { return KEY_TYPE_AES; }
127 
128  uint32_t size_;
129 };
130 
131 }
132 
133 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
Definition: key-params.hpp:107
Definition: key-params.hpp:59
KeyParams is a base class for key parameters.
Definition: key-params.hpp:35
Definition: key-params.hpp:83