encryptor.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_ENCRYPTOR_HPP
21 #define NDN_NAC_ENCRYPTOR_HPP
22 
23 #include "common.hpp"
24 #include "encrypted-content.hpp"
25 
26 namespace ndn::nac {
27 
33 class Encryptor
34 {
35 public:
50  Encryptor(const Name& accessPrefix,
51  const Name& ckPrefix, SigningInfo ckDataSigningInfo,
52  const ErrorCallback& onFailure,
53  Validator& validator, KeyChain& keyChain, Face& face);
54 
55  ~Encryptor();
56 
74  encrypt(span<const uint8_t> data);
75 
82  void
83  regenerateCk();
84 
85 public: // accessor interface for published data packets
89  size_t
90  size() const
91  {
92  return m_ims.size();
93  }
94 
100  InMemoryStorage::const_iterator
101  begin() const
102  {
103  return m_ims.begin();
104  }
105 
111  InMemoryStorage::const_iterator
112  end() const
113  {
114  return m_ims.end();
115  }
116 
117 private:
118  void
119  retryFetchingKek();
120 
121  void
122  fetchKekAndPublishCkData(const std::function<void()>& onReady,
123  const ErrorCallback& onFailure,
124  size_t nTriesLeft);
125 
126  bool
127  makeAndPublishCkData(const ErrorCallback& onFailure);
128 
130  Name m_accessPrefix;
131  Name m_ckPrefix;
132  Name m_ckName;
133  Buffer m_ckBits;
134  SigningInfo m_ckDataSigningInfo;
135 
136  bool m_isKekRetrievalInProgress;
137  std::optional<Data> m_kek;
138  ErrorCallback m_onFailure;
139 
140  InMemoryStoragePersistent m_ims; // for encrypted CKs
141  ScopedRegisteredPrefixHandle m_ckReg;
142  PendingInterestHandle m_kekPendingInterest;
143 
144  KeyChain& m_keyChain;
145  Face& m_face;
146  Scheduler m_scheduler;
147 };
148 
149 } // namespace ndn::nac
150 
151 #endif // NDN_NAC_ENCRYPTOR_HPP
NAC Encryptor.
Definition: encryptor.hpp:34
size_t size() const
Definition: encryptor.hpp:90
Encryptor(const Name &accessPrefix, const Name &ckPrefix, SigningInfo ckDataSigningInfo, const ErrorCallback &onFailure, Validator &validator, KeyChain &keyChain, Face &face)
Definition: encryptor.cpp:36
EncryptedContent encrypt(span< const uint8_t > data)
Synchronously encrypt supplied data.
Definition: encryptor.cpp:117
void regenerateCk()
Create a new content key and publish the corresponding CK data.
Definition: encryptor.cpp:98
InMemoryStorage::const_iterator end() const
Returns end iterator of the in-memory storage ordered by name with digest.
Definition: encryptor.hpp:112
InMemoryStorage::const_iterator begin() const
Returns begin iterator of the in-memory storage ordered by name with digest.
Definition: encryptor.hpp:101
#define NAC_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:33
std::function< void(const ErrorCode &, const std::string &)> ErrorCallback
Definition: common.hpp:117