blob: 12555c9c51f908659bdcb76896074868c41a157f [file] [log] [blame]
Zhiyi Zhang3e62a832015-07-20 18:36:31 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016 Regents of the University of California.
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 * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
22 */
23#ifndef NDN_CXX_SECURITY_SAFE_BAG_HPP
24#define NDN_CXX_SECURITY_SAFE_BAG_HPP
25
26#include "../common.hpp"
27#include "../data.hpp"
28#include "../encoding/buffer.hpp"
29#include "../encoding/encoder.hpp"
30#include "../encoding/encoding-buffer.hpp"
31#include "security-common.hpp"
32
33namespace ndn {
34namespace security {
35
36/** @brief a secured container for sensitive information(certificate, private key)
37 */
38class SafeBag
39{
40public:
41 /**
42 * @brief Create a new empty SafeBag object
43 */
44 SafeBag();
45
46 /**
47 * @brief Create a new SafeBag object from the block
48 */
49 explicit
50 SafeBag(const Block& wire);
51
52 /**
53 * @brief Create a new Safe object with the given certificate and private key
54 *
55 * @param certificate A reference to the certificate data packet
56 * @param encryptedKeyBag A reference to the Buffer of private key in PKCS#8
57 */
58 SafeBag(const Data& certificate,
59 const Buffer& encryptedKeyBag);
60
61 /**
62 * @brief Create a new Safe object with the given certificate and private key
63 *
64 * @param certificate A reference to the certificate data packet
65 * @param encryptedKey A reference to the uint8_t* of private key in PKCS#8
66 * @param encryptedKeyLen The length of the encryptedKey
67 */
68 SafeBag(const Data& certificate,
69 const uint8_t* encryptedKey,
70 size_t encryptedKeyLen);
71
72public:
73 /**
74 * @brief Fast encoding or block size estimation
75 */
76 template<encoding::Tag TAG>
77 size_t
78 wireEncode(EncodingImpl<TAG>& encoder) const;
79
80 /**
81 * @brief Encode to a wire format
82 */
83 const Block&
84 wireEncode() const;
85
86 /**
87 * @brief Decode the input from wire format
88 */
89 void
90 wireDecode(const Block& wire);
91
92public:
93 /**
94 * @brief Get the certificate data packet from safe bag
95 */
96 const Data&
97 getCertificate() const
98 {
99 return m_certificate;
100 }
101
102 /**
103 * @brief Get the private key in PKCS#8 from safe bag
104 */
105 const Buffer&
106 getEncryptedKeyBag() const
107 {
108 return m_encryptedKeyBag;
109 }
110
111private:
112 Data m_certificate;
113 Buffer m_encryptedKeyBag;
114
115 mutable Block m_wire;
116};
117
118} // namespace security
119} // namespace ndn
120
121#endif // NDN_CXX_SECURITY_SAFE_BAG_HPP