blob: c6d914c15b11ba4622a226ed1f2efc5b6a35550a [file] [log] [blame]
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_SIGNATURE_HPP
9#define NDN_SIGNATURE_HPP
10
11namespace ndn {
12
13/**
14 * A Signature is storage for the signature-related information (info and value) in a Data packet.
15 */
16class Signature {
17public:
18 enum {
19 DigestSha256 = 0,
20 SignatureSha256WithRsa = 1
21 };
22
23 Signature()
24 : type_(-1)
25 {
26 }
27
28 Signature(const Block &info, const Block &value)
29 : info_(info)
30 , value_(value)
31 {
32 Buffer::const_iterator i = info_.value_begin();
33 Tlv::readVarNumber(i, info_.value_end());
34 size_t length = Tlv::readVarNumber(i, info_.value_end());
35 type_ = Tlv::readNonNegativeInteger(length, i, info_.value_end());
36 }
37
38 operator bool() const
39 {
40 return type_ != -1;
41 }
42
43 uint32_t
44 getType() const
45 {
46 return type_;
47 }
48
49 const Block&
50 getInfo() const
51 {
52 return info_;
53 }
54
55 void
56 setInfo(const Block &info)
57 {
58 info_ = info;
59 if (info_.hasWire() || info_.hasValue())
60 {
61 info_.parse();
62 const Block &signatureType = info_.get(Tlv::SignatureType);
63
64 Buffer::const_iterator i = signatureType.value_begin();
65 type_ = Tlv::readVarNumber(i, signatureType.value_end());
66 }
67 else
68 {
69 type_ = -1;
70 }
71 }
72
73 const Block&
74 getValue() const
75 {
76 return value_;
77 }
78
79 void
80 setValue(const Block &value)
81 {
82 value_ = value;
83 }
84
85 void
86 reset()
87 {
88 type_ = -1;
89 info_ = Block();
90 value_ = Block();
91 }
92
93private:
94 int32_t type_;
95
96 Block info_;
97 Block value_;
98};
99
100} // namespace ndn
101
102#endif // NDN_SIGNATURE_HPP