blob: d1110587449a7f0f158a41c57598b4879772f712 [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"
11#include "publisher-public-key-digest.hpp"
12
13namespace 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 */
19class Sha256WithRsaSignature : public Signature {
20public:
21 /**
22 * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature.
23 */
24 virtual ptr_lib::shared_ptr<Signature> clone() const;
25
26 /**
27 * Set the signatureStruct to point to the values in this signature object, without copying any memory.
28 * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory.
29 * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
30 */
31 virtual void get(struct ndn_Signature& signatureStruct) const;
32
33 /**
34 * Clear this signature, and set the values by copying from the ndn_Signature struct.
35 * @param signatureStruct a C ndn_Signature struct
36 */
37 virtual void set(const struct ndn_Signature& signatureStruct);
38
39 const Blob& getDigestAlgorithm() const { return digestAlgorithm_; }
40
41 const Blob& getWitness() const { return witness_; }
42
43 const Blob& getSignature() const { return signature_; }
44
45 const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
46 PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
47
48 const KeyLocator& getKeyLocator() const { return keyLocator_; }
49 KeyLocator& getKeyLocator() { return keyLocator_; }
50
51 void setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
52 void setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength)
53 {
54 digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
55 }
56
57 void setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; }
58 void setWitness(const unsigned char *witness, unsigned int witnessLength)
59 {
60 witness_ = Blob(witness, witnessLength);
61 }
62
63 void setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; }
64 void setSignature(const unsigned char *signature, unsigned int signatureLength)
65 {
66 signature_ = Blob(signature, signatureLength);
67 }
68
69 void setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
70
71 void setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
72
73 /**
74 * Clear all the fields.
75 */
76 void clear()
77 {
78 digestAlgorithm_.reset();
79 witness_.reset();
80 signature_.reset();
81 publisherPublicKeyDigest_.clear();
82 keyLocator_.clear();
83 }
84
85private:
86 Blob digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
87 Blob witness_;
88 Blob signature_;
89 PublisherPublicKeyDigest publisherPublicKeyDigest_;
90 KeyLocator keyLocator_;
91};
92
93}
94
95#endif