Skip to content

Commit ae4bd2c

Browse files
authored
Fix warnings and add -D warnings check in CI (#226)
1 parent f7cbeee commit ae4bd2c

File tree

6 files changed

+8
-108
lines changed

6 files changed

+8
-108
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11+
RUSTFLAGS: '-D warnings'
1112

1213
jobs:
1314
test:

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ std = ["curve25519-dalek/std", "ed25519/std", "serde_crate/std", "sha2/std", "ra
5454
alloc = ["curve25519-dalek/alloc", "rand/alloc", "zeroize/alloc"]
5555
nightly = ["curve25519-dalek/nightly"]
5656
serde = ["serde_crate", "serde_bytes", "ed25519/serde"]
57-
batch = ["merlin", "rand"]
57+
batch = ["merlin", "rand/std"]
5858
# This feature enables deterministic batch verification.
5959
batch_deterministic = ["merlin", "rand", "rand_core"]
6060
asm = ["sha2/asm"]

benches/ed25519_benchmarks.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ mod ed25519_benches {
5757
fn verify_batch_signatures(c: &mut Criterion) {
5858
static BATCH_SIZES: [usize; 8] = [4, 8, 16, 32, 64, 96, 128, 256];
5959

60+
// TODO: use BenchmarkGroups instead.
61+
#[allow(deprecated)]
6062
c.bench_function_over_inputs(
6163
"Ed25519 batch signature verification",
6264
|b, &&size| {

src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub(crate) enum InternalError {
3838
VerifyError,
3939
/// Two arrays did not match in size, making the called signature
4040
/// verification method impossible.
41+
#[cfg(any(feature = "batch", feature = "batch_deterministic"))]
4142
ArrayLengthError{ name_a: &'static str, length_a: usize,
4243
name_b: &'static str, length_b: usize,
4344
name_c: &'static str, length_c: usize, },
@@ -58,6 +59,7 @@ impl Display for InternalError {
5859
=> write!(f, "{} must be {} bytes in length", n, l),
5960
InternalError::VerifyError
6061
=> write!(f, "Verification equation was not satisfied"),
62+
#[cfg(any(feature = "batch", feature = "batch_deterministic"))]
6163
InternalError::ArrayLengthError{ name_a: na, length_a: la,
6264
name_b: nb, length_b: lb,
6365
name_c: nc, length_c: lc, }

src/secret.rs

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -292,109 +292,6 @@ impl<'a> From<&'a SecretKey> for ExpandedSecretKey {
292292
}
293293

294294
impl ExpandedSecretKey {
295-
/// Convert this `ExpandedSecretKey` into an array of 64 bytes.
296-
///
297-
/// # Returns
298-
///
299-
/// An array of 64 bytes. The first 32 bytes represent the "expanded"
300-
/// secret key, and the last 32 bytes represent the "domain-separation"
301-
/// "nonce".
302-
///
303-
/// # Examples
304-
///
305-
/// ```ignore
306-
/// # extern crate rand;
307-
/// # extern crate sha2;
308-
/// # extern crate ed25519_dalek;
309-
/// #
310-
/// # #[cfg(feature = "std")]
311-
/// # fn main() {
312-
/// #
313-
/// use rand::rngs::OsRng;
314-
/// use ed25519_dalek::{SecretKey, ExpandedSecretKey};
315-
///
316-
/// let mut csprng = OsRng{};
317-
/// let secret_key: SecretKey = SecretKey::generate(&mut csprng);
318-
/// let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
319-
/// let expanded_secret_key_bytes: [u8; 64] = expanded_secret_key.to_bytes();
320-
///
321-
/// assert!(&expanded_secret_key_bytes[..] != &[0u8; 64][..]);
322-
/// # }
323-
/// #
324-
/// # #[cfg(not(feature = "std"))]
325-
/// # fn main() { }
326-
/// ```
327-
#[inline]
328-
pub fn to_bytes(&self) -> [u8; EXPANDED_SECRET_KEY_LENGTH] {
329-
let mut bytes: [u8; 64] = [0u8; 64];
330-
331-
bytes[..32].copy_from_slice(self.key.as_bytes());
332-
bytes[32..].copy_from_slice(&self.nonce[..]);
333-
bytes
334-
}
335-
336-
/// Construct an `ExpandedSecretKey` from a slice of bytes.
337-
///
338-
/// # Returns
339-
///
340-
/// A `Result` whose okay value is an EdDSA `ExpandedSecretKey` or whose
341-
/// error value is an `SignatureError` describing the error that occurred.
342-
///
343-
/// # Examples
344-
///
345-
/// ```ignore
346-
/// # extern crate rand;
347-
/// # extern crate sha2;
348-
/// # extern crate ed25519_dalek;
349-
/// #
350-
/// # use ed25519_dalek::{ExpandedSecretKey, SignatureError};
351-
/// #
352-
/// # #[cfg(feature = "std")]
353-
/// # fn do_test() -> Result<ExpandedSecretKey, SignatureError> {
354-
/// #
355-
/// use rand::rngs::OsRng;
356-
/// use ed25519_dalek::{SecretKey, ExpandedSecretKey};
357-
/// use ed25519_dalek::SignatureError;
358-
///
359-
/// let mut csprng = OsRng{};
360-
/// let secret_key: SecretKey = SecretKey::generate(&mut csprng);
361-
/// let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
362-
/// let bytes: [u8; 64] = expanded_secret_key.to_bytes();
363-
/// let expanded_secret_key_again = ExpandedSecretKey::from_bytes(&bytes)?;
364-
/// #
365-
/// # Ok(expanded_secret_key_again)
366-
/// # }
367-
/// #
368-
/// # #[cfg(feature = "std")]
369-
/// # fn main() {
370-
/// # let result = do_test();
371-
/// # assert!(result.is_ok());
372-
/// # }
373-
/// #
374-
/// # #[cfg(not(feature = "std"))]
375-
/// # fn main() { }
376-
/// ```
377-
#[inline]
378-
pub(crate) fn from_bytes(bytes: &[u8]) -> Result<ExpandedSecretKey, SignatureError> {
379-
if bytes.len() != EXPANDED_SECRET_KEY_LENGTH {
380-
return Err(InternalError::BytesLengthError {
381-
name: "ExpandedSecretKey",
382-
length: EXPANDED_SECRET_KEY_LENGTH,
383-
}
384-
.into());
385-
}
386-
let mut lower: [u8; 32] = [0u8; 32];
387-
let mut upper: [u8; 32] = [0u8; 32];
388-
389-
lower.copy_from_slice(&bytes[00..32]);
390-
upper.copy_from_slice(&bytes[32..64]);
391-
392-
Ok(ExpandedSecretKey {
393-
key: Scalar::from_bits(lower),
394-
nonce: upper,
395-
})
396-
}
397-
398295
/// Sign a message with this `ExpandedSecretKey`.
399296
#[allow(non_snake_case)]
400297
pub(crate) fn sign(&self, message: &[u8], public_key: &PublicKey) -> ed25519::Signature {

tests/ed25519.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,17 @@ mod integrations {
277277
signatures.push(keypair.sign(&messages[i]));
278278
keypairs.push(keypair);
279279
}
280-
let public_keys: Vec<PublicKey> = keypairs.iter().map(|key| key.public).collect();
280+
let public_keys: Vec<PublicKey> = keypairs.iter().map(|key| key.public_key()).collect();
281281

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

284284
assert!(result.is_ok());
285285
}
286286
}
287287

288-
#[serde(crate = "serde_crate")]
289288
#[cfg(all(test, feature = "serde"))]
290289
#[derive(Debug, serde_crate::Serialize, serde_crate::Deserialize)]
290+
#[serde(crate = "serde_crate")]
291291
struct Demo {
292292
keypair: Keypair
293293
}
@@ -296,8 +296,6 @@ struct Demo {
296296
mod serialisation {
297297
use super::*;
298298

299-
use ed25519::signature::Signature as _;
300-
301299
// The size for bincode to serialize the length of a byte array.
302300
static BINCODE_INT_LENGTH: usize = 8;
303301

0 commit comments

Comments
 (0)