All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
verification-helpers.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_VERIFICATION_HELPERS_HPP
24 #define NDN_VERIFICATION_HELPERS_HPP
25 
26 #include "../interest.hpp"
27 #include "certificate/public-key.hpp"
28 #include "v2/certificate-v2.hpp"
29 
30 namespace ndn {
31 
37 public:
49  static bool
51  (const uint8_t* buffer, size_t bufferLength, const uint8_t* signature,
52  size_t signatureLength, const PublicKey& publicKey,
53  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256);
54 
64  static bool
66  (const Blob& buffer, const Blob& signature, const PublicKey& publicKey,
67  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256)
68  {
69  return verifySignature
70  (buffer.buf(), buffer.size(), signature.buf(), signature.size(),
71  publicKey, digestAlgorithm);
72  }
73 
90  static bool
92  (const uint8_t* buffer, size_t bufferLength, const uint8_t* signature,
93  size_t signatureLength, const Blob& publicKeyDer,
94  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256);
95 
110  static bool
112  (const Blob& buffer, const Blob& signature, const Blob& publicKeyDer,
113  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256)
114  {
115  return verifySignature
116  (buffer.buf(), buffer.size(), signature.buf(), signature.size(),
117  publicKeyDer, digestAlgorithm);
118  }
119 
132  static bool
134  (const Data& data, const PublicKey& publicKey,
135  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256,
137 
155  static bool
157  (const Data& data, const Blob& publicKeyDer,
158  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256,
160 
174  static bool
176  (const Data& data, const CertificateV2& certificate,
177  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256,
179  {
180  return verifyDataSignature
181  (data, certificate.getPublicKey(), digestAlgorithm, wireFormat);
182  }
183 
198  static bool
200  (const Interest& interest, const PublicKey& publicKey,
201  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256,
203 
222  static bool
224  (const Interest& interest, const Blob& publicKeyDer,
225  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256,
227 
242  static bool
244  (const Interest& interest, const CertificateV2& certificate,
245  DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256,
247  {
249  (interest, certificate.getPublicKey(), digestAlgorithm, wireFormat);
250  }
251 
253 
264  static bool
266  (const uint8_t* buffer, size_t bufferLength, const uint8_t* digest,
267  size_t digestLength, DigestAlgorithm digestAlgorithm);
268 
277  static bool
279  (const Blob& buffer, const Blob& digest, DigestAlgorithm digestAlgorithm)
280  {
281  return verifyDigest
282  (buffer.buf(), buffer.size(), digest.buf(), digest.size(),
283  digestAlgorithm);
284  }
285 
297  static bool
299  (const Data& data, DigestAlgorithm digestAlgorithm,
301 
315  static bool
317  (const Interest& interest, DigestAlgorithm digestAlgorithm,
319 
320 private:
328  static ptr_lib::shared_ptr<Signature>
329  extractSignature(const Interest& interest, WireFormat& wireFormat);
330 };
331 
332 }
333 
334 #endif
Definition: data.hpp:37
static bool verifyInterestDigest(const Interest &interest, DigestAlgorithm digestAlgorithm, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Verify the Interest packet using the digest algorithm, where the last two name components are the Sig...
Definition: verification-helpers.cpp:184
The VerificationHelpers class has static methods to verify signatures and digests.
Definition: verification-helpers.hpp:36
static bool verifyDataSignature(const Data &data, const PublicKey &publicKey, DigestAlgorithm digestAlgorithm=DIGEST_ALGORITHM_SHA256, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Verify the Data packet using the public key.
Definition: verification-helpers.cpp:87
CertificateV2 represents a certificate following the certificate format naming convention.
Definition: certificate-v2.hpp:81
static bool verifyInterestSignature(const Interest &interest, const PublicKey &publicKey, DigestAlgorithm digestAlgorithm=DIGEST_ALGORITHM_SHA256, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Verify the Interest packet using the public key, where the last two name components are the Signature...
Definition: verification-helpers.cpp:118
static bool verifySignature(const uint8_t *buffer, size_t bufferLength, const uint8_t *signature, size_t signatureLength, const PublicKey &publicKey, DigestAlgorithm digestAlgorithm=DIGEST_ALGORITHM_SHA256)
Verify the buffer against the signature using the public key.
Definition: verification-helpers.cpp:36
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:43
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:159
Definition: public-key.hpp:34
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:147
static bool verifyDigest(const uint8_t *buffer, size_t bufferLength, const uint8_t *digest, size_t digestLength, DigestAlgorithm digestAlgorithm)
Verify the buffer against the digest using the digest algorithm.
Definition: verification-helpers.cpp:154
const Blob & getPublicKey() const
Get the public key DER encoding.
Definition: certificate-v2.cpp:66
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
Definition: wire-format.hpp:39
static bool verifyDataDigest(const Data &data, DigestAlgorithm digestAlgorithm, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Verify the Data packet using the digest algorithm.
Definition: verification-helpers.cpp:167