88#include < sframe/result.h>
99#include < sframe/vector.h>
1010
11+ #ifdef __cpp_exceptions
12+ #include < stdexcept>
13+ #endif
14+
1115#include < namespace.h>
1216
1317// These constants define the size of certain internal data structures if
2832
2933namespace SFRAME_NAMESPACE {
3034
35+ #ifdef __cpp_exceptions
3136struct crypto_error : std::runtime_error
3237{
3338 crypto_error ();
@@ -60,6 +65,7 @@ struct invalid_key_usage_error : std::runtime_error
6065 using parent = std::runtime_error;
6166 using parent::parent;
6267};
68+ #endif
6369
6470enum class CipherSuite : uint16_t
6571{
@@ -111,15 +117,15 @@ class Context
111117 Context (CipherSuite suite);
112118 virtual ~Context ();
113119
114- void add_key (KeyID kid, KeyUsage usage, input_bytes key);
120+ Result< void > add_key (KeyID kid, KeyUsage usage, input_bytes key);
115121
116- output_bytes protect (KeyID key_id,
117- output_bytes ciphertext,
118- input_bytes plaintext,
119- input_bytes metadata);
120- output_bytes unprotect (output_bytes plaintext,
121- input_bytes ciphertext,
122- input_bytes metadata);
122+ Result< output_bytes> protect (KeyID key_id,
123+ output_bytes ciphertext,
124+ input_bytes plaintext,
125+ input_bytes metadata);
126+ Result< output_bytes> unprotect (output_bytes plaintext,
127+ input_bytes ciphertext,
128+ input_bytes metadata);
123129
124130 static constexpr size_t max_overhead = 17 + 16 ;
125131 static constexpr size_t max_metadata_size = 512 ;
@@ -150,29 +156,30 @@ class MLSContext : protected Context
150156
151157 MLSContext (CipherSuite suite_in, size_t epoch_bits_in);
152158
153- void add_epoch (EpochID epoch_id, input_bytes sframe_epoch_secret);
154- void add_epoch (EpochID epoch_id,
155- input_bytes sframe_epoch_secret,
156- size_t sender_bits);
159+ Result< void > add_epoch (EpochID epoch_id, input_bytes sframe_epoch_secret);
160+ Result< void > add_epoch (EpochID epoch_id,
161+ input_bytes sframe_epoch_secret,
162+ size_t sender_bits);
157163 void purge_before (EpochID keeper);
158164
159- output_bytes protect (EpochID epoch_id,
160- SenderID sender_id,
161- output_bytes ciphertext,
162- input_bytes plaintext,
163- input_bytes metadata);
164- output_bytes protect (EpochID epoch_id,
165- SenderID sender_id,
166- ContextID context_id,
167- output_bytes ciphertext,
168- input_bytes plaintext,
169- input_bytes metadata);
170-
171- output_bytes unprotect (output_bytes plaintext,
172- input_bytes ciphertext,
173- input_bytes metadata);
165+ Result< output_bytes> protect (EpochID epoch_id,
166+ SenderID sender_id,
167+ output_bytes ciphertext,
168+ input_bytes plaintext,
169+ input_bytes metadata);
170+ Result< output_bytes> protect (EpochID epoch_id,
171+ SenderID sender_id,
172+ ContextID context_id,
173+ output_bytes ciphertext,
174+ input_bytes plaintext,
175+ input_bytes metadata);
176+
177+ Result< output_bytes> unprotect (output_bytes plaintext,
178+ input_bytes ciphertext,
179+ input_bytes metadata);
174180
175181private:
182+ // NOLINTBEGIN(clang-analyzer-core.uninitialized.Assign)
176183 struct EpochKeys
177184 {
178185 static constexpr size_t max_secret_size = 64 ;
@@ -184,20 +191,22 @@ class MLSContext : protected Context
184191 uint64_t max_sender_id;
185192 uint64_t max_context_id;
186193
187- EpochKeys (EpochID full_epoch_in,
188- input_bytes sframe_epoch_secret_in,
189- size_t epoch_bits,
190- size_t sender_bits_in);
194+ EpochKeys () = default ;
195+ static Result<EpochKeys> create (EpochID full_epoch_in,
196+ input_bytes sframe_epoch_secret_in,
197+ size_t epoch_bits,
198+ size_t sender_bits_in);
191199 Result<owned_bytes<max_secret_size>> base_key (CipherSuite suite,
192200 SenderID sender_id) const ;
193201 };
202+ // NOLINTEND(clang-analyzer-core.uninitialized.Assign)
194203
195204 void purge_epoch (EpochID epoch_id);
196205
197- KeyID form_key_id (EpochID epoch_id,
198- SenderID sender_id,
199- ContextID context_id) const ;
200- void ensure_key (KeyID key_id, KeyUsage usage);
206+ Result< KeyID> form_key_id (EpochID epoch_id,
207+ SenderID sender_id,
208+ ContextID context_id) const ;
209+ Result< void > ensure_key (KeyID key_id, KeyUsage usage);
201210
202211 const size_t epoch_bits;
203212 const size_t epoch_mask;
0 commit comments