mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-06 20:41:14 +00:00
Merge pull request #243 from pinkforest/fix-signingkey-docs-coverage
Fix `SigningKey` from/to_bytes docs +coverage
This commit is contained in:
commit
c01cab0d19
1 changed files with 29 additions and 33 deletions
|
|
@ -58,40 +58,36 @@ pub struct SigningKey {
|
||||||
pub(crate) verifying_key: VerifyingKey,
|
pub(crate) verifying_key: VerifyingKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # extern crate ed25519_dalek;
|
||||||
|
/// #
|
||||||
|
/// use ed25519_dalek::SigningKey;
|
||||||
|
/// use ed25519_dalek::SECRET_KEY_LENGTH;
|
||||||
|
/// use ed25519_dalek::SignatureError;
|
||||||
|
///
|
||||||
|
/// # fn doctest() -> Result<SigningKey, SignatureError> {
|
||||||
|
/// let secret_key_bytes: [u8; SECRET_KEY_LENGTH] = [
|
||||||
|
/// 157, 097, 177, 157, 239, 253, 090, 096,
|
||||||
|
/// 186, 132, 074, 244, 146, 236, 044, 196,
|
||||||
|
/// 068, 073, 197, 105, 123, 050, 105, 025,
|
||||||
|
/// 112, 059, 172, 003, 028, 174, 127, 096, ];
|
||||||
|
///
|
||||||
|
/// let signing_key: SigningKey = SigningKey::from_bytes(&secret_key_bytes);
|
||||||
|
/// assert_eq!(signing_key.to_bytes(), secret_key_bytes);
|
||||||
|
///
|
||||||
|
/// # Ok(signing_key)
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # fn main() {
|
||||||
|
/// # let result = doctest();
|
||||||
|
/// # assert!(result.is_ok());
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
impl SigningKey {
|
impl SigningKey {
|
||||||
/// Construct a [`SigningKey`] from a slice of bytes.
|
/// Construct a [`SigningKey`] from a [`SecretKey`]
|
||||||
///
|
///
|
||||||
/// # Example
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// # extern crate ed25519_dalek;
|
|
||||||
/// #
|
|
||||||
/// use ed25519_dalek::SigningKey;
|
|
||||||
/// use ed25519_dalek::SECRET_KEY_LENGTH;
|
|
||||||
/// use ed25519_dalek::SignatureError;
|
|
||||||
///
|
|
||||||
/// # fn doctest() -> Result<SigningKey, SignatureError> {
|
|
||||||
/// let secret_key_bytes: [u8; SECRET_KEY_LENGTH] = [
|
|
||||||
/// 157, 097, 177, 157, 239, 253, 090, 096,
|
|
||||||
/// 186, 132, 074, 244, 146, 236, 044, 196,
|
|
||||||
/// 068, 073, 197, 105, 123, 050, 105, 025,
|
|
||||||
/// 112, 059, 172, 003, 028, 174, 127, 096, ];
|
|
||||||
///
|
|
||||||
/// let signing_key: SigningKey = SigningKey::from_bytes(&secret_key_bytes);
|
|
||||||
/// #
|
|
||||||
/// # Ok(signing_key)
|
|
||||||
/// # }
|
|
||||||
/// #
|
|
||||||
/// # fn main() {
|
|
||||||
/// # let result = doctest();
|
|
||||||
/// # assert!(result.is_ok());
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// A `Result` whose okay value is an EdDSA `SecretKey` or whose error value
|
|
||||||
/// is an `SignatureError` wrapping the internal error that occurred.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_bytes(secret_key: &SecretKey) -> Self {
|
pub fn from_bytes(secret_key: &SecretKey) -> Self {
|
||||||
let verifying_key = VerifyingKey::from(&ExpandedSecretKey::from(secret_key));
|
let verifying_key = VerifyingKey::from(&ExpandedSecretKey::from(secret_key));
|
||||||
|
|
@ -101,7 +97,7 @@ impl SigningKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this secret key to a byte array.
|
/// Convert this [`SigningKey`] into a [`SecretKey`]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_bytes(&self) -> SecretKey {
|
pub fn to_bytes(&self) -> SecretKey {
|
||||||
self.secret_key
|
self.secret_key
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue