Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 1 | /* -*- 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 | |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 22 | #ifndef NDN_ENCRYPTED_CONTENT_HPP |
| 23 | #define NDN_ENCRYPTED_CONTENT_HPP |
| 24 | |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 25 | #include "tlv.hpp" |
| 26 | #include <list> |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/encoding/tlv.hpp> |
| 28 | #include <ndn-cxx/key-locator.hpp> |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace gep { |
| 32 | |
| 33 | class EncryptedContent |
| 34 | { |
| 35 | public: |
| 36 | class Error : public ndn::tlv::Error |
| 37 | { |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 38 | public: |
| 39 | explicit Error(const std::string& what) |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 40 | : ndn::tlv::Error(what) |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 41 | { |
| 42 | } |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | public: |
| 46 | EncryptedContent(); |
| 47 | |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 48 | 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); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 54 | |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 55 | explicit EncryptedContent(const Block& block); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 56 | |
| 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 Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 69 | return m_hasKeyLocator; |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void |
| 73 | setKeyLocator(const KeyLocator& keyLocator); |
| 74 | |
| 75 | const KeyLocator& |
| 76 | getKeyLocator() const; |
| 77 | |
| 78 | void |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 79 | setInitialVector(const uint8_t* iv, size_t ivLen); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 80 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 81 | const Buffer& |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 82 | getInitialVector() const; |
| 83 | |
| 84 | void |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 85 | setPayload(const uint8_t* payload, size_t payloadLen); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 86 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 87 | const Buffer& |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 88 | 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 | |
| 100 | public: |
| 101 | bool |
| 102 | operator==(const EncryptedContent& rhs) const; |
| 103 | bool |
| 104 | operator!=(const EncryptedContent& rhs) const |
| 105 | { |
| 106 | return !(*this == rhs); |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | int32_t m_type; |
| 111 | bool m_hasKeyLocator; |
| 112 | KeyLocator m_keyLocator; |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 113 | Buffer m_payload; |
| 114 | Buffer m_iv; |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 115 | |
| 116 | mutable Block m_wire; |
| 117 | }; |
| 118 | |
| 119 | } // namespace gep |
| 120 | } // namespace ndn |
| 121 | |
| 122 | #endif // NDN_ENCRYPTED_CONTENT_HPP |