From c925644b74b69fe81523e43950bf980ac8b032ed Mon Sep 17 00:00:00 2001 From: Jules Comte Date: Thu, 20 May 2021 07:18:42 -0600 Subject: [PATCH] Touch recovery module in no_std_test --- no_std_test/Cargo.toml | 2 +- no_std_test/src/main.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/no_std_test/Cargo.toml b/no_std_test/Cargo.toml index f68a47c..9ab53af 100644 --- a/no_std_test/Cargo.toml +++ b/no_std_test/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Elichai Turkel "] [dependencies] -secp256k1 = { path = "../", default-features = false, features = ["serde", "rand"] } +secp256k1 = { path = "../", default-features = false, features = ["serde", "rand", "recovery"] } libc = { version = "0.2", default-features = false } serde_cbor = { version = "0.10", default-features = false } # A random serializer that supports no-std. diff --git a/no_std_test/src/main.rs b/no_std_test/src/main.rs index 0c49d06..9586aed 100644 --- a/no_std_test/src/main.rs +++ b/no_std_test/src/main.rs @@ -15,7 +15,7 @@ //! # secp256k1 no-std test. //! This binary is a short smallest rust code to produce a working binary *without libstd*. //! This gives us 2 things: -//! 1. Test that the parts of the code that should work in a no-std enviroment actually work. +//! 1. Test that the parts of the code that should work in a no-std enviroment actually work. Note that this is not a comprehensive list. //! 2. Test that we don't accidentally import libstd into `secp256k1`. //! //! The first is tested using the following command `cargo run --release | grep -q "Verified Successfully"`. @@ -96,6 +96,13 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize { let sig = secp.sign(&message, &secret_key); assert!(secp.verify(&message, &sig, &public_key).is_ok()); + let rec_sig = secp.sign_recoverable(&message, &secret_key); + assert!(secp.verify(&message, &rec_sig.to_standard(), &public_key).is_ok()); + assert_eq!(public_key, secp.recover(&message, &rec_sig).unwrap()); + let (rec_id, data) = rec_sig.serialize_compact(); + let new_rec_sig = recovery::RecoverableSignature::from_compact(&data, rec_id).unwrap(); + assert_eq!(rec_sig, new_rec_sig); + let mut cbor_ser = [0u8; 100]; let writer = SliceWrite::new(&mut cbor_ser[..]); let mut ser = Serializer::new(writer);