Skip to content

Commit

Permalink
elliptic-curve: impl From<SecretBytes> for FieldBytes
Browse files Browse the repository at this point in the history
This is needed to fulfill the trait bounds for `SecretValue`
  • Loading branch information
tarcieri committed Oct 8, 2020
1 parent 83f2e51 commit 33603e6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion elliptic-curve/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@ use rand_core::{CryptoRng, RngCore};

/// Inner value stored by a [`SecretKey`].
pub trait SecretValue: Curve {
/// Inner secret value
/// Inner secret value.
///
/// ⚠️ WARNING ⚠️
///
/// This type is not intended to be part of the public API and in future
/// versions of this crate we will try to explore ways to hide it.
///
/// Crates such as `k256` and `p256` conditionally define this type
/// differently depending on what cargo features are enabled.
/// This means any consumers of this crate attempting to use this type
/// may experience breakages if the cargo features are not what are
/// expected.
///
/// We regret exposing it as part of the public API for now, however if
/// you do reference this type as a downstream consumer of a curve crate,
/// be aware you will experience breakages!
type Secret: Into<FieldBytes<Self>> + Zeroize;

/// Parse the secret value from bytes
Expand Down Expand Up @@ -161,6 +176,12 @@ impl<C: Curve> From<FieldBytes<C>> for SecretBytes<C> {
}
}

impl<C: Curve> From<SecretBytes<C>> for FieldBytes<C> {
fn from(bytes: SecretBytes<C>) -> FieldBytes<C> {
bytes.0
}
}

impl<C: Curve> AsRef<[u8]> for SecretBytes<C> {
fn as_ref(&self) -> &[u8] {
&self.0
Expand Down

0 comments on commit 33603e6

Please sign in to comment.