blob: 8fccbc6ae22b017178b331a455862d16a04dfb4d [file] [log] [blame]
Junxiao Shibe8d2212014-12-01 23:41:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 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"
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080023#include "../../encoding/tlv-security.hpp"
24#include "../../util/concepts.hpp"
Junxiao Shibe8d2212014-12-01 23:41:24 -070025
26namespace ndn {
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080027namespace security {
28namespace v1 {
Junxiao Shibe8d2212014-12-01 23:41:24 -070029
30//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<SecuredBag>));
31BOOST_CONCEPT_ASSERT((WireEncodable<SecuredBag>));
32BOOST_CONCEPT_ASSERT((WireDecodable<SecuredBag>));
33static_assert(std::is_base_of<tlv::Error, SecuredBag::Error>::value,
34 "SecuredBag::Error must inherit from tlv::Error");
35
36SecuredBag::SecuredBag()
37 : m_wire(tlv::security::IdentityPackage)
38{
39}
40
41SecuredBag::SecuredBag(const Block& wire)
42{
43 this->wireDecode(wire);
44}
45
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080046SecuredBag::SecuredBag(const IdentityCertificate& cert, ConstBufferPtr key)
Junxiao Shibe8d2212014-12-01 23:41:24 -070047 : m_cert(cert)
48 , m_key(key)
49 , m_wire(tlv::security::IdentityPackage)
50{
51 Block wireKey(tlv::security::KeyPackage, m_key);
52 Block wireCert(tlv::security::CertificatePackage, cert.wireEncode());
53 m_wire.push_back(wireCert);
54 m_wire.push_back(wireKey);
55}
56
57SecuredBag::~SecuredBag()
58{
59}
60
61void
62SecuredBag::wireDecode(const Block& wire)
63{
64 m_wire = wire;
65 m_wire.parse();
66
67 m_cert.wireDecode(m_wire.get(tlv::security::CertificatePackage).blockFromValue());
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
74const Block&
75SecuredBag::wireEncode() const
76{
77 m_wire.encode();
78 return m_wire;
79}
80
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080081} // namespace v1
82} // namespace security
Junxiao Shibe8d2212014-12-01 23:41:24 -070083} // namespace ndn