NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
signing-info.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "signing-info.hpp"
23 #include "key-chain.hpp"
24 
25 namespace ndn {
26 namespace security {
27 
30 
32  const Name& signerName,
33  const SignatureInfo& signatureInfo)
34  : m_type(signerType)
35  , m_name(signerName)
36  , m_digestAlgorithm(DigestAlgorithm::SHA256)
37  , m_info(signatureInfo)
38 {
39 }
40 
41 SigningInfo::SigningInfo(const std::string& signingStr)
42 {
43  *this = SigningInfo();
44 
45  if (signingStr.empty()) {
46  return;
47  }
48 
49  size_t pos = signingStr.find(':');
50 
51  if (pos == std::string::npos) {
52  BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid signing string cannot represent SigningInfo"));
53  }
54 
55  std::string scheme = signingStr.substr(0, pos);
56  std::string nameArg = signingStr.substr(pos + 1);
57 
58  if (scheme == "id") {
59  if (nameArg == KeyChain::DIGEST_SHA256_IDENTITY.toUri()) {
61  }
62  else {
63  setSigningIdentity(nameArg);
64  }
65  }
66  else if (scheme == "key") {
67  setSigningKeyName(nameArg);
68  }
69  else if (scheme == "cert") {
70  setSigningCertName(nameArg);
71  }
72  else {
73  BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid signing string scheme"));
74  }
75 }
76 
77 void
79 {
80  m_type = SIGNER_TYPE_ID;
81  m_name = identity;
82 }
83 void
85 {
86  m_type = SIGNER_TYPE_KEY;
87  m_name = keyName;
88 }
89 
90 void
91 SigningInfo::setSigningCertName(const Name& certificateName)
92 {
93  m_type = SIGNER_TYPE_CERT;
94  m_name = certificateName;
95 }
96 
97 void
99 {
100  m_type = SIGNER_TYPE_SHA256;
101  m_name.clear();
102 }
103 
104 void
106 {
107  m_info = signatureInfo;
108 }
109 
110 std::ostream&
111 operator<<(std::ostream& os, const SigningInfo& si)
112 {
113  switch (si.getSignerType()) {
115  return os;
117  os << "id:";
118  break;
120  os << "key:";
121  break;
123  os << "cert:";
124  break;
126  os << "id:" << KeyChain::DIGEST_SHA256_IDENTITY;
127  return os;
128  default:
129  BOOST_THROW_EXCEPTION(std::invalid_argument("Unknown signer type"));
130  }
131 
132  os << si.getSignerName();
133  return os;
134 }
135 
136 } // namespace security
137 } // namespace ndn
SigningInfo(SignerType signerType=SIGNER_TYPE_NULL, const Name &signerName=EMPTY_NAME, const SignatureInfo &signatureInfo=EMPTY_SIGNATURE_INFO)
Constructor.
Copyright (c) 2011-2015 Regents of the University of California.
void setSigningCertName(const Name &certificateName)
Set signer as a certificate with name certificateName.
use sha256 digest, no signer needs to be specified
Signing parameters passed to KeyChain.
std::ostream & operator<<(std::ostream &os, CommandInterestValidator::ErrorCode error)
const Name & getSignerName() const
static const Name EMPTY_NAME
void setSigningIdentity(const Name &identity)
Set signer as an identity with name identity.
no signer is specified, use default setting or follow the trust schema
void setSha256Signing()
Set Sha256 as the signing method.
void setSignatureInfo(const SignatureInfo &signatureInfo)
Set a semi-prepared SignatureInfo;.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
signer is a certificate, use it directly
signer is a key, use its default certificate
void setSigningKeyName(const Name &keyName)
Set signer as a key with name keyName.
signer is an identity, use its default key and default certificate
static const Name DIGEST_SHA256_IDENTITY
A localhost identity which indicates that signature is generated using SHA-256.
Definition: key-chain.hpp:878
static const SignatureInfo EMPTY_SIGNATURE_INFO
void clear()
Clear all the components.
Definition: name.hpp:210
SignerType getSignerType() const