From 60157153d6748a36b64e7f0bc29b2fd09b866052 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Thu, 3 Sep 2020 14:41:07 -0700 Subject: [PATCH] ecdsa: use impl Into bounds on Signature::from_scalars --- ecdsa/src/lib.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ecdsa/src/lib.rs b/ecdsa/src/lib.rs index 066b171a..b905d55e 100644 --- a/ecdsa/src/lib.rs +++ b/ecdsa/src/lib.rs @@ -67,7 +67,7 @@ use core::{ ops::Add, }; use elliptic_curve::{Arithmetic, ElementBytes, FromBytes}; -use generic_array::{typenum::Unsigned, ArrayLength, GenericArray}; +use generic_array::{sequence::Concat, typenum::Unsigned, ArrayLength, GenericArray}; /// Size of a fixed sized signature for the given elliptic curve. pub type SignatureSize = <::FieldSize as Add>::Output; @@ -103,13 +103,12 @@ impl Signature where SignatureSize: ArrayLength, { - /// Create a [`Signature`] from the serialized `r` and `s` components - pub fn from_scalars(r: &ElementBytes, s: &ElementBytes) -> Self { - let mut bytes = SignatureBytes::::default(); - let scalar_size = C::FieldSize::to_usize(); - bytes[..scalar_size].copy_from_slice(r.as_slice()); - bytes[scalar_size..].copy_from_slice(s.as_slice()); - Signature { bytes } + /// Create a [`Signature`] from the serialized `r` and `s` scalar values + /// which comprise the signature. + pub fn from_scalars(r: impl Into>, s: impl Into>) -> Self { + Signature { + bytes: r.into().concat(s.into()), + } } /// Parse a signature from ASN.1 DER