22 #include <ndn-cxx/encoding/block-helpers.hpp>
23 #include <ndn-cxx/util/concepts.hpp>
24 #include <ndn-cxx/util/exception.hpp>
28 BOOST_CONCEPT_ASSERT((WireEncodable<EncryptedContent>));
29 BOOST_CONCEPT_ASSERT((WireDecodable<EncryptedContent>));
30 static_assert(std::is_base_of_v<ndn::tlv::Error, EncryptedContent::Error>,
31 "EncryptedContent::Error must inherit from tlv::Error");
46 m_payload = std::move(payload);
96 m_payloadKey = std::move(key);
121 m_keyLocator = std::move(keyLocator);
133 template<encoding::Tag TAG>
137 size_t totalLength = 0;
140 totalLength += m_keyLocator.wireEncode(encoder);
144 totalLength += prependBlock(encoder, m_payloadKey);
148 totalLength += prependBlock(encoder, m_iv);
151 if (m_payload.isValid()) {
152 totalLength += prependBlock(encoder, m_payload);
155 NDN_THROW(
Error(
"Required EncryptedPayload is not set on EncryptedContent"));
158 totalLength += encoder.prependVarNumber(totalLength);
166 if (m_wire.hasWire())
169 EncodingEstimator estimator;
172 EncodingBuffer buffer(estimatedSize, 0);
175 m_wire = buffer.block();
182 if (!wire.hasWire()) {
183 NDN_THROW(
Error(
"The supplied block does not contain wire format"));
186 NDN_THROW(
Error(
"EncryptedContent", wire.type()));
194 if (block != m_wire.elements_end()) {
198 NDN_THROW(
Error(
"Required EncryptedPayload not found in EncryptedContent"));
202 if (block != m_wire.elements_end()) {
207 if (block != m_wire.elements_end()) {
208 m_payloadKey = *block;
211 block = m_wire.find(tlv::Name);
212 if (block != m_wire.elements_end()) {
213 m_keyLocator.wireDecode(*block);
EncryptedContent & setPayloadKey(Block key)
EncryptedContent & unsetPayloadKey()
EncryptedContent & unsetKeyLocator()
EncryptedContent & setPayload(Block payload)
bool hasIv() const noexcept
EncryptedContent & setIv(Block iv)
EncryptedContent()=default
EncryptedContent & setKeyLocator(Name keyLocator)
bool hasKeyLocator() const
const Block & wireEncode() const
EncryptedContent & unsetIv()
void wireDecode(const Block &wire)
bool hasPayloadKey() const noexcept