security-common.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2024 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 
24 
25 #include <ostream>
26 
27 namespace ndn {
28 
29 std::ostream&
30 operator<<(std::ostream& os, KeyIdType keyIdType)
31 {
32  switch (keyIdType) {
34  return os << "USER-SPECIFIED";
35  case KeyIdType::SHA256:
36  return os << "SHA256";
37  case KeyIdType::RANDOM:
38  return os << "RANDOM";
39  }
40  return os << to_underlying(keyIdType);
41 }
42 
43 std::ostream&
44 operator<<(std::ostream& os, KeyType keyType)
45 {
46  switch (keyType) {
47  case KeyType::NONE:
48  return os << "NONE";
49  case KeyType::RSA:
50  return os << "RSA";
51  case KeyType::EC:
52  return os << "EC";
53  case KeyType::AES:
54  return os << "AES";
55  case KeyType::HMAC:
56  return os << "HMAC";
57  }
58  return os << to_underlying(keyType);
59 }
60 
61 std::ostream&
62 operator<<(std::ostream& os, DigestAlgorithm algorithm)
63 {
64  switch (algorithm) {
66  return os << "NONE";
68  return os << "SHA224";
70  return os << "SHA256";
72  return os << "SHA384";
74  return os << "SHA512";
76  return os << "BLAKE2b-512";
78  return os << "BLAKE2s-256";
80  return os << "SHA3-224";
82  return os << "SHA3-256";
84  return os << "SHA3-384";
86  return os << "SHA3-512";
87  }
88  return os << to_underlying(algorithm);
89 }
90 
91 std::ostream&
92 operator<<(std::ostream& os, BlockCipherAlgorithm algorithm)
93 {
94  switch (algorithm) {
96  return os << "NONE";
98  return os << "AES-CBC";
99  }
100  return os << to_underlying(algorithm);
101 }
102 
103 std::ostream&
104 operator<<(std::ostream& os, CipherOperator op)
105 {
106  switch (op) {
108  return os << "DECRYPT";
110  return os << "ENCRYPT";
111  }
112  return os << to_underlying(op);
113 }
114 
115 } // namespace ndn
Definition: data.cpp:25
KeyType
The type of a cryptographic key.
@ EC
Elliptic Curve key (e.g. for ECDSA), supports sign/verify operations.
@ RSA
RSA key, supports sign/verify and encrypt/decrypt operations.
@ AES
AES key, supports encrypt/decrypt operations.
@ NONE
Unknown or unsupported key type.
@ HMAC
HMAC key, supports sign/verify operations.
KeyIdType
The type of KeyId component in a key name.
@ RANDOM
Use a 64-bit random number as key id.
@ USER_SPECIFIED
User-specified key id.
@ SHA256
Use the SHA-256 hash of the public key as key id.
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:377
BlockCipherAlgorithm
constexpr std::underlying_type_t< T > to_underlying(T val) noexcept
Definition: backports.hpp:44