mirror of
https://github.com/dalek-cryptography/ed25519-dalek.git
synced 2026-01-09 19:18:00 -05:00
Fix warnings and add -D warnings check in CI (#226)
This commit is contained in:
1
.github/workflows/rust.yml
vendored
1
.github/workflows/rust.yml
vendored
@@ -8,6 +8,7 @@ on:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RUSTFLAGS: '-D warnings'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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| {
|
||||
|
||||
@@ -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, },
|
||||
@@ -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, }
|
||||
|
||||
103
src/secret.rs
103
src/secret.rs
@@ -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 {
|
||||
|
||||
@@ -277,7 +277,7 @@ 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[..]);
|
||||
|
||||
@@ -285,9 +285,9 @@ mod integrations {
|
||||
}
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user