|
20 | 20 |
|
21 | 21 | //! Secp256k1 keys. |
22 | 22 |
|
23 | | -use super::error::{DecodingError, SigningError}; |
| 23 | +use super::error::DecodingError; |
24 | 24 | use asn1_der::typed::{DerDecodable, Sequence}; |
25 | 25 | use core::cmp; |
26 | 26 | use core::fmt; |
@@ -142,25 +142,25 @@ impl SecretKey { |
142 | 142 | /// ECDSA signature, as defined in [RFC3278]. |
143 | 143 | /// |
144 | 144 | /// [RFC3278]: https://tools.ietf.org/html/rfc3278#section-8.2 |
145 | | - pub fn sign(&self, msg: &[u8]) -> Result<Vec<u8>, SigningError> { |
146 | | - self.sign_hash(Sha256::digest(msg).as_ref()) |
147 | | - } |
| 145 | + pub fn sign(&self, msg: &[u8]) -> Vec<u8> { |
| 146 | + let generic_array = Sha256::digest(msg); |
148 | 147 |
|
149 | | - /// Returns the raw bytes of the secret key. |
150 | | - pub fn to_bytes(&self) -> [u8; 32] { |
151 | | - self.0.serialize() |
152 | | - } |
| 148 | + // FIXME: Once `generic-array` hits 1.0, we should be able to just use `Into` here. |
| 149 | + let mut array = [0u8; 32]; |
| 150 | + array.copy_from_slice(generic_array.as_slice()); |
| 151 | + |
| 152 | + let message = Message::parse(&array); |
153 | 153 |
|
154 | | - /// Sign a raw message of length 256 bits with this secret key, produces a DER-encoded |
155 | | - /// ECDSA signature. |
156 | | - pub fn sign_hash(&self, msg: &[u8]) -> Result<Vec<u8>, SigningError> { |
157 | | - let m = Message::parse_slice(msg) |
158 | | - .map_err(|_| SigningError::new("failed to parse secp256k1 digest"))?; |
159 | | - Ok(libsecp256k1::sign(&m, &self.0) |
| 154 | + libsecp256k1::sign(&message, &self.0) |
160 | 155 | .0 |
161 | 156 | .serialize_der() |
162 | 157 | .as_ref() |
163 | | - .into()) |
| 158 | + .into() |
| 159 | + } |
| 160 | + |
| 161 | + /// Returns the raw bytes of the secret key. |
| 162 | + pub fn to_bytes(&self) -> [u8; 32] { |
| 163 | + self.0.serialize() |
164 | 164 | } |
165 | 165 | } |
166 | 166 |
|
|
0 commit comments