Skip to content

Commit 55a3ec4

Browse files
authored
Fix up ed25519_compact signature change (#70)
* Fix up to recommended signature use * clean up some new clippy warnings
1 parent 79d1f90 commit 55a3ec4

4 files changed

Lines changed: 11 additions & 21 deletions

File tree

src/ecc_compact/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ use p256::{
44
elliptic_curve::{ecdh, sec1::ToCompactEncodedPoint, DecompactPoint},
55
FieldBytes,
66
};
7-
use std::{
8-
convert::TryFrom,
9-
hash::{Hash, Hasher},
10-
ops::Deref,
11-
};
7+
use std::{hash::Hasher, ops::Deref};
128

139
#[derive(Debug, Clone)]
1410
pub struct PublicKey(pub(crate) p256::PublicKey);

src/ed25519/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use crate::*;
2-
use std::{
3-
convert::TryFrom,
4-
hash::{Hash, Hasher},
5-
};
2+
use std::hash::Hasher;
63

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

10198
impl signature::Signature for Signature {
10299
fn from_bytes(input: &[u8]) -> std::result::Result<Self, signature::Error> {
103-
let signature =
104-
ed25519_compact::Signature::try_from(input).map_err(signature::Error::from_source)?;
105-
Ok(Signature(signature))
100+
Ok(Signature(
101+
ed25519_compact::Signature::from_slice(input)
102+
.map_err(|_| signature::Error::default())?,
103+
))
106104
}
107105

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

141139
impl Signature {
142140
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
143-
let signature = ed25519_compact::Signature::try_from(bytes)?;
144-
Ok(Signature(signature))
141+
Ok(Signature(ed25519_compact::Signature::from_slice(bytes)?))
145142
}
146143

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

155152
fn try_from(input: &[u8]) -> Result<Self> {
156-
let signature = ed25519_compact::Signature::try_from(input)?;
157-
Ok(Signature(signature))
153+
ed25519_compact::Signature::from_slice(input)
154+
.map(Signature)
155+
.map_err(Error::from)
158156
}
159157
}
160158

src/public_key.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! since a client will need to be able to parse and use a public key from any
44
//! keypair.
55
use crate::*;
6-
use std::{convert::TryFrom, hash::Hash};
76

87
///Verify a given message against a given signature slice. Public keys are
98
///expected to implemt this trait to verify signed messages.

src/secp256k1/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use crate::*;
22
use base64::{engine::general_purpose::STANDARD, Engine};
33
use k256::{ecdsa, elliptic_curve::sec1::ToEncodedPoint};
4-
use std::{
5-
convert::TryFrom,
6-
hash::{Hash, Hasher},
7-
};
4+
use std::hash::Hasher;
85
use thiserror::Error;
96

107
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)