validation-error.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::security {
28 
29 std::ostream&
30 operator<<(std::ostream& os, ValidationError::Code code)
31 {
32  switch (code) {
34  return os << "No error";
36  return os << "Signature verification failed";
38  return os << "Missing or malformed signature";
40  return os << "Cannot retrieve certificate";
42  return os << "Certificate expired or not yet valid";
44  return os << "Loop detected in certification chain";
46  return os << "Malformed certificate";
48  return os << "Exceeded validation depth limit";
50  return os << "Invalid key locator";
52  return os << "Policy violation";
54  return os << "Internal error";
56  break;
57  }
58  if (code >= ValidationError::Code::USER_MIN) {
59  return os << "Custom error code " << to_underlying(code);
60  }
61  else {
62  return os << "Unknown error code " << to_underlying(code);
63  }
64 }
65 
66 void
67 ValidationError::print(std::ostream& os) const
68 {
69  os << m_code;
70  if (!m_info.empty()) {
71  os << " (" << m_info << ")";
72  }
73 }
74 
75 } // namespace ndn::security
Code
Known error codes that can be returned by the Validator interface.
@ CANNOT_RETRIEVE_CERT
The certificate cannot be retrieved.
@ INVALID_KEY_LOCATOR
The KeyLocator element is missing or has an invalid format.
@ EXCEEDED_DEPTH_LIMIT
Exceeded validation depth limit.
@ MALFORMED_CERT
The certificate is malformed.
@ EXPIRED_CERT
The certificate expired or is not yet valid.
@ POLICY_ERROR
The packet violates the validation rules enforced by the policy.
@ INVALID_SIGNATURE
Signature verification failed.
@ IMPLEMENTATION_ERROR
Internal implementation error.
@ USER_MIN
Third-party validator implementations can use error codes greater than or equal to this value to indi...
@ LOOP_DETECTED
Loop detected in the certification chain.
@ MALFORMED_SIGNATURE
The signature (e.g., SignatureInfo element) is missing or malformed.
Contains the ndn-cxx security framework.
std::ostream & operator<<(std::ostream &os, const AdditionalDescription &desc)
constexpr std::underlying_type_t< T > to_underlying(T val) noexcept
Definition: backports.hpp:44