All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
secured-bag.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
7 #ifndef NDN_SECURITY_SECURED_BAG_HPP
8 #define NDN_SECURITY_SECURED_BAG_HPP
9 
10 #include "../common.hpp"
11 #include "identity-certificate.hpp"
12 #include "../encoding/tlv-security.hpp"
13 
14 namespace ndn {
15 
17 {
18 public:
19  class Error : public std::runtime_error
20  {
21  public:
22  explicit
23  Error(const std::string& what)
24  : std::runtime_error(what)
25  {
26  }
27  };
28 
30  : m_wire(tlv::security::IdentityPackage)
31  {
32  }
33 
35  ConstBufferPtr key)
36  : m_cert(cert)
37  , m_key(key)
38  , m_wire(tlv::security::IdentityPackage)
39  {
40  Block wireKey(tlv::security::KeyPackage, m_key);
42  m_wire.push_back(wireCert);
43  m_wire.push_back(wireKey);
44  }
45 
46  virtual
48  {
49  }
50 
51  void
52  wireDecode(const Block& wire)
53  {
54  m_wire = wire;
55  m_wire.parse();
56 
58 
59  Block wireKey = m_wire.get(tlv::security::KeyPackage);
60  shared_ptr<Buffer> key = make_shared<Buffer>(wireKey.value(), wireKey.value_size());
61  m_key = key;
62  }
63 
64  inline const Block&
65  wireEncode() const
66  {
67  m_wire.encode();
68  return m_wire;
69  }
70 
71  const IdentityCertificate&
73  {
74  return m_cert;
75  }
76 
78  getKey() const
79  {
80  return m_key;
81  }
82 
83 private:
84  IdentityCertificate m_cert;
85  ConstBufferPtr m_key;
86 
87  mutable Block m_wire;
88 };
89 
90 } // namespace ndn
91 
92 #endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP
virtual ~SecuredBag()
Definition: secured-bag.hpp:47
void wireDecode(const Block &wire)
Definition: secured-bag.hpp:52
ConstBufferPtr getKey() const
Definition: secured-bag.hpp:78
Class representing wire element of the NDN packet.
Definition: block.hpp:26
void wireDecode(const Block &wire)
size_t wireEncode(EncodingImpl< T > &block, bool unsignedPortion=false) const
Fast encoding or block size estimation.
Definition: data.hpp:242
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:17
Block blockFromValue() const
Definition: block.cpp:352
Error(const std::string &what)
Definition: secured-bag.hpp:23
const Block & get(uint32_t type) const
Get the first subelement of the requested type.
Definition: block.hpp:326
void push_back(const Block &element)
Definition: block.hpp:390
size_t value_size() const
Definition: block.hpp:455
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:265
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:298
const IdentityCertificate & getCertificate() const
Definition: secured-bag.hpp:72
SecuredBag(const IdentityCertificate &cert, ConstBufferPtr key)
Definition: secured-bag.hpp:34
const uint8_t * value() const
Definition: block.hpp:446
const Block & wireEncode() const
Definition: secured-bag.hpp:65