@@ -53,6 +53,7 @@ impl Zeroize for BackupData {
5353 self . 0 . generator . zeroize ( ) ;
5454 }
5555}
56+
5657/// Pad a seed with zeroes to the right up to 32 bytes. That the seed field in backups is always 32
5758/// bytes is a historical "accident" as it was easier to fix the size when using C (and nanopb
5859/// protobuf), with the seed_length indicating the actual length.
@@ -267,6 +268,24 @@ mod tests {
267268
268269 use bitbox02:: testing:: mock_sd;
269270
271+ #[ test]
272+ fn test_id ( ) {
273+ // Seeds of different lengths (16, 24, 32 bytes)
274+ let seed_16 = [ 1u8 ; 16 ] ;
275+ let seed_24 = [ 2u8 ; 24 ] ;
276+ let seed_32 = [ 3u8 ; 32 ] ;
277+
278+ // Expected outputs for each seed length
279+ let expected_output_16 = "2ca3c18f988437806217db3bbee04913cbfaaa7152d4a9c00c80cf3802d0ef6f" ;
280+ let expected_output_24 = "57c24fa271ba9c6f4d5f2519c26f52dae8f491423daffb87d1c1002ca8a2b172" ;
281+ let expected_output_32 = "89910bac6d7f82e4e97ea2b6449e201dfd793adb75b342a90314d178866c89eb" ;
282+
283+ // Assert that id function produces expected outputs
284+ assert_eq ! ( id( & seed_16) , expected_output_16) ;
285+ assert_eq ! ( id( & seed_24) , expected_output_24) ;
286+ assert_eq ! ( id( & seed_32) , expected_output_32) ;
287+ }
288+
270289 fn _test_create_load ( seed : & [ u8 ] ) {
271290 mock_sd ( ) ;
272291 let timestamp = 1601281809 ;
@@ -328,6 +347,7 @@ mod tests {
328347 fn test_create_load ( ) {
329348 // Test for seeds of different size.
330349 _test_create_load ( & b"\x52 \x20 \xa4 \xe9 \xce \xea \xc6 \x80 \x5d \xf2 \x36 \x09 \xf6 \xb4 \x78 \xbb \x28 \xca \x69 \xb5 \x16 \x95 \xed \x7c \x03 \xbf \x74 \x3a \xa5 \xde \xe3 \x7e " [ ..] ) ;
350+ _test_create_load ( & b"\x52 \x20 \xa4 \xe9 \xce \xea \xc6 \x80 \x5d \xf2 \x36 \x09 \xf6 \xb4 \x78 \xbb \x28 \xca \x69 \xb5 \x16 \x95 \xed \x7c " [ ..] ) ;
331351 _test_create_load ( & b"\x52 \x20 \xa4 \xe9 \xce \xea \xc6 \x80 \x5d \xf2 \x36 \x09 " [ ..] ) ;
332352 }
333353
0 commit comments