@@ -148,11 +148,22 @@ impl MithrilFixtureBuilder {
148
148
key_buffer : & ' a mut [ u8 ] ,
149
149
kes_key_seed : & ' a mut [ u8 ] ,
150
150
) -> ( Sum6KesBytes , PublicKey ) {
151
- if let Some ( cached_value) = precomputed_keskey:: cached_kes_key ( kes_key_seed) {
152
- return cached_value;
151
+ if let Some ( ( kes_bytes, kes_verification_key) ) =
152
+ MithrilFixtureBuilder :: cached_kes_key ( kes_key_seed)
153
+ {
154
+ ( kes_bytes, kes_verification_key)
155
+ } else {
156
+ // TODO We can log a warning to indicate that the cache is not used
157
+ MithrilFixtureBuilder :: generate_kes_key ( key_buffer, kes_key_seed)
153
158
}
154
- // TODO We can log a warning to indicate that the cache is not used
155
- MithrilFixtureBuilder :: generate_kes_key ( key_buffer, kes_key_seed)
159
+ }
160
+
161
+ fn cached_kes_key ( kes_key_seed : & [ u8 ] ) -> Option < ( Sum6KesBytes , PublicKey ) > {
162
+ precomputed_keskey:: cached_kes_key ( kes_key_seed) . map ( |( kes_bytes, kes_verification_key) | {
163
+ let kes_verification_key = PublicKey :: from_bytes ( & kes_verification_key) . unwrap ( ) ;
164
+ let kes_bytes = Sum6KesBytes ( kes_bytes) ;
165
+ ( kes_bytes, kes_verification_key)
166
+ } )
156
167
}
157
168
158
169
fn generate_kes_key < ' a > (
@@ -302,7 +313,9 @@ mod tests {
302
313
}
303
314
304
315
/// Verify that there is cached kes key for a number of party id.
305
- /// If the cache is not up to date, it will generate the code to use as cache.
316
+ /// If the cache is not up to date, the test will generate the code that could be copy/paste into the [precomputed_keskey] module.
317
+ /// The number of party id that should be in cache is defined in the test.
318
+ /// If we want lore or less, just change `precomputed_number` value and launch the test to generate the code.
306
319
#[ test]
307
320
fn verify_kes_key_cache_content ( ) {
308
321
// Generate code that should be in the match instruction of cached_kes_key.
@@ -337,7 +350,7 @@ mod tests {
337
350
let cached_kes_key: Vec < _ > = cold_keys
338
351
. iter ( )
339
352
. filter_map ( |cold_key| {
340
- precomputed_keskey :: cached_kes_key ( cold_key) . map (
353
+ MithrilFixtureBuilder :: cached_kes_key ( cold_key) . map (
341
354
|( kes_bytes, kes_verification_key) | {
342
355
( cold_key. as_slice ( ) , kes_bytes. 0 , kes_verification_key)
343
356
} ,
@@ -356,7 +369,7 @@ mod tests {
356
369
357
370
let kes_key_seed = fixture. generate_cold_key_seed ( precomputed_number) ;
358
371
assert ! (
359
- precomputed_keskey :: cached_kes_key( kes_key_seed. as_slice( ) ) . is_none( ) ,
372
+ MithrilFixtureBuilder :: cached_kes_key( kes_key_seed. as_slice( ) ) . is_none( ) ,
360
373
"We checked precomputed keskey up to {} but it seems to be more." ,
361
374
precomputed_number
362
375
) ;
0 commit comments