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-2019 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  }
45  return os << "Unknown(" << static_cast<uint32_t>(st) << ')';
46 }
47 
48 std::ostream&
49 operator<<(std::ostream& os, ContentTypeValue ct)
50 {
51  switch (ct) {
52  case ContentType_Blob:
53  return os << "Blob";
54  case ContentType_Link:
55  return os << "Link";
56  case ContentType_Key:
57  return os << "Key";
58  case ContentType_Nack:
59  return os << "Nack";
61  return os << "Manifest";
63  return os << "PrefixAnn";
64  case ContentType_Flic:
65  return os << "FLIC";
66  }
67 
68  if (ct >= 6 && ct <= 1023) {
69  os << "Reserved(";
70  }
71  else if (ct >= 9000 && ct <= 9999) {
72  os << "Experimental(";
73  }
74  else {
75  os << "Unknown(";
76  }
77  return os << static_cast<uint32_t>(ct) << ')';
78 }
79 
80 } // namespace tlv
81 } // namespace ndn
Represents a signature of Sha256WithRsa type.
Definition: data.cpp:26
std::ostream & operator<<(std::ostream &os, SignatureTypeValue st)
Definition: tlv.cpp:33
public key, certificate
Definition: tlv.hpp:159
Represents a signature of DigestSha256 type.
prefix announcement
Definition: tlv.hpp:162
File-Like ICN Collection.
Definition: tlv.hpp:163
another name that identifies the actual data content
Definition: tlv.hpp:158
Represents a signature of Sha256WithEcdsa type.
ContentTypeValue
ContentType values.
Definition: tlv.hpp:156
SignatureTypeValue
SignatureType values.
Definition: tlv.hpp:129
application-level nack
Definition: tlv.hpp:160
std::string to_string(const V &v)
Definition: backports.hpp:67
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
represents an error in TLV encoding or decoding
Definition: tlv.hpp:52