diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2021-01-19 08:53:04 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2021-01-19 08:53:04 +0100 |
| commit | ab4c2dcfba4c774c802846d24c6a8443176e8cda (patch) | |
| tree | 8ab9a48214cd190f54b88db17eb46c26770eef16 /src | |
| parent | 7e0f711245633967256ed5ca09bae295dd647b50 (diff) | |
fix clippy lint
Diffstat (limited to 'src')
| -rw-r--r-- | src/account.rs | 17 | ||||
| -rw-r--r-- | src/account/signature.rs | 2 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/account.rs b/src/account.rs index cbe0148..a518753 100644 --- a/src/account.rs +++ b/src/account.rs @@ -10,7 +10,10 @@ use secp256k1::{ key::{PublicKey, SecretKey, ONE_KEY}, Message, Secp256k1, }; -use std::fmt::{self, Debug, Formatter}; +use std::{ + convert::TryInto, + fmt::{self, Debug, Formatter}, +}; /// A struct representing an Ethereum private key. pub struct PrivateKey(SecretKey); @@ -50,13 +53,13 @@ impl PrivateKey { .sign_recoverable(&message, &self.0) .serialize_compact(); debug_assert!(matches!(recovery_id.to_i32(), 0 | 1)); + debug_assert_eq!(raw_signature.len(), 64); - let mut signature = Signature::default(); - signature.v = 27 + (recovery_id.to_i32() as u8); - signature.r.copy_from_slice(&raw_signature[..32]); - signature.s.copy_from_slice(&raw_signature[32..]); - - signature + Signature { + v: 27 + (recovery_id.to_i32() as u8), + r: raw_signature[..32].try_into().unwrap(), + s: raw_signature[32..].try_into().unwrap(), + } } } diff --git a/src/account/signature.rs b/src/account/signature.rs index eef37da..fd3c53d 100644 --- a/src/account/signature.rs +++ b/src/account/signature.rs @@ -3,7 +3,7 @@ use std::fmt::{self, Display, Formatter}; /// A secp256k1 signature. -#[derive(Clone, Debug, Default, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct Signature { /// Signature V value in Electrum notation. pub v: u8, |
