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-2016 Regents of the University of California.
Definition: common.hpp:74
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
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:52
Block blockFromValue() const
Definition: block.cpp:437
const Block & get(uint32_t type) const
Get the first subelement of the requested type.
Definition: block.cpp:409
void push_back(const Block &element)
Definition: block.cpp:568
size_t value_size() const
Definition: block.cpp:529
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:322
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:355
const uint8_t * value() const
Definition: block.cpp:520
const Block & wireEncode() const
Definition: secured-bag.cpp:75
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:40
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Definition: concepts.hpp:76