blob: 24fa69f46a6f0a91a738c706de7b1bb23e16f8aa [file] [log] [blame]
Jeff Thompson20af0732013-09-12 17:01:45 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson20af0732013-09-12 17:01:45 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NDN_SHA256_WITH_RSA_SIGNATURE_HPP
8#define NDN_SHA256_WITH_RSA_SIGNATURE_HPP
9
10#include "data.hpp"
11#include "publisher-public-key-digest.hpp"
12
13namespace ndn {
14
15/**
16 * A Sha256WithRsaSignature extends Signature and holds the signature bits and other info representing a
17 * SHA256-with-RSA signature in a data packet.
18 */
19class Sha256WithRsaSignature : public Signature {
20public:
21 /**
22 * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature.
23 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070024 virtual ptr_lib::shared_ptr<Signature>
25 clone() const;
Jeff Thompson20af0732013-09-12 17:01:45 -070026
27 /**
28 * Set the signatureStruct to point to the values in this signature object, without copying any memory.
29 * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory.
30 * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
31 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070032 virtual void
33 get(struct ndn_Signature& signatureStruct) const;
Jeff Thompson20af0732013-09-12 17:01:45 -070034
35 /**
36 * Clear this signature, and set the values by copying from the ndn_Signature struct.
37 * @param signatureStruct a C ndn_Signature struct
38 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070039 virtual void
40 set(const struct ndn_Signature& signatureStruct);
Jeff Thompson20af0732013-09-12 17:01:45 -070041
Jeff Thompson0050abe2013-09-17 12:50:25 -070042 const Blob&
43 getDigestAlgorithm() const { return digestAlgorithm_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070044
Jeff Thompson0050abe2013-09-17 12:50:25 -070045 const Blob&
46 getWitness() const { return witness_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070047
Jeff Thompson0050abe2013-09-17 12:50:25 -070048 const Blob&
49 getSignature() const { return signature_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070050
Jeff Thompson0050abe2013-09-17 12:50:25 -070051 const PublisherPublicKeyDigest&
52 getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070053
Jeff Thompson0050abe2013-09-17 12:50:25 -070054 PublisherPublicKeyDigest&
55 getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
56
57 const KeyLocator&
58 getKeyLocator() const { return keyLocator_; }
59
60 KeyLocator&
61 getKeyLocator() { return keyLocator_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070062
Jeff Thompson0050abe2013-09-17 12:50:25 -070063 void
64 setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
65
66 void
67 setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength)
Jeff Thompson20af0732013-09-12 17:01:45 -070068 {
69 digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
70 }
71
Jeff Thompson0050abe2013-09-17 12:50:25 -070072 void
73 setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; }
74
75 void
76 setWitness(const unsigned char *witness, unsigned int witnessLength)
Jeff Thompson20af0732013-09-12 17:01:45 -070077 {
78 witness_ = Blob(witness, witnessLength);
79 }
80
Jeff Thompson0050abe2013-09-17 12:50:25 -070081 void
82 setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; }
83
84 void
85 setSignature(const unsigned char *signature, unsigned int signatureLength)
Jeff Thompson20af0732013-09-12 17:01:45 -070086 {
87 signature_ = Blob(signature, signatureLength);
88 }
89
Jeff Thompson0050abe2013-09-17 12:50:25 -070090 void
91 setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
Jeff Thompson20af0732013-09-12 17:01:45 -070092
Jeff Thompson0050abe2013-09-17 12:50:25 -070093 void
94 setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
Jeff Thompson20af0732013-09-12 17:01:45 -070095
96 /**
97 * Clear all the fields.
98 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070099 void
100 clear()
Jeff Thompson20af0732013-09-12 17:01:45 -0700101 {
102 digestAlgorithm_.reset();
103 witness_.reset();
104 signature_.reset();
105 publisherPublicKeyDigest_.clear();
106 keyLocator_.clear();
107 }
108
109private:
110 Blob digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
111 Blob witness_;
112 Blob signature_;
113 PublisherPublicKeyDigest publisherPublicKeyDigest_;
114 KeyLocator keyLocator_;
115};
116
117}
118
119#endif