Junxiao Shi | be8d221 | 2014-12-01 23:41:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Junxiao Shi | be8d221 | 2014-12-01 23:41:24 -0700 | [diff] [blame] | 4 | * |
| 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 | |
| 26 | namespace ndn { |
| 27 | |
| 28 | //BOOST_CONCEPT_ASSERT((boost::EqualityComparable<SecuredBag>)); |
| 29 | BOOST_CONCEPT_ASSERT((WireEncodable<SecuredBag>)); |
| 30 | BOOST_CONCEPT_ASSERT((WireDecodable<SecuredBag>)); |
| 31 | static_assert(std::is_base_of<tlv::Error, SecuredBag::Error>::value, |
| 32 | "SecuredBag::Error must inherit from tlv::Error"); |
| 33 | |
| 34 | SecuredBag::SecuredBag() |
| 35 | : m_wire(tlv::security::IdentityPackage) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | SecuredBag::SecuredBag(const Block& wire) |
| 40 | { |
| 41 | this->wireDecode(wire); |
| 42 | } |
| 43 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 44 | SecuredBag::SecuredBag(const v1::IdentityCertificate& cert, ConstBufferPtr key) |
Junxiao Shi | be8d221 | 2014-12-01 23:41:24 -0700 | [diff] [blame] | 45 | : 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 | |
| 55 | SecuredBag::~SecuredBag() |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | SecuredBag::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 | |
| 72 | const Block& |
| 73 | SecuredBag::wireEncode() const |
| 74 | { |
| 75 | m_wire.encode(); |
| 76 | return m_wire; |
| 77 | } |
| 78 | |
| 79 | } // namespace ndn |