Skip to content

Commit

Permalink
chore: improve header error (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored Feb 27, 2024
1 parent 6588932 commit e504051
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions relay_rpc/src/auth/cacao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use {
core::fmt::Debug,
serde::{Deserialize, Serialize},
serde_json::value::RawValue,
std::fmt::{Display, Write},
std::{
fmt::{Display, Write},
sync::Arc,
},
};

pub mod header;
Expand All @@ -17,8 +20,8 @@ pub mod signature;
/// Errors that can occur during Cacao verification.
#[derive(Debug, thiserror::Error)]
pub enum CacaoError {
#[error("Invalid header")]
Header,
#[error("Header `t` value unsupported: {0}")]
HeaderTypeUnsupported(Arc<str>),

#[error("Invalid or missing identity key in payload resources")]
PayloadIdentityKey,
Expand Down
7 changes: 4 additions & 3 deletions relay_rpc/src/auth/cacao/header.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use {
super::CacaoError,
serde::{Deserialize, Serialize},
std::sync::Arc,
};

pub const EIP4361: &str = "eip4361";

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Hash)]
pub struct Header {
pub t: String,
pub t: Arc<str>,
}

impl Header {
pub fn validate(&self) -> Result<(), CacaoError> {
match self.t.as_str() {
match self.t.as_ref() {
EIP4361 => Ok(()),
_ => Err(CacaoError::Header),
_ => Err(CacaoError::HeaderTypeUnsupported(self.t.clone())),
}
}
}

0 comments on commit e504051

Please sign in to comment.