encrypted-content.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, Regents of the University of California
4  *
5  * NAC library is free software: you can redistribute it and/or modify it under the
6  * terms of the GNU Lesser General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later version.
8  *
9  * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12  *
13  * You should have received copies of the GNU General Public License and GNU Lesser
14  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * See AUTHORS.md for complete list of NAC library authors and contributors.
18  */
19 
20 #ifndef NDN_NAC_ENCRYPTED_CONTENT_HPP
21 #define NDN_NAC_ENCRYPTED_CONTENT_HPP
22 
23 #include "common.hpp"
24 
25 #include <ndn-cxx/encoding/tlv.hpp>
26 
27 namespace ndn::nac {
28 
45 {
46 public:
47  class Error : public ndn::tlv::Error
48  {
49  public:
50  using ndn::tlv::Error::Error;
51  };
52 
53 public:
54  EncryptedContent() = default;
55 
56  explicit
57  EncryptedContent(const Block& block);
58 
59  const Block&
60  getPayload() const
61  {
62  return m_payload;
63  }
64 
66  setPayload(Block payload);
67 
69  setPayload(ConstBufferPtr payload);
70 
71  bool
72  hasIv() const noexcept
73  {
74  return m_iv.isValid();
75  }
76 
77  const Block&
78  getIv() const
79  {
80  return m_iv;
81  }
82 
84  unsetIv();
85 
87  setIv(Block iv);
88 
90  setIv(ConstBufferPtr iv);
91 
92  bool
93  hasPayloadKey() const noexcept
94  {
95  return m_payloadKey.isValid();
96  }
97 
98  const Block&
99  getPayloadKey() const
100  {
101  return m_payloadKey;
102  }
103 
105  setPayloadKey(Block key);
106 
108  setPayloadKey(ConstBufferPtr key);
109 
111  unsetPayloadKey();
112 
113  bool
115  {
116  return !m_keyLocator.empty();
117  }
118 
119  const Name&
121  {
122  return m_keyLocator;
123  }
124 
126  setKeyLocator(Name keyLocator);
127 
129  unsetKeyLocator();
130 
131  template<encoding::Tag TAG>
132  size_t
133  wireEncode(EncodingImpl<TAG>& block) const;
134 
135  const Block&
136  wireEncode() const;
137 
138  void
139  wireDecode(const Block& wire);
140 
141 private:
142  Block m_iv;
143  Block m_payload;
144  Block m_payloadKey;
146  Name m_keyLocator;
147 
148  mutable Block m_wire;
149 };
150 
151 } // namespace ndn::nac
152 
153 #endif // NDN_NAC_ENCRYPTED_CONTENT_HPP
EncryptedContent & setPayloadKey(Block key)
EncryptedContent & unsetPayloadKey()
const Name & getKeyLocator() const
const Block & getPayload() const
EncryptedContent & unsetKeyLocator()
EncryptedContent & setPayload(Block payload)
const Block & getIv() const
bool hasIv() const noexcept
EncryptedContent & setIv(Block iv)
EncryptedContent & setKeyLocator(Name keyLocator)
const Block & getPayloadKey() const
const Block & wireEncode() const
EncryptedContent & unsetIv()
void wireDecode(const Block &wire)
bool hasPayloadKey() const noexcept