blob: 661276fef95977a8f465cc843640ff2c3544de77 [file] [log] [blame]
Yingdi Yu1b0311c2015-06-10 14:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 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#ifndef NDN_SECURITY_SIGNING_INFO_HPP
23#define NDN_SECURITY_SIGNING_INFO_HPP
24
25#include "../name.hpp"
26#include "../signature-info.hpp"
27#include "security-common.hpp"
28
29
30namespace ndn {
31namespace security {
32
33/**
34 * @brief Signing parameters passed to KeyChain
35 */
36class SigningInfo
37{
38public:
39 class Error : public std::runtime_error
40 {
41 public:
42 explicit
43 Error(const std::string& what)
44 : std::runtime_error(what)
45 {
46 }
47 };
48
49 enum SignerType {
50 /// @brief no signer is specified, use default setting or follow the trust schema
51 SIGNER_TYPE_NULL = 0,
52 /// @brief signer is an identity, use its default key and default certificate
53 SIGNER_TYPE_ID = 1,
54 /// @brief signer is a key, use its default certificate
55 SIGNER_TYPE_KEY = 2,
56 /// @brief signer is a certificate, use it directly
57 SIGNER_TYPE_CERT = 3,
58 /// @brief use sha256 digest, no signer needs to be specified
59 SIGNER_TYPE_SHA256 = 4
60 };
61
62public:
63 /**
64 * @brief Constructor
65 *
66 * @param signerType The type of signer
67 * @param signerName The name of signer; interpretation differs per signerType
68 * @param signatureInfo A semi-prepared SignatureInfo which contains other information except
69 * SignatureType and KeyLocator. If SignatureType and KeyLocator are
70 * specified, they may be overwritten by KeyChain.
71 */
72 explicit
73 SigningInfo(SignerType signerType = SIGNER_TYPE_NULL,
74 const Name& signerName = EMPTY_NAME,
75 const SignatureInfo& signatureInfo = EMPTY_SIGNATURE_INFO);
76
77 /**
78 * @brief Set signer as an identity with name @p identity
79 * @post Change the signerType to SIGNER_TYPE_ID
80 */
81 void
82 setSigningIdentity(const Name& identity);
83
84 /**
85 * @brief Set signer as a key with name @p keyName
86 * @post Change the signerType to SIGNER_TYPE_KEY
87 */
88 void
89 setSigningKeyName(const Name& keyName);
90
91 /**
92 * @brief Set signer as a certificate with name @p certificateName
93 * @post Change the signerType to SIGNER_TYPE_CERT
94 */
95 void
96 setSigningCertName(const Name& certificateName);
97
98 /**
99 * @brief Set Sha256 as the signing method
100 * @post Reset signerName, also change the signerType to SIGNER_TYPE_SHA256
101 */
102 void
103 setSha256Signing();
104
105 /**
106 * @return Type of the signer
107 */
108 SignerType
109 getSignerType() const
110 {
111 return m_type;
112 }
113
114 /**
115 * @return Name of signer; interpretation differs per signerType
116 */
117 const Name&
118 getSignerName() const
119 {
120 return m_name;
121 }
122
123 /**
124 * @brief Set the digest algorithm for public key operations
125 */
126 void
127 setDigestAlgorithm(const DigestAlgorithm& algorithm)
128 {
129 m_digestAlgorithm = algorithm;
130 }
131
132 /**
133 * @return The digest algorithm for public key operations
134 */
135 DigestAlgorithm
136 getDigestAlgorithm() const
137 {
138 return m_digestAlgorithm;
139 }
140
141 /**
142 * @brief Set a semi-prepared SignatureInfo;
143 */
144 void
145 setSignatureInfo(const SignatureInfo& signatureInfo);
146
147 /**
148 * @return Semi-prepared SignatureInfo
149 */
150 const SignatureInfo&
151 getSignatureInfo() const
152 {
153 return m_info;
154 }
155
156public:
157 static const Name EMPTY_NAME;
158 static const SignatureInfo EMPTY_SIGNATURE_INFO;
159
160private:
161 SignerType m_type;
162 Name m_name;
163
164 DigestAlgorithm m_digestAlgorithm;
165
166 SignatureInfo m_info;
167};
168
169} // namespace security
170} // namespace ndn
171
172#endif // NDN_SECURITY_SIGNING_INFO_HPP