ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
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-2023 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
24namespace ndn {
25
27 : m_keyType(keyType)
28 , m_keyIdType(keyIdType)
29{
30 BOOST_ASSERT(keyIdType != KeyIdType::USER_SPECIFIED);
31}
32
34 : m_keyType(keyType)
35 , m_keyIdType(KeyIdType::USER_SPECIFIED)
36 , m_keyId(keyId)
37{
38 BOOST_ASSERT(!keyId.empty());
39}
40
41KeyParams::~KeyParams() = default;
42
43namespace detail {
44
45constexpr uint32_t MIN_RSA_KEY_SIZE = 2048;
46constexpr uint32_t MAX_RSA_KEY_SIZE = 16384;
47constexpr uint32_t DEFAULT_RSA_KEY_SIZE = 2048;
48constexpr uint32_t EC_KEY_SIZES[] = {224, 256, 384, 521};
49constexpr uint32_t DEFAULT_EC_KEY_SIZE = 256;
50constexpr uint32_t AES_KEY_SIZES[] = {128, 192, 256};
51constexpr uint32_t DEFAULT_AES_KEY_SIZE = 128;
52constexpr uint32_t DEFAULT_HMAC_KEY_SIZE = 256;
53
54uint32_t
56{
57 if (size < MIN_RSA_KEY_SIZE || size > MAX_RSA_KEY_SIZE)
58 NDN_THROW(KeyParams::Error("Unsupported RSA key size " + to_string(size)));
59 return size;
60}
61
62uint32_t
67
68uint32_t
70{
71 for (auto s : EC_KEY_SIZES) {
72 if (s == size)
73 return size;
74 }
75 NDN_THROW(KeyParams::Error("Unsupported EC key size " + to_string(size)));
76}
77
78uint32_t
83
84uint32_t
85AesKeyParamsInfo::checkKeySize(uint32_t size)
86{
87 for (auto s : AES_KEY_SIZES) {
88 if (s == size)
89 return size;
90 }
91 NDN_THROW(KeyParams::Error("Unsupported AES key size " + to_string(size)));
92}
93
94uint32_t
95AesKeyParamsInfo::getDefaultSize()
96{
98}
99
100uint32_t
101HmacKeyParamsInfo::checkKeySize(uint32_t size)
102{
103 if (size == 0 || size % 8 != 0)
104 NDN_THROW(KeyParams::Error("Unsupported HMAC key size " + to_string(size)));
105 return size;
106}
107
108uint32_t
109HmacKeyParamsInfo::getDefaultSize()
110{
112}
113
114} // namespace detail
115} // namespace ndn
KeyParams(KeyType keyType, KeyIdType keyIdType)
Constructor.
virtual ~KeyParams()
static uint32_t checkKeySize(uint32_t size)
Check if size is valid and supported for this key type.
static uint32_t getDefaultSize()
static uint32_t getDefaultSize()
static uint32_t checkKeySize(uint32_t size)
Check if size is valid and supported for this key type.
Represents a name component.
bool empty() const noexcept
#define NDN_THROW(e)
Definition exception.hpp:56
constexpr uint32_t AES_KEY_SIZES[]
constexpr uint32_t MIN_RSA_KEY_SIZE
constexpr uint32_t DEFAULT_HMAC_KEY_SIZE
constexpr uint32_t DEFAULT_RSA_KEY_SIZE
constexpr uint32_t EC_KEY_SIZES[]
constexpr uint32_t DEFAULT_AES_KEY_SIZE
constexpr uint32_t DEFAULT_EC_KEY_SIZE
constexpr uint32_t MAX_RSA_KEY_SIZE
std::string to_string(const errinfo_stacktrace &x)
Definition exception.cpp:30
Definition data.cpp:25
KeyType
The type of a cryptographic key.
KeyIdType
The type of KeyId component in a key name.
@ USER_SPECIFIED
User-specified key id.