Skip to content

Commit 2415aa9

Browse files
committed
chore: fmtfix
1 parent 0ca15dd commit 2415aa9

File tree

7 files changed

+70
-68
lines changed

7 files changed

+70
-68
lines changed
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
//! COSE Signature Protected Header `kid` URI Authority.
22
33
use std::{
4-
fmt::{Display, Formatter},
5-
str::FromStr,
4+
fmt::{Display, Formatter},
5+
str::FromStr,
66
};
77

88
/// URI Authority
99
#[derive(Debug, Clone)]
1010
pub enum Authority {
11-
/// Cardano Blockchain
12-
Cardano,
13-
/// Midnight Blockchain
14-
Midnight,
11+
/// Cardano Blockchain
12+
Cardano,
13+
/// Midnight Blockchain
14+
Midnight,
1515
}
1616

1717
impl FromStr for Authority {
18-
type Err = anyhow::Error;
18+
type Err = anyhow::Error;
1919

20-
fn from_str(s: &str) -> Result<Self, Self::Err> {
21-
match s {
22-
"cardano" => Ok(Authority::Cardano),
23-
"midnight" => Ok(Authority::Midnight),
24-
_ => Err(anyhow::anyhow!("Unknown Authority: {s}")),
25-
}
26-
}
20+
fn from_str(s: &str) -> Result<Self, Self::Err> {
21+
match s {
22+
"cardano" => Ok(Authority::Cardano),
23+
"midnight" => Ok(Authority::Midnight),
24+
_ => Err(anyhow::anyhow!("Unknown Authority: {s}")),
25+
}
26+
}
2727
}
2828

2929
impl Display for Authority {
30-
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
31-
let authority = match self {
32-
Self::Cardano => "cardano",
33-
Self::Midnight => "midnight",
34-
};
35-
write!(f, "{authority}")
36-
}
37-
}
30+
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
31+
let authority = match self {
32+
Self::Cardano => "cardano",
33+
Self::Midnight => "midnight",
34+
};
35+
write!(f, "{authority}")
36+
}
37+
}

rust/catalyst-types/src/kid_uri/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ pub enum KidURIError {
4040
/// Encryption key Identifier Fragment is not valid
4141
#[error("Invalid Encryption Key Fragment")]
4242
InvalidEncryptionKeyFragment,
43-
}
43+
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! COSE Signature Protected Header `kid` Role0 Key Version.
22
33
use std::{
4-
fmt::{Display, Formatter},
5-
num::ParseIntError,
6-
str::FromStr,
4+
fmt::{Display, Formatter},
5+
num::ParseIntError,
6+
str::FromStr,
77
};
88

99
use thiserror::Error;
@@ -12,31 +12,31 @@ use thiserror::Error;
1212
#[derive(Error, Debug)]
1313
#[allow(clippy::module_name_repetitions)]
1414
pub enum KeyRotationError {
15-
/// Key Rotation could not be parsed from a string
16-
#[error("Invalid Role Key Rotation")]
17-
InvalidRole(#[from] ParseIntError),
15+
/// Key Rotation could not be parsed from a string
16+
#[error("Invalid Role Key Rotation")]
17+
InvalidRole(#[from] ParseIntError),
1818
}
1919

2020
/// Rotation count of the Role Key.
2121
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
2222
pub struct KeyRotation(u16);
2323

2424
impl From<u16> for KeyRotation {
25-
fn from(value: u16) -> Self {
26-
Self(value)
27-
}
25+
fn from(value: u16) -> Self {
26+
Self(value)
27+
}
2828
}
2929

3030
impl FromStr for KeyRotation {
31-
type Err = KeyRotationError;
31+
type Err = KeyRotationError;
3232

33-
fn from_str(s: &str) -> Result<Self, Self::Err> {
34-
Ok(Self(s.parse::<u16>()?))
35-
}
33+
fn from_str(s: &str) -> Result<Self, Self::Err> {
34+
Ok(Self(s.parse::<u16>()?))
35+
}
3636
}
3737

3838
impl Display for KeyRotation {
39-
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
40-
write!(f, "{}", self.0)
41-
}
42-
}
39+
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
40+
write!(f, "{}", self.0)
41+
}
42+
}

rust/catalyst-types/src/kid_uri/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,4 @@ mod tests {
228228
let encoded_vk = base64_url::encode(vk.as_bytes());
229229
assert_eq!(encoded_vk, "1234");
230230
}
231-
}
231+
}
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
//! COSE Signature Protected Header `kid` URI Role0 Public Key.
22
33
use std::{
4-
fmt::{Display, Formatter},
5-
str::FromStr,
4+
fmt::{Display, Formatter},
5+
str::FromStr,
66
};
77

88
/// Role0 Public Key.
99
#[derive(Debug, Clone)]
1010
pub struct Role0PublicKey([u8; 32]);
1111

1212
impl FromStr for Role0PublicKey {
13-
type Err = anyhow::Error;
13+
type Err = anyhow::Error;
1414

15-
fn from_str(s: &str) -> Result<Self, Self::Err> {
16-
let Some(role0_hex) = s.strip_prefix("0x") else {
17-
anyhow::bail!("Role0 Public Key hex string must start with '0x': {}", s);
18-
};
19-
let role0_key = hex::decode(role0_hex)
20-
.map_err(|e| anyhow::anyhow!("Role0 Public Key is not a valid hex string: {}", e))?;
21-
if role0_key.len() != 32 {
22-
anyhow::bail!(
23-
"Role0 Public Key must have 32 bytes: {role0_hex}, len: {}",
24-
role0_key.len()
25-
);
26-
}
27-
let role0 = role0_key.try_into().map_err(|e| {
28-
anyhow::anyhow!(
29-
"Unable to read Role0 Public Key, this should never happen. Eror: {e:?}"
30-
)
31-
})?;
32-
Ok(Role0PublicKey(role0))
33-
}
15+
fn from_str(s: &str) -> Result<Self, Self::Err> {
16+
let Some(role0_hex) = s.strip_prefix("0x") else {
17+
anyhow::bail!("Role0 Public Key hex string must start with '0x': {}", s);
18+
};
19+
let role0_key = hex::decode(role0_hex)
20+
.map_err(|e| anyhow::anyhow!("Role0 Public Key is not a valid hex string: {}", e))?;
21+
if role0_key.len() != 32 {
22+
anyhow::bail!(
23+
"Role0 Public Key must have 32 bytes: {role0_hex}, len: {}",
24+
role0_key.len()
25+
);
26+
}
27+
let role0 = role0_key.try_into().map_err(|e| {
28+
anyhow::anyhow!(
29+
"Unable to read Role0 Public Key, this should never happen. Eror: {e:?}"
30+
)
31+
})?;
32+
Ok(Role0PublicKey(role0))
33+
}
3434
}
3535

3636
impl Display for Role0PublicKey {
37-
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
38-
write!(f, "0x{}", hex::encode(self.0))
39-
}
40-
}
37+
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
38+
write!(f, "0x{}", hex::encode(self.0))
39+
}
40+
}

rust/catalyst-types/src/kid_uri/role_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ impl Display for RoleIndex {
4141
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
4242
write!(f, "{}", self.0)
4343
}
44-
}
44+
}

rust/catalyst-types/tests/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ fn test_type_usage() {
1212
type D = catalyst_types::uuid::V4;
1313
type E = catalyst_types::uuid::V7;
1414

15+
type F = catalyst_types::kid_uri::KidURI;
16+
1517
let bytes: [u8; 32] = [0; 32];
1618
let _ = catalyst_types::hashes::Blake2bHash::from(bytes);
1719
}

0 commit comments

Comments
 (0)