@@ -16,17 +16,35 @@ XOF reader from which results of arbitrary length can be read. Note that
1616these functions do not implement ` Digest ` , so lower-level traits have to
1717be imported:
1818
19- ``` rust,ignore
20- // TODO: update to TurboSHAKE
21- use sha3::{Shake128, digest::{Update, ExtendableOutput, XofReader} };
19+ ``` rust
20+ use turbo_shake :: TurboShake128 ;
21+ use turbo_shake :: digest :: {Update , ExtendableOutput , XofReader };
2222use hex_literal :: hex;
2323
24- let mut hasher = Shake128::default();
24+ // With the default domain separator.
25+ //
26+ // Note that we have to use `<TurboShake128>` because of
27+ // the inadequate handling of defaults in Rust.
28+ // Alternatively, you could use `let mut hasher: TurboShake128 = Default::default();`
29+ // or `TurboShake128::<DEFAULT_DS>::default()`.
30+ let mut hasher = <TurboShake128 >:: default ();
2531hasher . update (b " abc" );
2632let mut reader = hasher . finalize_xof ();
2733let mut buf = [0u8 ; 10 ];
2834reader . read (& mut buf );
29- assert_eq!(buf, hex!("5881092dd818bf5cf8a3"));
35+ assert_eq! (buf , hex! (" dcf1646dfe993a8eb6b7" ));
36+ reader . read (& mut buf );
37+ assert_eq! (buf , hex! (" 82d1faaca6d82416a5dc" ));
38+
39+ // With a custom domain separator
40+ let mut hasher = TurboShake128 :: <0x10 >:: default ();
41+ hasher . update (b " abc" );
42+ let mut reader = hasher . finalize_xof ();
43+ let mut buf = [0u8 ; 10 ];
44+ reader . read (& mut buf );
45+ assert_eq! (buf , hex! (" 6702f7b19ea87087ed0f" ));
46+ reader . read (& mut buf );
47+ assert_eq! (buf , hex! (" 45a2fa692bc18c3526d3" ));
3048```
3149
3250See the [ ` digest ` ] crate docs for additional examples.
0 commit comments