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 |
| 65 | setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; } |
| 66 | |
| 67 | void |
| 68 | setDigestAlgorithm(const unsigned char *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 |
| 74 | setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; } |
| 75 | |
| 76 | void |
| 77 | setWitness(const unsigned char *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 |
| 83 | setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; } |
| 84 | |
| 85 | void |
| 86 | setSignature(const unsigned char *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 |
| 97 | setSignature(const ptr_lib::shared_ptr<std::vector<unsigned char> > &signature) { signature_ = signature; } |
| 98 | |
| 99 | void |
| 100 | setSignature(const ptr_lib::shared_ptr<const std::vector<unsigned char> > &signature) { signature_ = signature; } |
| 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 |