@@ -8,8 +8,8 @@ pub use admin::Admin;
88mod test_app;
99pub use test_app:: TestApp ;
1010
11- use blake2:: digest:: { Update , VariableOutput } ;
12- use blake2:: VarBlake2b ;
11+ use blake2:: digest:: { consts , VariableOutput } ;
12+ use blake2:: { Blake2b , Blake2bVar } ;
1313use ed25519_dalek:: { Keypair , Signer } ;
1414use rand:: { rngs:: OsRng , Rng } ;
1515use serde_json:: { json, Value } ;
@@ -24,25 +24,32 @@ const USER_SECRET_SIZE: usize = 32;
2424const SIGNATURE_SIZE : usize = 64 ;
2525
2626pub fn hash_user_id ( app_id : & [ u8 ] , user_id : & str ) -> Vec < u8 > {
27- let mut hasher = VarBlake2b :: new ( BLOCK_HASH_SIZE ) . unwrap ( ) ;
27+ use blake2:: digest:: Update ;
28+
29+ let mut hasher = Blake2bVar :: new ( BLOCK_HASH_SIZE ) . unwrap ( ) ;
2830 hasher. update ( user_id. as_bytes ( ) ) ;
2931 hasher. update ( app_id) ;
3032 hasher. finalize_boxed ( ) . to_vec ( )
3133}
3234
3335pub fn generate_user_secret ( hashed_user_id : & [ u8 ] ) -> Vec < u8 > {
36+ use blake2:: Digest ;
37+
3438 let random_bytes: [ u8 ; USER_SECRET_SIZE - 1 ] = rand:: thread_rng ( ) . gen ( ) ;
35- let mut hasher = VarBlake2b :: new ( 1 ) . unwrap ( ) ;
39+ let mut hasher = Blake2b :: < consts :: U1 > :: new ( ) ;
3640 hasher. update ( & random_bytes) ;
3741 hasher. update ( hashed_user_id) ;
3842
3943 let mut user_secret = random_bytes. to_vec ( ) ;
40- hasher. finalize_variable ( |h| user_secret. push ( h[ 0 ] ) ) ;
44+ let res = hasher. finalize ( ) ;
45+ user_secret. push ( res[ 0 ] ) ;
4146 user_secret
4247}
4348
4449pub fn generate_app_id ( app_secret : & [ u8 ] ) -> Vec < u8 > {
45- let mut hasher = VarBlake2b :: new ( BLOCK_HASH_SIZE ) . unwrap ( ) ;
50+ use blake2:: digest:: Update ;
51+
52+ let mut hasher = Blake2bVar :: new ( BLOCK_HASH_SIZE ) . unwrap ( ) ;
4653 hasher. update ( & [ APP_CREATION_NATURE ] ) ;
4754 hasher. update ( & [ 0u8 ; AUTHOR_SIZE ] ) ;
4855 hasher. update ( & app_secret[ app_secret. len ( ) - APP_PUBLIC_KEY_SIZE ..] ) ;
0 commit comments