Skip to content

Commit

Permalink
Fix up ed25519_compact signature change (#70)
Browse files Browse the repository at this point in the history
* Fix up to recommended signature use

* clean up some new clippy warnings
  • Loading branch information
madninja authored Mar 26, 2024
1 parent 79d1f90 commit 55a3ec4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/ecc_compact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use p256::{
elliptic_curve::{ecdh, sec1::ToCompactEncodedPoint, DecompactPoint},
FieldBytes,
};
use std::{
convert::TryFrom,
hash::{Hash, Hasher},
ops::Deref,
};
use std::{hash::Hasher, ops::Deref};

#[derive(Debug, Clone)]
pub struct PublicKey(pub(crate) p256::PublicKey);
Expand Down
20 changes: 9 additions & 11 deletions src/ed25519/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::*;
use std::{
convert::TryFrom,
hash::{Hash, Hasher},
};
use std::hash::Hasher;

#[derive(Debug, Clone)]
pub struct PublicKey(pub(crate) ed25519_compact::PublicKey);
Expand Down Expand Up @@ -100,9 +97,10 @@ impl Keypair {

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

fn as_bytes(&self) -> &[u8] {
Expand Down Expand Up @@ -140,8 +138,7 @@ impl signature::Signer<Signature> for Keypair {

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

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

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

Expand Down
1 change: 0 additions & 1 deletion src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! since a client will need to be able to parse and use a public key from any
//! keypair.
use crate::*;
use std::{convert::TryFrom, hash::Hash};

///Verify a given message against a given signature slice. Public keys are
///expected to implemt this trait to verify signed messages.
Expand Down
5 changes: 1 addition & 4 deletions src/secp256k1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::*;
use base64::{engine::general_purpose::STANDARD, Engine};
use k256::{ecdsa, elliptic_curve::sec1::ToEncodedPoint};
use std::{
convert::TryFrom,
hash::{Hash, Hasher},
};
use std::hash::Hasher;
use thiserror::Error;

#[derive(Debug, Clone)]
Expand Down

0 comments on commit 55a3ec4

Please sign in to comment.