Skip to content

Commit

Permalink
Make helium-crypto-rs compilable with the latest ed25519-compact vers…
Browse files Browse the repository at this point in the history
…ion (#69)

* Fix compiling issue. Use ed25519-compact 2.0.6 version

* Make helium-crypto-rs compilable with the latest ed25519-compact version

* Remove useless map_err

* Use ed25519_compact::Signature::try_from for all implemented traits
  • Loading branch information
kurotych authored Feb 5, 2024
1 parent 0b855d4 commit 79d1f90
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ed25519/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ impl Keypair {

impl signature::Signature for Signature {
fn from_bytes(input: &[u8]) -> std::result::Result<Self, signature::Error> {
Ok(Signature(signature::Signature::from_bytes(input)?))
let signature =
ed25519_compact::Signature::try_from(input).map_err(signature::Error::from_source)?;
Ok(Signature(signature))
}

fn as_bytes(&self) -> &[u8] {
self.0.as_bytes()
self.0.as_ref()
}
}

Expand Down Expand Up @@ -138,7 +140,8 @@ impl signature::Signer<Signature> for Keypair {

impl Signature {
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
Ok(Signature(signature::Signature::from_bytes(bytes)?))
let signature = ed25519_compact::Signature::try_from(bytes)?;
Ok(Signature(signature))
}

pub fn to_vec(&self) -> Vec<u8> {
Expand All @@ -150,9 +153,8 @@ impl TryFrom<&[u8]> for Signature {
type Error = Error;

fn try_from(input: &[u8]) -> Result<Self> {
signature::Signature::from_bytes(input)
.map(Signature)
.map_err(Error::from)
let signature = ed25519_compact::Signature::try_from(input)?;
Ok(Signature(signature))
}
}

Expand Down

0 comments on commit 79d1f90

Please sign in to comment.