blob: 53bad96f1a5225e74e709d3f9beac95475d0f53d [file] [log] [blame]
Zhiyi Zhang19a11d22018-04-12 22:58:20 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9091d832018-04-18 17:21:08 -04003 * Copyright (c) 2014-2018, Regents of the University of California
Zhiyi Zhang19a11d22018-04-12 22:58:20 -07004 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04005 * 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 Zhang19a11d22018-04-12 22:58:20 -07007 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04008 * NAC is free software: you can redistribute it and/or modify it under the terms
Zhiyi Zhang19a11d22018-04-12 22:58:20 -07009 * 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 Afanasyev9091d832018-04-18 17:21:08 -040012 * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070013 * 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 Afanasyev9091d832018-04-18 17:21:08 -040017 * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070018 *
19 * @author Yingdi Yu <yingdi@cs.ucla.edu>
20 */
21
Alexander Afanasyev9091d832018-04-18 17:21:08 -040022#ifndef NDN_NAC_ENCRYPTED_CONTENT_HPP
23#define NDN_NAC_ENCRYPTED_CONTENT_HPP
Prashanthc0029b62015-04-27 14:00:08 -070024
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 {
Alexander Afanasyev9091d832018-04-18 17:21:08 -040031namespace nac {
Prashanthc0029b62015-04-27 14:00:08 -070032
33class EncryptedContent
34{
35public:
36 class Error : public ndn::tlv::Error
37 {
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070038 public:
Alexander Afanasyev9091d832018-04-18 17:21:08 -040039 using ndn::tlv::Error::Error;
Prashanthc0029b62015-04-27 14:00:08 -070040 };
41
42public:
43 EncryptedContent();
44
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070045 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);
Prashanthc0029b62015-04-27 14:00:08 -070051
Alexander Afanasyev9091d832018-04-18 17:21:08 -040052 explicit
53 EncryptedContent(const Block& block);
Prashanthc0029b62015-04-27 14:00:08 -070054
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 Zhang19a11d22018-04-12 22:58:20 -070067 return m_hasKeyLocator;
Prashanthc0029b62015-04-27 14:00:08 -070068 }
69
70 void
71 setKeyLocator(const KeyLocator& keyLocator);
72
73 const KeyLocator&
74 getKeyLocator() const;
75
76 void
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -070077 setInitialVector(const uint8_t* iv, size_t ivLen);
Prashanthc0029b62015-04-27 14:00:08 -070078
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -070079 const Buffer&
Prashanth Swaminathanb1b95962015-07-06 13:13:08 -070080 getInitialVector() const;
81
82 void
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -070083 setPayload(const uint8_t* payload, size_t payloadLen);
Prashanth Swaminathanb1b95962015-07-06 13:13:08 -070084
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -070085 const Buffer&
Prashanthc0029b62015-04-27 14:00:08 -070086 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
98public:
99 bool
100 operator==(const EncryptedContent& rhs) const;
Alexander Afanasyev9091d832018-04-18 17:21:08 -0400101
Prashanthc0029b62015-04-27 14:00:08 -0700102 bool
103 operator!=(const EncryptedContent& rhs) const
104 {
105 return !(*this == rhs);
106 }
107
108private:
109 int32_t m_type;
110 bool m_hasKeyLocator;
111 KeyLocator m_keyLocator;
Prashanth Swaminathand5b3eae2015-07-09 15:37:05 -0700112 Buffer m_payload;
113 Buffer m_iv;
Prashanthc0029b62015-04-27 14:00:08 -0700114
115 mutable Block m_wire;
116};
117
Alexander Afanasyev9091d832018-04-18 17:21:08 -0400118} // namespace nac
Prashanthc0029b62015-04-27 14:00:08 -0700119} // namespace ndn
120
Alexander Afanasyev9091d832018-04-18 17:21:08 -0400121#endif // NDN_NAC_ENCRYPTED_CONTENT_HPP