Skip to content

Commit a481394

Browse files
committed
fix(rust): Fail correctly if converting from &[u8] and the data isn't valid UTF8.
1 parent 40fc69a commit a481394

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ pub enum IdUriError {
3232
InvalidRotationValue(#[from] KeyRotationError),
3333
/// Encryption key Identifier Fragment is not valid
3434
InvalidEncryptionKeyFragment,
35+
/// Invalid Text encoding
36+
InvalidTextEncoding(#[from] std::string::FromUtf8Error),
3537
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl FromStr for IdUri {
395395
let mut cat_id = Self::new(network, subnet, role0_pk)
396396
.with_role(role_index)
397397
.with_rotation(rotation);
398-
398+
399399
if uri.has_fragment() {
400400
if uri.fragment() == Some(Self::ENCRYPTION_FRAGMENT) {
401401
cat_id = cat_id.with_encryption();
@@ -476,7 +476,7 @@ impl TryFrom<&[u8]> for IdUri {
476476
type Error = errors::IdUriError;
477477

478478
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
479-
let kid_str = String::from_utf8_lossy(value);
479+
let kid_str = String::from_utf8(value.to_vec())?;
480480
IdUri::from_str(&kid_str)
481481
}
482482
}

0 commit comments

Comments
 (0)