Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elliptic-curve: impl From<SecretBytes> for FieldBytes #326

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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