Skip to content

Commit e504051

Browse files
authored
chore: improve header error (#67)
1 parent 6588932 commit e504051

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

relay_rpc/src/auth/cacao.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use {
77
core::fmt::Debug,
88
serde::{Deserialize, Serialize},
99
serde_json::value::RawValue,
10-
std::fmt::{Display, Write},
10+
std::{
11+
fmt::{Display, Write},
12+
sync::Arc,
13+
},
1114
};
1215

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

2326
#[error("Invalid or missing identity key in payload resources")]
2427
PayloadIdentityKey,

relay_rpc/src/auth/cacao/header.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
use {
22
super::CacaoError,
33
serde::{Deserialize, Serialize},
4+
std::sync::Arc,
45
};
56

67
pub const EIP4361: &str = "eip4361";
78

89
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Hash)]
910
pub struct Header {
10-
pub t: String,
11+
pub t: Arc<str>,
1112
}
1213

1314
impl Header {
1415
pub fn validate(&self) -> Result<(), CacaoError> {
15-
match self.t.as_str() {
16+
match self.t.as_ref() {
1617
EIP4361 => Ok(()),
17-
_ => Err(CacaoError::Header),
18+
_ => Err(CacaoError::HeaderTypeUnsupported(self.t.clone())),
1819
}
1920
}
2021
}

0 commit comments

Comments
 (0)