blob: 2d5c4ce4be09b8e077ea4650e77ab9f806e7188a [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"
Jeff Thompsonbad29b32013-09-17 14:23:41 -070011#include "key.hpp"
Jeff Thompson20af0732013-09-12 17:01:45 -070012#include "publisher-public-key-digest.hpp"
13
14namespace ndn {
15
16/**
17 * A Sha256WithRsaSignature extends Signature and holds the signature bits and other info representing a
18 * SHA256-with-RSA signature in a data packet.
19 */
20class Sha256WithRsaSignature : public Signature {
21public:
22 /**
23 * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature.
24 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070025 virtual ptr_lib::shared_ptr<Signature>
26 clone() const;
Jeff Thompson20af0732013-09-12 17:01:45 -070027
28 /**
29 * Set the signatureStruct to point to the values in this signature object, without copying any memory.
30 * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory.
31 * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
32 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070033 virtual void
34 get(struct ndn_Signature& signatureStruct) const;
Jeff Thompson20af0732013-09-12 17:01:45 -070035
36 /**
37 * Clear this signature, and set the values by copying from the ndn_Signature struct.
38 * @param signatureStruct a C ndn_Signature struct
39 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070040 virtual void
41 set(const struct ndn_Signature& signatureStruct);
Jeff Thompson20af0732013-09-12 17:01:45 -070042
Jeff Thompson0050abe2013-09-17 12:50:25 -070043 const Blob&
44 getDigestAlgorithm() const { return digestAlgorithm_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070045
Jeff Thompson0050abe2013-09-17 12:50:25 -070046 const Blob&
47 getWitness() const { return witness_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070048
Jeff Thompson0050abe2013-09-17 12:50:25 -070049 const Blob&
50 getSignature() const { return signature_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070051
Jeff Thompson0050abe2013-09-17 12:50:25 -070052 const PublisherPublicKeyDigest&
53 getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070054
Jeff Thompson0050abe2013-09-17 12:50:25 -070055 PublisherPublicKeyDigest&
56 getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
57
58 const KeyLocator&
59 getKeyLocator() const { return keyLocator_; }
60
61 KeyLocator&
62 getKeyLocator() { return keyLocator_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070063
Jeff Thompson0050abe2013-09-17 12:50:25 -070064 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070065 setDigestAlgorithm(const std::vector<uint8_t>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
Jeff Thompson0050abe2013-09-17 12:50:25 -070066
67 void
Jeff Thompson97223af2013-09-24 17:01:27 -070068 setDigestAlgorithm(const uint8_t *digestAlgorithm, size_t digestAlgorithmLength)
Jeff Thompson20af0732013-09-12 17:01:45 -070069 {
70 digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
71 }
72
Jeff Thompson0050abe2013-09-17 12:50:25 -070073 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070074 setWitness(const std::vector<uint8_t>& witness) { witness_ = witness; }
Jeff Thompson0050abe2013-09-17 12:50:25 -070075
76 void
Jeff Thompson97223af2013-09-24 17:01:27 -070077 setWitness(const uint8_t *witness, size_t witnessLength)
Jeff Thompson20af0732013-09-12 17:01:45 -070078 {
79 witness_ = Blob(witness, witnessLength);
80 }
81
Jeff Thompson0050abe2013-09-17 12:50:25 -070082 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070083 setSignature(const std::vector<uint8_t>& signature) { signature_ = signature; }
Jeff Thompson0050abe2013-09-17 12:50:25 -070084
85 void
Jeff Thompson97223af2013-09-24 17:01:27 -070086 setSignature(const uint8_t *signature, size_t signatureLength)
Jeff Thompson20af0732013-09-12 17:01:45 -070087 {
88 signature_ = Blob(signature, signatureLength);
89 }
90
Jeff Thompsonbad29b32013-09-17 14:23:41 -070091 /**
92 * Set signature to point to an existing byte array. IMPORTANT: After calling this,
93 * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
94 * @param signature A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
95 */
96 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070097 setSignature(const ptr_lib::shared_ptr<std::vector<uint8_t> > &signature) { signature_ = signature; }
Jeff Thompsonbad29b32013-09-17 14:23:41 -070098
99 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -0700100 setSignature(const ptr_lib::shared_ptr<const std::vector<uint8_t> > &signature) { signature_ = signature; }
Jeff Thompsonbad29b32013-09-17 14:23:41 -0700101
Jeff Thompson0050abe2013-09-17 12:50:25 -0700102 void
103 setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
Jeff Thompson20af0732013-09-12 17:01:45 -0700104
Jeff Thompson0050abe2013-09-17 12:50:25 -0700105 void
106 setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
Jeff Thompson20af0732013-09-12 17:01:45 -0700107
108 /**
109 * Clear all the fields.
110 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700111 void
112 clear()
Jeff Thompson20af0732013-09-12 17:01:45 -0700113 {
114 digestAlgorithm_.reset();
115 witness_.reset();
116 signature_.reset();
117 publisherPublicKeyDigest_.clear();
118 keyLocator_.clear();
119 }
120
121private:
122 Blob digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
123 Blob witness_;
124 Blob signature_;
125 PublisherPublicKeyDigest publisherPublicKeyDigest_;
126 KeyLocator keyLocator_;
127};
128
129}
130
131#endif