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 6665342
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 116 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
10 changes: 0 additions & 10 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ pub(crate) enum InternalError {
},
/// The verification equation wasn't satisfied
VerifyError,
/// Two arrays did not match in size, making the called signature
/// verification method impossible.
ArrayLengthError{ name_a: &'static str, length_a: usize,
name_b: &'static str, length_b: usize,
name_c: &'static str, length_c: usize, },
/// An ed25519ph signature can only take up to 255 octets of context.
PrehashedContextLengthError,
/// A mismatched (public, secret) key pair.
Expand All @@ -58,11 +53,6 @@ impl Display for InternalError {
=> write!(f, "{} must be {} bytes in length", n, l),
InternalError::VerifyError
=> write!(f, "Verification equation was not satisfied"),
InternalError::ArrayLengthError{ name_a: na, length_a: la,
name_b: nb, length_b: lb,
name_c: nc, length_c: lc, }
=> write!(f, "Arrays must be the same length: {} has length {},
{} has length {}, {} has length {}.", na, la, nb, lb, nc, lc),
InternalError::PrehashedContextLengthError
=> write!(f, "An ed25519ph signature can only take up to 255 octets of context"),
InternalError::MismatchedKeypairError => write!(f, "Mismatched Keypair detected"),
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
4 changes: 1 addition & 3 deletions tests/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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 6665342

Please sign in to comment.