Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve header error #67

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())),
}
}
}
Loading