Skip to content

Commit

Permalink
PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Jan 16, 2024
1 parent faefe9c commit 6fdfc09
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/ed25519-pub-key-bytes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"iota-crypto": patch
---

Added ed25519 PublicKeyBytes wrapper that does not require validation to use.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iota-crypto"
version = "0.23.1"
version = "0.23.0"
license = "Apache-2.0"
authors = [ "IOTA Stiftung" ]
edition = "2021"
Expand Down
9 changes: 5 additions & 4 deletions src/signatures/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ impl PublicKeyBytes {
}

pub fn into_public_key(self) -> crate::Result<PublicKey> {
Ok(PublicKey(self.0.try_into().map_err(|_| {
crate::Error::ConvertError {
self.0
.try_into()
.map_err(|_| crate::Error::ConvertError {
from: "Ed25519 public key bytes",
to: "Ed25519 public key",
}
})?))
})
.map(PublicKey)
}

pub fn as_slice(&self) -> &[u8] {
Expand Down
14 changes: 10 additions & 4 deletions tests/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ fn test_zip215() -> crypto::Result<()> {
for tv in tvs.iter() {
let mut pkb = [0; PUBLIC_KEY_LENGTH];
hex::decode_to_slice(tv.public_key, &mut pkb as &mut [u8]).unwrap();
let pk = PublicKeyBytes::from_bytes(pkb);
let pk = PublicKey::try_from_bytes(pkb)?;
let pkb = PublicKeyBytes::from_bytes(pkb);

let mut sigb = [0; SIGNATURE_LENGTH];
hex::decode_to_slice(tv.signature, &mut sigb as &mut [u8]).unwrap();
let sig = Signature::from_bytes(sigb);

assert!(pk.verify(&sig, ms)?);
assert!(pk.verify(&sig, ms));
assert!(pkb.verify(&sig, ms)?);
assert_eq!(pkb.into_public_key()?, pk);
}

Ok(())
Expand All @@ -55,9 +58,12 @@ fn test_malleability() -> crypto::Result<()> {
0x7d, 0x4d, 0x0e, 0x7f, 0x61, 0x53, 0xa6, 0x9b, 0x62, 0x42, 0xb5, 0x22, 0xab, 0xbe, 0xe6, 0x85, 0xfd, 0xa4,
0x42, 0x0f, 0x88, 0x34, 0xb1, 0x08, 0xc3, 0xbd, 0xae, 0x36, 0x9e, 0xf5, 0x49, 0xfa,
];
let pk = PublicKeyBytes::from_bytes(pkb);
let pk = PublicKey::try_from_bytes(pkb)?;
let pkb = PublicKeyBytes::from_bytes(pkb);

assert!(!pk.verify(&sig, &ms)?);
assert!(!pk.verify(&sig, &ms));
assert!(!pkb.verify(&sig, &ms)?);
assert_eq!(pkb.into_public_key()?, pk);

Ok(())
}
Expand Down

0 comments on commit 6fdfc09

Please sign in to comment.