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" |
| 11 | #include "publisher-public-key-digest.hpp" |
| 12 | |
| 13 | namespace 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 | */ |
| 19 | class Sha256WithRsaSignature : public Signature { |
| 20 | public: |
| 21 | /** |
| 22 | * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature. |
| 23 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 24 | virtual ptr_lib::shared_ptr<Signature> |
| 25 | clone() const; |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 26 | |
| 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 Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 32 | virtual void |
| 33 | get(struct ndn_Signature& signatureStruct) const; |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 34 | |
| 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 Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 39 | virtual void |
| 40 | set(const struct ndn_Signature& signatureStruct); |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 41 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 42 | const Blob& |
| 43 | getDigestAlgorithm() const { return digestAlgorithm_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 44 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 45 | const Blob& |
| 46 | getWitness() const { return witness_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 47 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 48 | const Blob& |
| 49 | getSignature() const { return signature_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 50 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 51 | const PublisherPublicKeyDigest& |
| 52 | getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 53 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 54 | PublisherPublicKeyDigest& |
| 55 | getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 56 | |
| 57 | const KeyLocator& |
| 58 | getKeyLocator() const { return keyLocator_; } |
| 59 | |
| 60 | KeyLocator& |
| 61 | getKeyLocator() { return keyLocator_; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 62 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 63 | void |
| 64 | setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; } |
| 65 | |
| 66 | void |
| 67 | setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 68 | { |
| 69 | digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength); |
| 70 | } |
| 71 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 72 | void |
| 73 | setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; } |
| 74 | |
| 75 | void |
| 76 | setWitness(const unsigned char *witness, unsigned int witnessLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 77 | { |
| 78 | witness_ = Blob(witness, witnessLength); |
| 79 | } |
| 80 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 81 | void |
| 82 | setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; } |
| 83 | |
| 84 | void |
| 85 | setSignature(const unsigned char *signature, unsigned int signatureLength) |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 86 | { |
| 87 | signature_ = Blob(signature, signatureLength); |
| 88 | } |
| 89 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 90 | void |
| 91 | setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 92 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 93 | void |
| 94 | setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; } |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Clear all the fields. |
| 98 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 99 | void |
| 100 | clear() |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 101 | { |
| 102 | digestAlgorithm_.reset(); |
| 103 | witness_.reset(); |
| 104 | signature_.reset(); |
| 105 | publisherPublicKeyDigest_.clear(); |
| 106 | keyLocator_.clear(); |
| 107 | } |
| 108 | |
| 109 | private: |
| 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 |