Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 4 | * 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 Thompson | bad29b3 | 2013-09-17 14:23:41 -0700 | [diff] [blame] | 11 | #include "key.hpp" |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 12 | #include "publisher-public-key-digest.hpp" |
| 13 | |
| 14 | namespace 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 | */ |
| 20 | class Sha256WithRsaSignature : public Signature { |
| 21 | public: |
| 22 | /** |
| 23 | * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature. |
| 24 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 25 | virtual ptr_lib::shared_ptr<Signature> |
| 26 | clone() const; |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 27 | |
| 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 Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 33 | virtual void |
| 34 | get(struct ndn_Signature& signatureStruct) const; |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 35 | |
| 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 Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 40 | virtual void |
| 41 | set(const struct ndn_Signature& signatureStruct); |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 42 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 43 | const Blob& |
| 44 | getDigestAlgorithm() const { return digestAlgorithm_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 45 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 46 | const Blob& |
| 47 | getWitness() const { return witness_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 48 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 49 | const Blob& |
| 50 | getSignature() const { return signature_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 51 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 52 | const PublisherPublicKeyDigest& |
| 53 | getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 54 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 55 | PublisherPublicKeyDigest& |
| 56 | getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 57 | |
| 58 | const KeyLocator& |
| 59 | getKeyLocator() const { return keyLocator_; } |
| 60 | |
| 61 | KeyLocator& |
| 62 | getKeyLocator() { return keyLocator_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 63 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 64 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 65 | setDigestAlgorithm(const std::vector<uint8_t>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 66 | |
| 67 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 68 | setDigestAlgorithm(const uint8_t *digestAlgorithm, unsigned int digestAlgorithmLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 69 | { |
| 70 | digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength); |
| 71 | } |
| 72 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 73 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 74 | setWitness(const std::vector<uint8_t>& witness) { witness_ = witness; } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 75 | |
| 76 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 77 | setWitness(const uint8_t *witness, unsigned int witnessLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 78 | { |
| 79 | witness_ = Blob(witness, witnessLength); |
| 80 | } |
| 81 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 82 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 83 | setSignature(const std::vector<uint8_t>& signature) { signature_ = signature; } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 84 | |
| 85 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 86 | setSignature(const uint8_t *signature, unsigned int signatureLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 87 | { |
| 88 | signature_ = Blob(signature, signatureLength); |
| 89 | } |
| 90 | |
Jeff Thompson | bad29b3 | 2013-09-17 14:23:41 -0700 | [diff] [blame] | 91 | /** |
| 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 Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 97 | setSignature(const ptr_lib::shared_ptr<std::vector<uint8_t> > &signature) { signature_ = signature; } |
Jeff Thompson | bad29b3 | 2013-09-17 14:23:41 -0700 | [diff] [blame] | 98 | |
| 99 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 100 | setSignature(const ptr_lib::shared_ptr<const std::vector<uint8_t> > &signature) { signature_ = signature; } |
Jeff Thompson | bad29b3 | 2013-09-17 14:23:41 -0700 | [diff] [blame] | 101 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 102 | void |
| 103 | setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 104 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 105 | void |
| 106 | setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * Clear all the fields. |
| 110 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 111 | void |
| 112 | clear() |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 113 | { |
| 114 | digestAlgorithm_.reset(); |
| 115 | witness_.reset(); |
| 116 | signature_.reset(); |
| 117 | publisherPublicKeyDigest_.clear(); |
| 118 | keyLocator_.clear(); |
| 119 | } |
| 120 | |
| 121 | private: |
| 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 |