tlv.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 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 
22 #include "ndn-cxx/encoding/tlv.hpp"
23 
24 namespace ndn {
25 namespace tlv {
26 
27 Error::Error(const char* expectedType, uint32_t actualType)
28  : Error("Expecting "s + expectedType + " element, but TLV has type " + to_string(actualType))
29 {
30 }
31 
32 std::ostream&
33 operator<<(std::ostream& os, SignatureTypeValue st)
34 {
35  switch (st) {
36  case DigestSha256:
37  return os << "DigestSha256";
39  return os << "SignatureSha256WithRsa";
41  return os << "SignatureSha256WithEcdsa";
43  return os << "SignatureHmacWithSha256";
44  case SignatureEd25519:
45  return os << "SignatureEd25519";
46  case NullSignature:
47  return os << "NullSignature";
48  }
49  return os << "Unknown(" << static_cast<uint32_t>(st) << ')';
50 }
51 
52 std::ostream&
53 operator<<(std::ostream& os, ContentTypeValue ct)
54 {
55  switch (ct) {
56  case ContentType_Blob:
57  return os << "Blob";
58  case ContentType_Link:
59  return os << "Link";
60  case ContentType_Key:
61  return os << "Key";
62  case ContentType_Nack:
63  return os << "Nack";
65  return os << "Manifest";
67  return os << "PrefixAnn";
68  case ContentType_Flic:
69  return os << "FLIC";
70  }
71 
72  if (ct <= 1023) {
73  os << "Reserved(";
74  }
75  else if (ct >= 9000 && ct <= 9999) {
76  os << "Experimental(";
77  }
78  else {
79  os << "Unknown(";
80  }
81  return os << static_cast<uint32_t>(ct) << ')';
82 }
83 
84 } // namespace tlv
85 } // namespace ndn
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
std::string to_string(const errinfo_stacktrace &x)
Definition: exception.cpp:31
ContentTypeValue
ContentType values.
Definition: tlv.hpp:144
@ ContentType_Key
public key, certificate
Definition: tlv.hpp:147
@ ContentType_Manifest
Definition: tlv.hpp:149
@ ContentType_Link
another name that identifies the actual data content
Definition: tlv.hpp:146
@ ContentType_Blob
payload
Definition: tlv.hpp:145
@ ContentType_Flic
File-Like ICN Collection.
Definition: tlv.hpp:151
@ ContentType_PrefixAnn
prefix announcement
Definition: tlv.hpp:150
@ ContentType_Nack
application-level nack
Definition: tlv.hpp:148
std::ostream & operator<<(std::ostream &os, SignatureTypeValue st)
Definition: tlv.cpp:33
SignatureTypeValue
SignatureType values.
Definition: tlv.hpp:127
@ SignatureSha256WithRsa
Definition: tlv.hpp:129
@ DigestSha256
Definition: tlv.hpp:128
@ SignatureHmacWithSha256
Definition: tlv.hpp:131
@ SignatureEd25519
Definition: tlv.hpp:132
@ SignatureSha256WithEcdsa
Definition: tlv.hpp:130
@ NullSignature
Definition: tlv.hpp:133
Definition: data.cpp:25