blob: 82e4b667cade7a88f1c4697fcfc4e31f8378f736 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson20af0732013-09-12 17:01:45 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson20af0732013-09-12 17:01:45 -07005 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_SHA256_WITH_RSA_SIGNATURE_HPP
Jeff Thompsone589c3f2013-10-12 17:30:50 -07009#define NDN_SHA256_WITH_RSA_SIGNATURE_HPP
Jeff Thompson20af0732013-09-12 17:01:45 -070010
11#include "data.hpp"
Jeff Thompsonbad29b32013-09-17 14:23:41 -070012#include "key.hpp"
Jeff Thompson20af0732013-09-12 17:01:45 -070013#include "publisher-public-key-digest.hpp"
14
15namespace 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 */
21class Sha256WithRsaSignature : public Signature {
22public:
23 /**
24 * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature.
25 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070026 virtual ptr_lib::shared_ptr<Signature>
27 clone() const;
Jeff Thompson20af0732013-09-12 17:01:45 -070028
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 Thompson0050abe2013-09-17 12:50:25 -070034 virtual void
35 get(struct ndn_Signature& signatureStruct) const;
Jeff Thompson20af0732013-09-12 17:01:45 -070036
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 Thompson0050abe2013-09-17 12:50:25 -070041 virtual void
42 set(const struct ndn_Signature& signatureStruct);
Jeff Thompson20af0732013-09-12 17:01:45 -070043
Jeff Thompson0050abe2013-09-17 12:50:25 -070044 const Blob&
45 getDigestAlgorithm() const { return digestAlgorithm_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070046
Jeff Thompson0050abe2013-09-17 12:50:25 -070047 const Blob&
48 getWitness() const { return witness_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070049
Jeff Thompson0050abe2013-09-17 12:50:25 -070050 const Blob&
51 getSignature() const { return signature_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070052
Jeff Thompson0050abe2013-09-17 12:50:25 -070053 const PublisherPublicKeyDigest&
54 getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070055
Jeff Thompson0050abe2013-09-17 12:50:25 -070056 PublisherPublicKeyDigest&
57 getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
58
59 const KeyLocator&
60 getKeyLocator() const { return keyLocator_; }
61
62 KeyLocator&
63 getKeyLocator() { return keyLocator_; }
Jeff Thompson20af0732013-09-12 17:01:45 -070064
Jeff Thompson0050abe2013-09-17 12:50:25 -070065 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070066 setDigestAlgorithm(const std::vector<uint8_t>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
Jeff Thompson0050abe2013-09-17 12:50:25 -070067
68 void
Jeff Thompson97223af2013-09-24 17:01:27 -070069 setDigestAlgorithm(const uint8_t *digestAlgorithm, size_t digestAlgorithmLength)
Jeff Thompson20af0732013-09-12 17:01:45 -070070 {
71 digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
72 }
73
Jeff Thompson0050abe2013-09-17 12:50:25 -070074 void
Jeff Thompsonda530ea2013-10-14 13:59:20 -070075 setDigestAlgorithm(const Blob& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
76
77 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070078 setWitness(const std::vector<uint8_t>& witness) { witness_ = witness; }
Jeff Thompson0050abe2013-09-17 12:50:25 -070079
80 void
Jeff Thompsonda530ea2013-10-14 13:59:20 -070081 setWitness(const uint8_t *witness, size_t witnessLength) { witness_ = Blob(witness, witnessLength); }
82
83 void
84 setWitness(const Blob& witness) { witness_ = witness; }
Jeff Thompson20af0732013-09-12 17:01:45 -070085
Jeff Thompson0050abe2013-09-17 12:50:25 -070086 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070087 setSignature(const std::vector<uint8_t>& signature) { signature_ = signature; }
Jeff Thompson0050abe2013-09-17 12:50:25 -070088
89 void
Jeff Thompsonda530ea2013-10-14 13:59:20 -070090 setSignature(const uint8_t *signature, size_t signatureLength) { signature_ = Blob(signature, signatureLength); }
Jeff Thompsonbad29b32013-09-17 14:23:41 -070091
92 void
Jeff Thompsonda530ea2013-10-14 13:59:20 -070093 setSignature(const Blob& signature) { signature_ = signature; }
Jeff Thompsonbad29b32013-09-17 14:23:41 -070094
Jeff Thompson0050abe2013-09-17 12:50:25 -070095 void
96 setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
Jeff Thompson20af0732013-09-12 17:01:45 -070097
Jeff Thompson0050abe2013-09-17 12:50:25 -070098 void
99 setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
Jeff Thompson20af0732013-09-12 17:01:45 -0700100
101 /**
102 * Clear all the fields.
103 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700104 void
105 clear()
Jeff Thompson20af0732013-09-12 17:01:45 -0700106 {
107 digestAlgorithm_.reset();
108 witness_.reset();
109 signature_.reset();
110 publisherPublicKeyDigest_.clear();
111 keyLocator_.clear();
112 }
113
114private:
115 Blob digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
116 Blob witness_;
117 Blob signature_;
118 PublisherPublicKeyDigest publisherPublicKeyDigest_;
119 KeyLocator keyLocator_;
120};
121
122}
123
124#endif