secured-bag.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "secured-bag.hpp"
23 #include "../../encoding/tlv-security.hpp"
24 #include "../../util/concepts.hpp"
25 
26 namespace ndn {
27 namespace security {
28 namespace v1 {
29 
30 //BOOST_CONCEPT_ASSERT((boost::EqualityComparable<SecuredBag>));
31 BOOST_CONCEPT_ASSERT((WireEncodable<SecuredBag>));
32 BOOST_CONCEPT_ASSERT((WireDecodable<SecuredBag>));
33 static_assert(std::is_base_of<tlv::Error, SecuredBag::Error>::value,
34  "SecuredBag::Error must inherit from tlv::Error");
35 
37  : m_wire(tlv::security::IdentityPackage)
38 {
39 }
40 
42 {
43  this->wireDecode(wire);
44 }
45 
47  : m_cert(cert)
48  , m_key(key)
49  , m_wire(tlv::security::IdentityPackage)
50 {
51  Block wireKey(tlv::security::KeyPackage, m_key);
53  m_wire.push_back(wireCert);
54  m_wire.push_back(wireKey);
55 }
56 
58 {
59 }
60 
61 void
63 {
64  m_wire = wire;
65  m_wire.parse();
66 
68 
69  Block wireKey = m_wire.get(tlv::security::KeyPackage);
70  shared_ptr<Buffer> key = make_shared<Buffer>(wireKey.value(), wireKey.value_size());
71  m_key = key;
72 }
73 
74 const Block&
76 {
77  m_wire.encode();
78  return m_wire;
79 }
80 
81 } // namespace v1
82 } // namespace security
83 } // namespace ndn
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:75
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
BOOST_CONCEPT_ASSERT((WireEncodable< Certificate >))
void wireDecode(const Block &wire)
Definition: secured-bag.cpp:62
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Fast encoding or block size estimation.
Definition: data.cpp:48
Block blockFromValue() const
Definition: block.cpp:328
const Block & get(uint32_t type) const
Get the first sub element of specified TLV-TYPE.
Definition: block.cpp:421
void push_back(const Block &element)
Append a sub element.
Definition: block.cpp:480
size_t value_size() const
Get size of TLV-VALUE aka TLV-LENGTH.
Definition: block.cpp:322
void parse() const
Parse TLV-VALUE into sub elements.
Definition: block.cpp:339
void encode()
Encode sub elements into TLV-VALUE.
Definition: block.cpp:367
const uint8_t * value() const
Get pointer to TLV-VALUE.
Definition: block.cpp:316
const Block & wireEncode() const
Definition: secured-bag.cpp:75
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33