mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-24 02:11:01 +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 {
|
||||
expires_after: Duration,
|
||||
use_created_field: bool,
|
||||
required_headers: HashSet<String>,
|
||||
required_headers: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -155,8 +155,12 @@ impl RequiredError {
|
|||
|
||||
impl Config {
|
||||
/// Create a new Config with a default expiration of 10 seconds
|
||||
pub fn new() -> Self {
|
||||
Config::default()
|
||||
pub const fn new() -> Self {
|
||||
Config {
|
||||
expires_after: Duration::from_secs(10),
|
||||
use_created_field: true,
|
||||
required_headers: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Enable mastodon compatibility
|
||||
|
@ -184,14 +188,14 @@ impl Config {
|
|||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
||||
/// Mark a header as required
|
||||
pub fn require_header(mut self, header: &str) -> Self {
|
||||
self.required_headers.insert(header.to_lowercase());
|
||||
self.required_headers.push(header.to_lowercase());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -226,7 +230,7 @@ impl Config {
|
|||
expires,
|
||||
&sig_headers,
|
||||
&mut headers,
|
||||
self.required_headers.clone(),
|
||||
self.required_headers.iter().cloned().collect(),
|
||||
)?;
|
||||
|
||||
Ok(Unsigned {
|
||||
|
@ -260,7 +264,7 @@ impl Config {
|
|||
method,
|
||||
path_and_query,
|
||||
&mut headers,
|
||||
self.required_headers.clone(),
|
||||
self.required_headers.iter().cloned().collect(),
|
||||
)?;
|
||||
|
||||
Ok(unvalidated.validate(self.expires_after)?)
|
||||
|
@ -325,11 +329,7 @@ fn build_signing_string(
|
|||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Config {
|
||||
expires_after: Duration::from_secs(10),
|
||||
use_created_field: true,
|
||||
required_headers: HashSet::new(),
|
||||
}
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue