Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up ed25519_compact signature change #70

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading