Skip to content

Commit

Permalink
add basic checks
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Feb 17, 2024
1 parent 45ba735 commit f72d49f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/http-signatures/src/cavage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use derive_builder::Builder;
pub use self::parse::{parse, ParseError};

mod parse;
mod signature_string;

pub mod signature_string;

#[derive(Builder, Clone)]
#[builder(vis = "pub(crate)")]
Expand Down
15 changes: 15 additions & 0 deletions lib/http-signatures/src/cavage/signature_string.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use http::Method;

pub const REQUIRED_GET_HEADERS: &[&str] = &["host", "date"];
pub const REQUIRED_POST_HEADERS: &[&str] = &["host", "date", "content-type", "digest"];

#[inline]
fn is_subset<I>(left: &[I], right: &[I]) -> bool
where
Expand All @@ -12,6 +17,16 @@ where

#[inline]
pub fn construct<B>(request: &http::Request<B>, header_names: &[&str]) -> Result<(), ()> {
let fulfills_min_requirements = match *request.method() {
Method::GET => is_subset(REQUIRED_GET_HEADERS, header_names),
Method::POST => is_subset(REQUIRED_POST_HEADERS, header_names),
_ => todo!("how should we handle this?"),
};

if !fulfills_min_requirements {
return Err(());
}

todo!();
}

Expand Down

0 comments on commit f72d49f

Please sign in to comment.