Skip to content

Commit

Permalink
Fix warnings and add -D warnings check in CI
Browse files Browse the repository at this point in the history
- Eliminates dead code left over from #205
- Adds `-D warnings` in CI so that warnings are treated as errors.
  This ensures code must be warning-free to pass CI.
  • Loading branch information
tarcieri committed Nov 20, 2022
1 parent f7cbeee commit 1789f19
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 108 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: '-D warnings'

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ std = ["curve25519-dalek/std", "ed25519/std", "serde_crate/std", "sha2/std", "ra
alloc = ["curve25519-dalek/alloc", "rand/alloc", "zeroize/alloc"]
nightly = ["curve25519-dalek/nightly"]
serde = ["serde_crate", "serde_bytes", "ed25519/serde"]
batch = ["merlin", "rand"]
batch = ["merlin", "rand/std"]
# This feature enables deterministic batch verification.
batch_deterministic = ["merlin", "rand", "rand_core"]
asm = ["sha2/asm"]
Expand Down
2 changes: 2 additions & 0 deletions benches/ed25519_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ mod ed25519_benches {
fn verify_batch_signatures(c: &mut Criterion) {
static BATCH_SIZES: [usize; 8] = [4, 8, 16, 32, 64, 96, 128, 256];

// TODO: use BenchmarkGroups instead.
#[allow(deprecated)]
c.bench_function_over_inputs(
"Ed25519 batch signature verification",
|b, &&size| {
Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub(crate) enum InternalError {
VerifyError,
/// Two arrays did not match in size, making the called signature
/// verification method impossible.
#[cfg(any(feature = "batch", feature = "batch_deterministic"))]
ArrayLengthError{ name_a: &'static str, length_a: usize,
name_b: &'static str, length_b: usize,
name_c: &'static str, length_c: usize, },
Expand All @@ -58,6 +59,7 @@ impl Display for InternalError {
=> write!(f, "{} must be {} bytes in length", n, l),
InternalError::VerifyError
=> write!(f, "Verification equation was not satisfied"),
#[cfg(any(feature = "batch", feature = "batch_deterministic"))]
InternalError::ArrayLengthError{ name_a: na, length_a: la,
name_b: nb, length_b: lb,
name_c: nc, length_c: lc, }
Expand Down
103 changes: 0 additions & 103 deletions src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,109 +292,6 @@ impl<'a> From<&'a SecretKey> for ExpandedSecretKey {
}

impl ExpandedSecretKey {
/// Convert this `ExpandedSecretKey` into an array of 64 bytes.
///
/// # Returns
///
/// An array of 64 bytes. The first 32 bytes represent the "expanded"
/// secret key, and the last 32 bytes represent the "domain-separation"
/// "nonce".
///
/// # Examples
///
/// ```ignore
/// # extern crate rand;
/// # extern crate sha2;
/// # extern crate ed25519_dalek;
/// #
/// # #[cfg(feature = "std")]
/// # fn main() {
/// #
/// use rand::rngs::OsRng;
/// use ed25519_dalek::{SecretKey, ExpandedSecretKey};
///
/// let mut csprng = OsRng{};
/// let secret_key: SecretKey = SecretKey::generate(&mut csprng);
/// let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
/// let expanded_secret_key_bytes: [u8; 64] = expanded_secret_key.to_bytes();
///
/// assert!(&expanded_secret_key_bytes[..] != &[0u8; 64][..]);
/// # }
/// #
/// # #[cfg(not(feature = "std"))]
/// # fn main() { }
/// ```
#[inline]
pub fn to_bytes(&self) -> [u8; EXPANDED_SECRET_KEY_LENGTH] {
let mut bytes: [u8; 64] = [0u8; 64];

bytes[..32].copy_from_slice(self.key.as_bytes());
bytes[32..].copy_from_slice(&self.nonce[..]);
bytes
}

/// Construct an `ExpandedSecretKey` from a slice of bytes.
///
/// # Returns
///
/// A `Result` whose okay value is an EdDSA `ExpandedSecretKey` or whose
/// error value is an `SignatureError` describing the error that occurred.
///
/// # Examples
///
/// ```ignore
/// # extern crate rand;
/// # extern crate sha2;
/// # extern crate ed25519_dalek;
/// #
/// # use ed25519_dalek::{ExpandedSecretKey, SignatureError};
/// #
/// # #[cfg(feature = "std")]
/// # fn do_test() -> Result<ExpandedSecretKey, SignatureError> {
/// #
/// use rand::rngs::OsRng;
/// use ed25519_dalek::{SecretKey, ExpandedSecretKey};
/// use ed25519_dalek::SignatureError;
///
/// let mut csprng = OsRng{};
/// let secret_key: SecretKey = SecretKey::generate(&mut csprng);
/// let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
/// let bytes: [u8; 64] = expanded_secret_key.to_bytes();
/// let expanded_secret_key_again = ExpandedSecretKey::from_bytes(&bytes)?;
/// #
/// # Ok(expanded_secret_key_again)
/// # }
/// #
/// # #[cfg(feature = "std")]
/// # fn main() {
/// # let result = do_test();
/// # assert!(result.is_ok());
/// # }
/// #
/// # #[cfg(not(feature = "std"))]
/// # fn main() { }
/// ```
#[inline]
pub(crate) fn from_bytes(bytes: &[u8]) -> Result<ExpandedSecretKey, SignatureError> {
if bytes.len() != EXPANDED_SECRET_KEY_LENGTH {
return Err(InternalError::BytesLengthError {
name: "ExpandedSecretKey",
length: EXPANDED_SECRET_KEY_LENGTH,
}
.into());
}
let mut lower: [u8; 32] = [0u8; 32];
let mut upper: [u8; 32] = [0u8; 32];

lower.copy_from_slice(&bytes[00..32]);
upper.copy_from_slice(&bytes[32..64]);

Ok(ExpandedSecretKey {
key: Scalar::from_bits(lower),
nonce: upper,
})
}

/// Sign a message with this `ExpandedSecretKey`.
#[allow(non_snake_case)]
pub(crate) fn sign(&self, message: &[u8], public_key: &PublicKey) -> ed25519::Signature {
Expand Down
6 changes: 2 additions & 4 deletions tests/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,17 @@ mod integrations {
signatures.push(keypair.sign(&messages[i]));
keypairs.push(keypair);
}
let public_keys: Vec<PublicKey> = keypairs.iter().map(|key| key.public).collect();
let public_keys: Vec<PublicKey> = keypairs.iter().map(|key| key.public_key()).collect();

let result = verify_batch(&messages, &signatures[..], &public_keys[..]);

assert!(result.is_ok());
}
}

#[serde(crate = "serde_crate")]
#[cfg(all(test, feature = "serde"))]
#[derive(Debug, serde_crate::Serialize, serde_crate::Deserialize)]
#[serde(crate = "serde_crate")]
struct Demo {
keypair: Keypair
}
Expand All @@ -296,8 +296,6 @@ struct Demo {
mod serialisation {
use super::*;

use ed25519::signature::Signature as _;

// The size for bincode to serialize the length of a byte array.
static BINCODE_INT_LENGTH: usize = 8;

Expand Down

0 comments on commit 1789f19

Please sign in to comment.