mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-21 17:00:59 +00:00
Constify Config
This commit is contained in:
parent
c5065542c8
commit
0068556382
1 changed files with 12 additions and 12 deletions
24
src/lib.rs
24
src/lib.rs
|
@ -75,7 +75,7 @@ const SIGNATURE_FIELD: &str = "signature";
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
expires_after: Duration,
|
expires_after: Duration,
|
||||||
use_created_field: bool,
|
use_created_field: bool,
|
||||||
required_headers: HashSet<String>,
|
required_headers: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -155,8 +155,12 @@ impl RequiredError {
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
/// Create a new Config with a default expiration of 10 seconds
|
/// Create a new Config with a default expiration of 10 seconds
|
||||||
pub fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Config::default()
|
Config {
|
||||||
|
expires_after: Duration::from_secs(10),
|
||||||
|
use_created_field: true,
|
||||||
|
required_headers: Vec::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable mastodon compatibility
|
/// Enable mastodon compatibility
|
||||||
|
@ -184,14 +188,14 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the expiration to a custom duration
|
/// Set the expiration to a custom duration
|
||||||
pub fn set_expiration(mut self, expires_after: Duration) -> Self {
|
pub const fn set_expiration(mut self, expires_after: Duration) -> Self {
|
||||||
self.expires_after = expires_after;
|
self.expires_after = expires_after;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark a header as required
|
/// Mark a header as required
|
||||||
pub fn require_header(mut self, header: &str) -> Self {
|
pub fn require_header(mut self, header: &str) -> Self {
|
||||||
self.required_headers.insert(header.to_lowercase());
|
self.required_headers.push(header.to_lowercase());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +230,7 @@ impl Config {
|
||||||
expires,
|
expires,
|
||||||
&sig_headers,
|
&sig_headers,
|
||||||
&mut headers,
|
&mut headers,
|
||||||
self.required_headers.clone(),
|
self.required_headers.iter().cloned().collect(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Unsigned {
|
Ok(Unsigned {
|
||||||
|
@ -260,7 +264,7 @@ impl Config {
|
||||||
method,
|
method,
|
||||||
path_and_query,
|
path_and_query,
|
||||||
&mut headers,
|
&mut headers,
|
||||||
self.required_headers.clone(),
|
self.required_headers.iter().cloned().collect(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(unvalidated.validate(self.expires_after)?)
|
Ok(unvalidated.validate(self.expires_after)?)
|
||||||
|
@ -325,11 +329,7 @@ fn build_signing_string(
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Config {
|
Self::new()
|
||||||
expires_after: Duration::from_secs(10),
|
|
||||||
use_created_field: true,
|
|
||||||
required_headers: HashSet::new(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue