Skip to content

Commit

Permalink
document hmacconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Feb 7, 2022
1 parent 49f71c8 commit 885599c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ use crate::body_extractor_fold::body_extractor_fold;
/// .app_data(HmacConfig::static_key(key))
/// # ;
/// ```
///
/// # Todo
/// - [ ] Async dynamic key extractor methods.
/// - [ ] Concurrently acquire key and feed wrapped extractor.
/// - [ ] Expose constant-time digest verification.
#[derive(Debug, Clone)]
pub struct BodyHmac<T, D>
where
Expand Down Expand Up @@ -108,6 +113,7 @@ pub struct HmacConfig {
}

impl HmacConfig {
/// Configure HMAC extractors to use a global, static key for all HMAC calculations.
pub fn static_key(key: impl Into<Vec<u8>>) -> Self {
let key = key.into();

Expand All @@ -116,6 +122,10 @@ impl HmacConfig {
}
}

/// Configure HMAC extractors to use a custom method for obtaining a secret keys.
///
/// Closure receives a reference to the HTTP request. Use when signature of request depends on
/// per-user secret keys.
pub fn dynamic_key(key_fn: impl Fn(&HttpRequest) -> Result<Vec<u8>, Error> + 'static) -> Self {
Self {
key_fn: Box::new(key_fn),
Expand Down

0 comments on commit 885599c

Please sign in to comment.