Skip to content

Commit

Permalink
Update the ed25519 traits crate
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Feb 4, 2024
1 parent dc33fd0 commit 2cb1c6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ getrandom = { version = "0.2", optional = true }

[dependencies]
ct-codecs = { version = "1.1", optional = true }
ed25519 = { version = "1.5", optional = true }
ed25519 = { version = "2.2", optional = true }

[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }
Expand Down
19 changes: 12 additions & 7 deletions src/ed25519.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::fmt;
use core::ops::{Deref, DerefMut};
use std::convert::TryFrom;

use super::common::*;
#[cfg(feature = "blind-keys")]
Expand Down Expand Up @@ -141,6 +142,14 @@ impl fmt::Debug for Signature {
}
}

impl TryFrom<&[u8]> for Signature {
type Error = Error;

fn try_from(slice: &[u8]) -> Result<Self, Self::Error> {
Signature::from_slice(slice)
}
}

impl AsRef<[u8]> for Signature {
fn as_ref(&self) -> &[u8] {
&self.0
Expand Down Expand Up @@ -527,12 +536,8 @@ mod ed25519_trait {

use super::{PublicKey, SecretKey, Signature};

impl ed25519_trait::Signature for Signature {
fn from_bytes(bytes: &[u8]) -> Result<Self, ed25519_trait::Error> {
let mut bytes_ = [0u8; Signature::BYTES];
bytes_.copy_from_slice(bytes);
Ok(Signature::new(bytes_))
}
impl ed25519_trait::SignatureEncoding for Signature {
type Repr = Signature;
}

impl ed25519_trait::Signer<Signature> for SecretKey {
Expand All @@ -550,7 +555,7 @@ mod ed25519_trait {
#[cfg(feature = "std")]
{
self.verify(message, signature)
.map_err(|e| ed25519_trait::Error::from_source(e))
.map_err(ed25519_trait::Error::from_source)
}

#[cfg(not(feature = "std"))]
Expand Down

0 comments on commit 2cb1c6b

Please sign in to comment.