Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_SHA256_WITH_RSA_SIGNATURE_HPP |
| 9 | #define NDN_SHA256_WITH_RSA_SIGNATURE_HPP |
| 10 | |
| 11 | #include "data.hpp" |
Jeff Thompson | bad29b3 | 2013-09-17 14:23:41 -0700 | [diff] [blame] | 12 | #include "key.hpp" |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 13 | #include "publisher-public-key-digest.hpp" |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | /** |
| 18 | * A Sha256WithRsaSignature extends Signature and holds the signature bits and other info representing a |
| 19 | * SHA256-with-RSA signature in a data packet. |
| 20 | */ |
| 21 | class Sha256WithRsaSignature : public Signature { |
| 22 | public: |
| 23 | /** |
| 24 | * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature. |
| 25 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 26 | virtual ptr_lib::shared_ptr<Signature> |
| 27 | clone() const; |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Set the signatureStruct to point to the values in this signature object, without copying any memory. |
| 31 | * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory. |
| 32 | * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated. |
| 33 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 34 | virtual void |
| 35 | get(struct ndn_Signature& signatureStruct) const; |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Clear this signature, and set the values by copying from the ndn_Signature struct. |
| 39 | * @param signatureStruct a C ndn_Signature struct |
| 40 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 41 | virtual void |
| 42 | set(const struct ndn_Signature& signatureStruct); |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 43 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 44 | const Blob& |
| 45 | getDigestAlgorithm() const { return digestAlgorithm_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 46 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 47 | const Blob& |
| 48 | getWitness() const { return witness_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 49 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 50 | const Blob& |
| 51 | getSignature() const { return signature_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 52 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 53 | const PublisherPublicKeyDigest& |
| 54 | getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 55 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 56 | PublisherPublicKeyDigest& |
| 57 | getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 58 | |
| 59 | const KeyLocator& |
| 60 | getKeyLocator() const { return keyLocator_; } |
| 61 | |
| 62 | KeyLocator& |
| 63 | getKeyLocator() { return keyLocator_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 64 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 65 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 66 | setDigestAlgorithm(const std::vector<uint8_t>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 67 | |
| 68 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 69 | setDigestAlgorithm(const uint8_t *digestAlgorithm, size_t digestAlgorithmLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 70 | { |
| 71 | digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength); |
| 72 | } |
| 73 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 74 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 75 | setWitness(const std::vector<uint8_t>& witness) { witness_ = witness; } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 76 | |
| 77 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 78 | setWitness(const uint8_t *witness, size_t witnessLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 79 | { |
| 80 | witness_ = Blob(witness, witnessLength); |
| 81 | } |
| 82 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 83 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 84 | setSignature(const std::vector<uint8_t>& signature) { signature_ = signature; } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 85 | |
| 86 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 87 | setSignature(const uint8_t *signature, size_t signatureLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 88 | { |
| 89 | signature_ = Blob(signature, signatureLength); |
| 90 | } |
| 91 | |
Jeff Thompson | bad29b3 | 2013-09-17 14:23:41 -0700 | [diff] [blame] | 92 | /** |
| 93 | * Set signature to point to an existing byte array. IMPORTANT: After calling this, |
| 94 | * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it. |
| 95 | * @param signature A pointer to a vector with the byte array. This takes another reference and does not copy the bytes. |
| 96 | */ |
| 97 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 98 | 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] | 99 | |
| 100 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 101 | 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] | 102 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 103 | void |
| 104 | setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 105 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 106 | void |
| 107 | setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Clear all the fields. |
| 111 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 112 | void |
| 113 | clear() |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 114 | { |
| 115 | digestAlgorithm_.reset(); |
| 116 | witness_.reset(); |
| 117 | signature_.reset(); |
| 118 | publisherPublicKeyDigest_.clear(); |
| 119 | keyLocator_.clear(); |
| 120 | } |
| 121 | |
| 122 | private: |
| 123 | Blob digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */ |
| 124 | Blob witness_; |
| 125 | Blob signature_; |
| 126 | PublisherPublicKeyDigest publisherPublicKeyDigest_; |
| 127 | KeyLocator keyLocator_; |
| 128 | }; |
| 129 | |
| 130 | } |
| 131 | |
| 132 | #endif |