@@ -180,16 +180,12 @@ pub trait User {
180180 /// use cot::auth::{SessionAuthHash, User, UserId};
181181 /// use cot::common_types::Password;
182182 /// use cot::config::SecretKey;
183- /// use hmac::{Hmac, Mac};
184- /// use sha2::Sha512;
185183 ///
186184 /// struct MyUser {
187185 /// id: i64,
188186 /// password: Password,
189187 /// }
190188 ///
191- /// type SessionAuthHmac = Hmac<Sha512>;
192- ///
193189 /// impl User for MyUser {
194190 /// fn id(&self) -> Option<UserId> {
195191 /// Some(UserId::Int(self.id))
@@ -211,12 +207,12 @@ pub trait User {
211207 /// // thanks to this, the session hash is invalidated when the user changes their password
212208 /// // and the user is automatically logged out
213209 ///
214- /// let mut mac = SessionAuthHmac::new_from_slice(secret_key.as_bytes())
215- /// .expect("HMAC can take key of any size");
216- /// mac.update(self.password.as_str() .as_bytes());
217- /// let hmac_data = mac.finalize ().into_bytes( );
210+ /// const SESSION_AUTH_HASH_CONTEXT: &'static str = "cot.rs session auth hash v1";
211+ ///
212+ /// let key = blake3::derive_key(SESSION_AUTH_HASH_CONTEXT, secret_key .as_bytes());
213+ /// let hash = blake3::keyed_hash(&key, self.password.as_str ().as_bytes() );
218214 ///
219- /// Some(SessionAuthHash::new(&hmac_data ))
215+ /// Some(SessionAuthHash::new(hash.as_slice() ))
220216 /// }
221217 /// }
222218 /// ```
@@ -350,16 +346,12 @@ impl User for AnonymousUser {}
350346/// use cot::auth::{SessionAuthHash, User, UserId};
351347/// use cot::common_types::Password;
352348/// use cot::config::SecretKey;
353- /// use hmac::{Hmac, Mac};
354- /// use sha2::Sha512;
355349///
356350/// struct MyUser {
357351/// id: i64,
358352/// password: Password,
359353/// }
360354///
361- /// type SessionAuthHmac = Hmac<Sha512>;
362- ///
363355/// impl User for MyUser {
364356/// fn id(&self) -> Option<UserId> {
365357/// Some(UserId::Int(self.id))
@@ -381,12 +373,12 @@ impl User for AnonymousUser {}
381373/// // thanks to this, the session hash is invalidated when the user changes their password
382374/// // and the user is automatically logged out
383375///
384- /// let mut mac = SessionAuthHmac::new_from_slice(secret_key.as_bytes())
385- /// .expect("HMAC can take key of any size");
386- /// mac.update(self.password.as_str() .as_bytes());
387- /// let hmac_data = mac.finalize ().into_bytes( );
376+ /// const SESSION_AUTH_HASH_CONTEXT: &'static str = "cot.rs session auth hash v1";
377+ ///
378+ /// let key = blake3::derive_key(SESSION_AUTH_HASH_CONTEXT, secret_key .as_bytes());
379+ /// let hash = blake3::keyed_hash(&key, self.password.as_str ().as_bytes() );
388380///
389- /// Some(SessionAuthHash::new(&hmac_data ))
381+ /// Some(SessionAuthHash::new(hash.as_slice() ))
390382/// }
391383/// }
392384/// ```
0 commit comments