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 | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 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" |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 23 | #include "../../encoding/tlv-security.hpp" |
| 24 | #include "../../util/concepts.hpp" |
Junxiao Shi | be8d221 | 2014-12-01 23:41:24 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 27 | namespace security { |
| 28 | namespace v1 { |
Junxiao Shi | be8d221 | 2014-12-01 23:41:24 -0700 | [diff] [blame] | 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 | |
| 36 | SecuredBag::SecuredBag() |
| 37 | : m_wire(tlv::security::IdentityPackage) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | SecuredBag::SecuredBag(const Block& wire) |
| 42 | { |
| 43 | this->wireDecode(wire); |
| 44 | } |
| 45 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 46 | SecuredBag::SecuredBag(const IdentityCertificate& cert, ConstBufferPtr key) |
Junxiao Shi | be8d221 | 2014-12-01 23:41:24 -0700 | [diff] [blame] | 47 | : 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 | |
| 57 | SecuredBag::~SecuredBag() |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | SecuredBag::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 | |
| 74 | const Block& |
| 75 | SecuredBag::wireEncode() const |
| 76 | { |
| 77 | m_wire.encode(); |
| 78 | return m_wire; |
| 79 | } |
| 80 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 81 | } // namespace v1 |
| 82 | } // namespace security |
Junxiao Shi | be8d221 | 2014-12-01 23:41:24 -0700 | [diff] [blame] | 83 | } // namespace ndn |