NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
key-params.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
23 
24 namespace ndn {
25 
26 static const uint32_t MIN_RSA_KEY_SIZE = 2048;
27 static const uint32_t DEFAULT_RSA_KEY_SIZE = 2048;
28 static const uint32_t EC_KEY_SIZES[] = {224, 256, 384, 521};
29 static const uint32_t DEFAULT_EC_KEY_SIZE = 256;
30 static const uint32_t AES_KEY_SIZES[] = {128, 192, 256};
31 static const uint32_t DEFAULT_AES_KEY_SIZE = 128;
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 KeyParams::~KeyParams() = default;
49 
50 namespace detail {
51 
52 uint32_t
54 {
55  if (size < MIN_RSA_KEY_SIZE)
56  BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported RSA key size " + to_string(size)));
57  return size;
58 }
59 
60 uint32_t
62 {
63  return DEFAULT_RSA_KEY_SIZE;
64 }
65 
66 uint32_t
68 {
69  for (size_t i = 0; i < (sizeof(EC_KEY_SIZES) / sizeof(EC_KEY_SIZES[0])); i++) {
70  if (EC_KEY_SIZES[i] == size)
71  return size;
72  }
73  BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported EC key size " + to_string(size)));
74 }
75 
76 uint32_t
78 {
79  return DEFAULT_EC_KEY_SIZE;
80 }
81 
82 uint32_t
84 {
85  for (size_t i = 0; i < (sizeof(AES_KEY_SIZES) / sizeof(AES_KEY_SIZES[0])); i++) {
86  if (AES_KEY_SIZES[i] == size)
87  return size;
88  }
89  BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported AES key size " + to_string(size)));
90 }
91 
92 uint32_t
94 {
95  return DEFAULT_AES_KEY_SIZE;
96 }
97 
98 } // namespace detail
99 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
static const uint32_t DEFAULT_AES_KEY_SIZE
Definition: key-params.cpp:31
static const uint32_t DEFAULT_RSA_KEY_SIZE
Definition: key-params.cpp:27
static const uint32_t DEFAULT_EC_KEY_SIZE
Definition: key-params.cpp:29
KeyIdType
The type of KeyId component in a key name.
virtual ~KeyParams()
static uint32_t checkKeySize(uint32_t size)
check if size is valid and supported for this key type.
Definition: key-params.cpp:67
static const uint32_t AES_KEY_SIZES[]
Definition: key-params.cpp:30
static uint32_t checkKeySize(uint32_t size)
check if size is valid and supported for this key type.
Definition: key-params.cpp:83
KeyType
The type of a cryptographic key.
static const uint32_t MIN_RSA_KEY_SIZE
Definition: key-params.cpp:26
KeyParams(KeyType keyType, KeyIdType keyIdType)
Create a key generation parameter.
Definition: key-params.cpp:33
Represents a name component.
static uint32_t checkKeySize(uint32_t size)
check if size is valid and supported for this key type.
Definition: key-params.cpp:53
User-specified key ID.
std::string to_string(const V &v)
Definition: backports.hpp:67
static uint32_t getDefaultSize()
Definition: key-params.cpp:77
static uint32_t getDefaultSize()
Definition: key-params.cpp:93
static const uint32_t EC_KEY_SIZES[]
Definition: key-params.cpp:28
static uint32_t getDefaultSize()
Definition: key-params.cpp:61