blob: 8a96fc7e379e046dea0516fb4610a9d9aa250400 [file] [log] [blame]
Zhiyi Zhang19a11d22018-04-12 22:58:20 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2018, Regents of the University of California
4 *
5 * This file is part of gep (Group-based Encryption Protocol for NDN).
6 * See AUTHORS.md for complete list of gep authors and contributors.
7 *
8 * gep is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * gep is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Yingdi Yu <yingdi@cs.ucla.edu>
20 */
21
Prashanthc0029b62015-04-27 14:00:08 -070022#ifndef NDN_ENCRYPTED_CONTENT_HPP
23#define NDN_ENCRYPTED_CONTENT_HPP
24
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070025#include "tlv.hpp"
26#include <list>
Prashanthc0029b62015-04-27 14:00:08 -070027#include <ndn-cxx/encoding/tlv.hpp>
28#include <ndn-cxx/key-locator.hpp>
Prashanthc0029b62015-04-27 14:00:08 -070029
30namespace ndn {
31namespace gep {
32
33class EncryptedContent
34{
35public:
36 class Error : public ndn::tlv::Error
37 {
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070038 public:
39 explicit Error(const std::string& what)
Prashanthc0029b62015-04-27 14:00:08 -070040 : ndn::tlv::Error(what)
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070041 {
42 }
Prashanthc0029b62015-04-27 14:00:08 -070043 };
44
45public:
46 EncryptedContent();
47
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070048 EncryptedContent(tlv::AlgorithmTypeValue type,
49 const KeyLocator& keyLocator,
50 const uint8_t* payload,
51 size_t payloadLen,
52 const uint8_t* iv = 0,
53 size_t ivLen = 0);
Prashanthc0029b62015-04-27 14:00:08 -070054
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070055 explicit EncryptedContent(const Block& block);
Prashanthc0029b62015-04-27 14:00:08 -070056
57 void
58 setAlgorithmType(tlv::AlgorithmTypeValue type);
59
60 int32_t
61 getAlgorithmType() const
62 {
63 return m_type;
64 }
65
66 bool
67 hasKeyLocator() const
68 {
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070069 return m_hasKeyLocator;
Prashanthc0029b62015-04-27 14:00:08 -070070 }
71
72 void
73 setKeyLocator(const KeyLocator& keyLocator);
74
75 const KeyLocator&
76 getKeyLocator() const;
77
78 void
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -070079 setInitialVector(const uint8_t* iv, size_t ivLen);
Prashanthc0029b62015-04-27 14:00:08 -070080
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -070081 const Buffer&
Prashanth Swaminathanb1b95962015-07-06 13:13:08 -070082 getInitialVector() const;
83
84 void
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -070085 setPayload(const uint8_t* payload, size_t payloadLen);
Prashanth Swaminathanb1b95962015-07-06 13:13:08 -070086
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -070087 const Buffer&
Prashanthc0029b62015-04-27 14:00:08 -070088 getPayload() const;
89
90 template<encoding::Tag TAG>
91 size_t
92 wireEncode(EncodingImpl<TAG>& block) const;
93
94 const Block&
95 wireEncode() const;
96
97 void
98 wireDecode(const Block& wire);
99
100public:
101 bool
102 operator==(const EncryptedContent& rhs) const;
103 bool
104 operator!=(const EncryptedContent& rhs) const
105 {
106 return !(*this == rhs);
107 }
108
109private:
110 int32_t m_type;
111 bool m_hasKeyLocator;
112 KeyLocator m_keyLocator;
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -0700113 Buffer m_payload;
114 Buffer m_iv;
Prashanthc0029b62015-04-27 14:00:08 -0700115
116 mutable Block m_wire;
117};
118
119} // namespace gep
120} // namespace ndn
121
122#endif // NDN_ENCRYPTED_CONTENT_HPP