blob: 64b62b6c2d6df5fcda6bddc7d52176f2582ab0d1 [file] [log] [blame]
Jeff Thompson20af0732013-09-12 17:01:45 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#ifndef NDN_SHA256_WITH_RSA_SIGNATURE_HPP
7#define NDN_SHA256_WITH_RSA_SIGNATURE_HPP
8
9#include "data.hpp"
10#include "publisher-public-key-digest.hpp"
11
12namespace ndn {
13
14/**
15 * A Sha256WithRsaSignature extends Signature and holds the signature bits and other info representing a
16 * SHA256-with-RSA signature in a data packet.
17 */
18class Sha256WithRsaSignature : public Signature {
19public:
20 /**
21 * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature.
22 */
23 virtual ptr_lib::shared_ptr<Signature> clone() const;
24
25 /**
26 * Set the signatureStruct to point to the values in this signature object, without copying any memory.
27 * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory.
28 * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
29 */
30 virtual void get(struct ndn_Signature& signatureStruct) const;
31
32 /**
33 * Clear this signature, and set the values by copying from the ndn_Signature struct.
34 * @param signatureStruct a C ndn_Signature struct
35 */
36 virtual void set(const struct ndn_Signature& signatureStruct);
37
38 const Blob& getDigestAlgorithm() const { return digestAlgorithm_; }
39
40 const Blob& getWitness() const { return witness_; }
41
42 const Blob& getSignature() const { return signature_; }
43
44 const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
45 PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
46
47 const KeyLocator& getKeyLocator() const { return keyLocator_; }
48 KeyLocator& getKeyLocator() { return keyLocator_; }
49
50 void setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
51 void setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength)
52 {
53 digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
54 }
55
56 void setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; }
57 void setWitness(const unsigned char *witness, unsigned int witnessLength)
58 {
59 witness_ = Blob(witness, witnessLength);
60 }
61
62 void setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; }
63 void setSignature(const unsigned char *signature, unsigned int signatureLength)
64 {
65 signature_ = Blob(signature, signatureLength);
66 }
67
68 void setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
69
70 void setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
71
72 /**
73 * Clear all the fields.
74 */
75 void clear()
76 {
77 digestAlgorithm_.reset();
78 witness_.reset();
79 signature_.reset();
80 publisherPublicKeyDigest_.clear();
81 keyLocator_.clear();
82 }
83
84private:
85 Blob digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
86 Blob witness_;
87 Blob signature_;
88 PublisherPublicKeyDigest publisherPublicKeyDigest_;
89 KeyLocator keyLocator_;
90};
91
92}
93
94#endif