key-params.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "key-params.hpp"
23 
24 namespace ndn {
25 
26 static const uint32_t MIN_RSA_KEY_SIZE = 1024;
27 static const uint32_t DEFAULT_RSA_KEY_SIZE = 2048;
28 static const uint32_t EC_KEY_SIZES[] = {256, 384};
29 static const uint32_t AES_KEY_SIZES[] = {128, 192, 256};
30 
31 KeyParams::~KeyParams() = default;
32 
34  : m_keyType(keyType)
35  , m_keyIdType(keyIdType)
36 {
37  BOOST_ASSERT(keyIdType != KeyIdType::USER_SPECIFIED);
38 }
39 
41  : m_keyType(keyType)
42  , m_keyIdType(KeyIdType::USER_SPECIFIED)
43  , m_keyId(keyId)
44 {
45  BOOST_ASSERT(!keyId.empty());
46 }
47 
48 uint32_t
50 {
51  if (size < MIN_RSA_KEY_SIZE)
52  BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported key size"));
53  return size;
54 }
55 
56 uint32_t
58 {
59  return DEFAULT_RSA_KEY_SIZE;
60 }
61 
62 uint32_t
64 {
65  for (size_t i = 0; i < (sizeof(EC_KEY_SIZES) / sizeof(EC_KEY_SIZES[0])); i++) {
66  if (EC_KEY_SIZES[i] == size)
67  return size;
68  }
69  BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported key size"));
70 }
71 
72 uint32_t
74 {
75  return EC_KEY_SIZES[0];
76 }
77 
78 
79 uint32_t
81 {
82  for (size_t i = 0; i < (sizeof(AES_KEY_SIZES) / sizeof(AES_KEY_SIZES[0])); i++) {
83  if (AES_KEY_SIZES[i] == size)
84  return size;
85  }
86  BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported key size"));
87 }
88 
89 uint32_t
91 {
92  return AES_KEY_SIZES[0];
93 }
94 
95 } // namespace ndn
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
static const uint32_t DEFAULT_RSA_KEY_SIZE
Definition: key-params.cpp:27
KeyIdType
The type of KeyId component in a key name.
virtual ~KeyParams()
static uint32_t checkKeySize(uint32_t size)
check if size is qualified.
Definition: key-params.cpp:80
static uint32_t getDefaultSize()
Definition: key-params.cpp:73
static const uint32_t AES_KEY_SIZES[]
Definition: key-params.cpp:29
static uint32_t checkKeySize(uint32_t size)
check if size is qualified.
Definition: key-params.cpp:49
static const uint32_t MIN_RSA_KEY_SIZE
Definition: key-params.cpp:26
static uint32_t getDefaultSize()
Definition: key-params.cpp:90
static uint32_t getDefaultSize()
Definition: key-params.cpp:57
static uint32_t checkKeySize(uint32_t size)
check if size is qualified.
Definition: key-params.cpp:63
KeyParams(KeyType keyType, KeyIdType keyIdType)
Create a key generation parameter.
Definition: key-params.cpp:33
Component holds a read-only name component value.
User-specified key ID.
static const uint32_t EC_KEY_SIZES[]
Definition: key-params.cpp:28