blob: 66fad0295a82defda4e6dac520e71e1eb48078f6 [file] [log] [blame]
Junxiao Shibe8d2212014-12-01 23:41:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev2fa59392016-07-29 17:24:23 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Junxiao Shibe8d2212014-12-01 23:41:24 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "secured-bag.hpp"
23#include "encoding/tlv-security.hpp"
24#include "util/concepts.hpp"
25
26namespace ndn {
27
28//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<SecuredBag>));
29BOOST_CONCEPT_ASSERT((WireEncodable<SecuredBag>));
30BOOST_CONCEPT_ASSERT((WireDecodable<SecuredBag>));
31static_assert(std::is_base_of<tlv::Error, SecuredBag::Error>::value,
32 "SecuredBag::Error must inherit from tlv::Error");
33
34SecuredBag::SecuredBag()
35 : m_wire(tlv::security::IdentityPackage)
36{
37}
38
39SecuredBag::SecuredBag(const Block& wire)
40{
41 this->wireDecode(wire);
42}
43
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070044SecuredBag::SecuredBag(const v1::IdentityCertificate& cert, ConstBufferPtr key)
Junxiao Shibe8d2212014-12-01 23:41:24 -070045 : m_cert(cert)
46 , m_key(key)
47 , m_wire(tlv::security::IdentityPackage)
48{
49 Block wireKey(tlv::security::KeyPackage, m_key);
50 Block wireCert(tlv::security::CertificatePackage, cert.wireEncode());
51 m_wire.push_back(wireCert);
52 m_wire.push_back(wireKey);
53}
54
55SecuredBag::~SecuredBag()
56{
57}
58
59void
60SecuredBag::wireDecode(const Block& wire)
61{
62 m_wire = wire;
63 m_wire.parse();
64
65 m_cert.wireDecode(m_wire.get(tlv::security::CertificatePackage).blockFromValue());
66
67 Block wireKey = m_wire.get(tlv::security::KeyPackage);
68 shared_ptr<Buffer> key = make_shared<Buffer>(wireKey.value(), wireKey.value_size());
69 m_key = key;
70}
71
72const Block&
73SecuredBag::wireEncode() const
74{
75 m_wire.encode();
76 return m_wire;
77}
78
79} // namespace ndn