Replace secp256k1 crate with libsecp256k1. (#1029)

* Replace `secp256k1` crate with `libsecp256k1`.

Unfortunately we could not implement `AsRef<[u8]>` for `SecretKey`
as the crate does not provide a means to do so.

* Fix `DecodingError` invocation.

* Remove the cc for wasm

* Revert "Remove the cc for wasm"

This reverts commit 3a19db35e62931c6e9ffbff6c21f9b0d7ae5403a.

* Fix CircleCI build
This commit is contained in:
Toralf Wittner
2019-05-14 19:33:30 +02:00
committed by Pierre Krieger
parent 43d9084735
commit 057b379541
8 changed files with 60 additions and 64 deletions

View File

@ -41,7 +41,7 @@ impl Keypair {
/// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5
pub fn from_pkcs8(der: &mut [u8]) -> Result<Keypair, DecodingError> {
let kp = RsaKeyPair::from_pkcs8(Input::from(&der[..]))
.map_err(|e| DecodingError::new("RSA PKCS#8 PrivateKeyInfo", e))?;
.map_err(|e| DecodingError::new("RSA PKCS#8 PrivateKeyInfo").source(e))?;
der.zeroize();
Ok(Keypair(Arc::new(kp)))
}
@ -57,7 +57,7 @@ impl Keypair {
let rng = SystemRandom::new();
match self.0.sign(&RSA_PKCS1_SHA256, &rng, &data, &mut signature) {
Ok(()) => Ok(signature),
Err(e) => Err(SigningError::new("RSA", e))
Err(e) => Err(SigningError::new("RSA").source(e))
}
}
}
@ -105,7 +105,7 @@ impl PublicKey {
/// structure. See also `encode_x509`.
pub fn decode_x509(pk: &[u8]) -> Result<PublicKey, DecodingError> {
Asn1SubjectPublicKeyInfo::deserialize(pk.iter())
.map_err(|e| DecodingError::new("RSA X.509", e))
.map_err(|e| DecodingError::new("RSA X.509").source(e))
.map(|spki| spki.subjectPublicKey.0)
}
}