Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2018, Regents of the University of California |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 5 | * This file is part of NAC (Name-Based Access Control for NDN). |
| 6 | * See AUTHORS.md for complete list of NAC authors and contributors. |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 8 | * NAC is free software: you can redistribute it and/or modify it under the terms |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 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 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 12 | * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 17 | * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 18 | * |
| 19 | * @author Yingdi Yu <yingdi@cs.ucla.edu> |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 22 | #ifndef NDN_NAC_ENCRYPTED_CONTENT_HPP |
| 23 | #define NDN_NAC_ENCRYPTED_CONTENT_HPP |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 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 { |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 31 | namespace nac { |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 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: |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 39 | using ndn::tlv::Error::Error; |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | public: |
| 43 | EncryptedContent(); |
| 44 | |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 45 | EncryptedContent(tlv::AlgorithmTypeValue type, |
| 46 | const KeyLocator& keyLocator, |
| 47 | const uint8_t* payload, |
| 48 | size_t payloadLen, |
| 49 | const uint8_t* iv = 0, |
| 50 | size_t ivLen = 0); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 52 | explicit |
| 53 | EncryptedContent(const Block& block); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 54 | |
| 55 | void |
| 56 | setAlgorithmType(tlv::AlgorithmTypeValue type); |
| 57 | |
| 58 | int32_t |
| 59 | getAlgorithmType() const |
| 60 | { |
| 61 | return m_type; |
| 62 | } |
| 63 | |
| 64 | bool |
| 65 | hasKeyLocator() const |
| 66 | { |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 67 | return m_hasKeyLocator; |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void |
| 71 | setKeyLocator(const KeyLocator& keyLocator); |
| 72 | |
| 73 | const KeyLocator& |
| 74 | getKeyLocator() const; |
| 75 | |
| 76 | void |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 77 | setInitialVector(const uint8_t* iv, size_t ivLen); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 78 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 79 | const Buffer& |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 80 | getInitialVector() const; |
| 81 | |
| 82 | void |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 83 | setPayload(const uint8_t* payload, size_t payloadLen); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 84 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 85 | const Buffer& |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 86 | getPayload() const; |
| 87 | |
| 88 | template<encoding::Tag TAG> |
| 89 | size_t |
| 90 | wireEncode(EncodingImpl<TAG>& block) const; |
| 91 | |
| 92 | const Block& |
| 93 | wireEncode() const; |
| 94 | |
| 95 | void |
| 96 | wireDecode(const Block& wire); |
| 97 | |
| 98 | public: |
| 99 | bool |
| 100 | operator==(const EncryptedContent& rhs) const; |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 101 | |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 102 | bool |
| 103 | operator!=(const EncryptedContent& rhs) const |
| 104 | { |
| 105 | return !(*this == rhs); |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | int32_t m_type; |
| 110 | bool m_hasKeyLocator; |
| 111 | KeyLocator m_keyLocator; |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 112 | Buffer m_payload; |
| 113 | Buffer m_iv; |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 114 | |
| 115 | mutable Block m_wire; |
| 116 | }; |
| 117 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 118 | } // namespace nac |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 119 | } // namespace ndn |
| 120 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 121 | #endif // NDN_NAC_ENCRYPTED_CONTENT_HPP |