Skip to content

Commit

Permalink
define error
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Feb 17, 2024
1 parent f72d49f commit f5882e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/http-signatures/src/cavage/signature_string.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
use crate::{REQUIRED_GET_HEADERS, REQUIRED_POST_HEADERS};
use http::Method;
use miette::Diagnostic;
use thiserror::Error;

pub const REQUIRED_GET_HEADERS: &[&str] = &["host", "date"];
pub const REQUIRED_POST_HEADERS: &[&str] = &["host", "date", "content-type", "digest"];
#[derive(Debug, Diagnostic, Error)]
pub enum Error {
#[error("Invalid HTTP method")]
InvalidMethod,

#[error("Missing required header names")]
MissingHeaderNames,
}

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

#[inline]
pub fn construct<B>(request: &http::Request<B>, header_names: &[&str]) -> Result<(), ()> {
pub fn construct<B>(request: &http::Request<B>, header_names: &[&str]) -> Result<(), Error> {
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?"),
_ => return Err(Error::InvalidMethod),
};

if !fulfills_min_requirements {
return Err(());
return Err(Error::MissingHeaderNames);
}

todo!();
Expand Down
3 changes: 3 additions & 0 deletions lib/http-signatures/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pub mod cavage;

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

0 comments on commit f5882e1

Please sign in to comment.