@@ -327,6 +327,11 @@ where
327
327
. collect :: < Result < _ , Error < C > > > ( )
328
328
}
329
329
330
+ /// Serialize to bytes
331
+ pub fn serialize_whole ( & self ) -> Result < Vec < u8 > , Error < C > > {
332
+ self . serialize ( ) . map ( |v| v. concat ( ) )
333
+ }
334
+
330
335
/// Returns VerifiableSecretSharingCommitment from an iterator of serialized
331
336
/// CoefficientCommitments (e.g. a [`Vec<Vec<u8>>`]).
332
337
pub fn deserialize < I , V > ( serialized_coefficient_commitments : I ) -> Result < Self , Error < C > >
@@ -342,6 +347,24 @@ where
342
347
Ok ( Self :: new ( coefficient_commitments) )
343
348
}
344
349
350
+ /// Deserialize from bytes
351
+ pub fn deserialize_whole ( bytes : & [ u8 ] ) -> Result < Self , Error < C > > {
352
+ // Get size from the size of the generator
353
+ let generator = <C :: Group >:: generator ( ) ;
354
+ let len = <C :: Group >:: serialize ( & generator)
355
+ . expect ( "serializing the generator always works" )
356
+ . as_ref ( )
357
+ . len ( ) ;
358
+
359
+ let serialized_coefficient_commitments = bytes. chunks_exact ( len) ;
360
+
361
+ if !serialized_coefficient_commitments. remainder ( ) . is_empty ( ) {
362
+ return Err ( Error :: InvalidCoefficient ) ;
363
+ }
364
+
365
+ Self :: deserialize ( serialized_coefficient_commitments)
366
+ }
367
+
345
368
/// Get the VerifyingKey matching this commitment vector (which is the first
346
369
/// element in the vector), or an error if the vector is empty.
347
370
pub ( crate ) fn verifying_key ( & self ) -> Result < VerifyingKey < C > , Error < C > > {
0 commit comments