Skip to content

Commit

Permalink
test: allow to sign and verify secp256k1
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Aug 12, 2022
1 parent 2ae6448 commit ea00176
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ zeroize = "1.5.5"
[dev-dependencies]
assert_matches = "1.5.0"
byte-unit = "4.0.13"
libsecp256k1 = {git = "https://github.com/brentstone/libsecp256k1", rev = "bbb3bd44a49db361f21d9db80f9a087c194c0ae9"}
pretty_assertions = "0.7.2"
# A fork with state machine testing
proptest = {git = "https://github.com/heliaxdev/proptest", branch = "tomas/sm"}
Expand Down
12 changes: 6 additions & 6 deletions shared/src/types/key/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,14 @@ impl super::SigScheme for SigScheme {

/// Sign the data with a key
fn sign(keypair: &SecretKey, data: impl AsRef<[u8]>) -> Self::Signature {
#[cfg(not(features = "secp256k1-sign-verify"))]
#[cfg(not(any(test, features = "secp256k1-sign-verify")))]
{
// to avoid `unused-variables` warn
let _ = (keypair, data);
panic!("\"secp256k1-sign-verify\" feature must be enabled");
}

#[cfg(features = "secp256k1-sign-verify")]
#[cfg(any(test, features = "secp256k1-sign-verify"))]
{
use sha2::{Digest, Sha256};
let hash = Sha256::digest(data.as_ref());
Expand All @@ -443,14 +443,14 @@ impl super::SigScheme for SigScheme {
data: &T,
sig: &Self::Signature,
) -> Result<(), VerifySigError> {
#[cfg(not(features = "secp256k1-sign-verify"))]
#[cfg(not(any(test, features = "secp256k1-sign-verify")))]
{
// to avoid `unused-variables` warn
let _ = (pk, data, sig);
panic!("\"secp256k1-sign-verify\" feature must be enabled");
}

#[cfg(features = "secp256k1-sign-verify")]
#[cfg(any(test, features = "secp256k1-sign-verify"))]
{
use sha2::{Digest, Sha256};
let bytes = &data
Expand All @@ -476,14 +476,14 @@ impl super::SigScheme for SigScheme {
data: &[u8],
sig: &Self::Signature,
) -> Result<(), VerifySigError> {
#[cfg(not(features = "secp256k1-sign-verify"))]
#[cfg(not(any(test, features = "secp256k1-sign-verify")))]
{
// to avoid `unused-variables` warn
let _ = (pk, data, sig);
panic!("\"secp256k1-sign-verify\" feature must be enabled");
}

#[cfg(features = "secp256k1-sign-verify")]
#[cfg(any(test, features = "secp256k1-sign-verify"))]
{
use sha2::{Digest, Sha256};
let hash = Sha256::digest(data);
Expand Down

0 comments on commit ea00176

Please sign in to comment.