#[non_exhaustive]pub enum SecretKey {
System,
Ed25519(SigningKey),
Secp256k1(SigningKey),
}Expand description
A secret or private asymmetric key.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
System
System secret key.
Ed25519(SigningKey)
Ed25519 secret key.
Secp256k1(SigningKey)
secp256k1 secret key.
Implementations§
Source§impl SecretKey
impl SecretKey
Sourcepub const SYSTEM_LENGTH: usize = 0usize
pub const SYSTEM_LENGTH: usize = 0usize
The length in bytes of a system secret key.
Sourcepub const ED25519_LENGTH: usize = 32usize
pub const ED25519_LENGTH: usize = 32usize
The length in bytes of an Ed25519 secret key.
Sourcepub const SECP256K1_LENGTH: usize = 32usize
pub const SECP256K1_LENGTH: usize = 32usize
The length in bytes of a secp256k1 secret key.
Sourcepub fn ed25519_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, Error>
pub fn ed25519_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, Error>
Constructs a new ed25519 variant from a byte slice.
Sourcepub fn secp256k1_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, Error>
pub fn secp256k1_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, Error>
Constructs a new secp256k1 variant from a byte slice.
Sourcepub fn generate_ed25519() -> Result<Self, ErrorExt>
Available on crate features std or testing only.
pub fn generate_ed25519() -> Result<Self, ErrorExt>
std or testing only.Generates a new ed25519 variant using the system’s secure random number generator.
Sourcepub fn generate_secp256k1() -> Result<Self, ErrorExt>
Available on crate features std or testing only.
pub fn generate_secp256k1() -> Result<Self, ErrorExt>
std or testing only.Generates a new secp256k1 variant using the system’s secure random number generator.
Sourcepub fn to_file<P: AsRef<Path>>(&self, file: P) -> Result<(), ErrorExt>
Available on crate feature std-fs-io only.
pub fn to_file<P: AsRef<Path>>(&self, file: P) -> Result<(), ErrorExt>
std-fs-io only.Attempts to write the key bytes to the configured file path.
Sourcepub fn from_file<P: AsRef<Path>>(file: P) -> Result<Self, ErrorExt>
Available on crate feature std-fs-io only.
pub fn from_file<P: AsRef<Path>>(file: P) -> Result<Self, ErrorExt>
std-fs-io only.Attempts to read the key bytes from configured file path.
Sourcepub fn to_der(&self) -> Result<Vec<u8>, ErrorExt>
Available on crate feature std only.
pub fn to_der(&self) -> Result<Vec<u8>, ErrorExt>
std only.DER encodes a key.
Sourcepub fn from_der<T: AsRef<[u8]>>(input: T) -> Result<Self, ErrorExt>
Available on crate feature std only.
pub fn from_der<T: AsRef<[u8]>>(input: T) -> Result<Self, ErrorExt>
std only.Decodes a key from a DER-encoded slice.
Sourcepub fn to_pem(&self) -> Result<String, ErrorExt>
Available on crate feature std only.
pub fn to_pem(&self) -> Result<String, ErrorExt>
std only.PEM encodes a key.
Sourcepub fn from_pem<T: AsRef<[u8]>>(input: T) -> Result<Self, ErrorExt>
Available on crate feature std only.
pub fn from_pem<T: AsRef<[u8]>>(input: T) -> Result<Self, ErrorExt>
std only.Decodes a key from a PEM-encoded slice.
Sourcepub fn random(rng: &mut TestRng) -> Self
Available on crate feature testing only.
pub fn random(rng: &mut TestRng) -> Self
testing only.Returns a random SecretKey.
Sourcepub fn random_ed25519(rng: &mut TestRng) -> Self
Available on crate feature testing only.
pub fn random_ed25519(rng: &mut TestRng) -> Self
testing only.Returns a random Ed25519 variant of SecretKey.
Sourcepub fn random_secp256k1(rng: &mut TestRng) -> Self
Available on crate feature testing only.
pub fn random_secp256k1(rng: &mut TestRng) -> Self
testing only.Returns a random secp256k1 variant of SecretKey.
Trait Implementations§
Source§impl DataSize for SecretKey
impl DataSize for SecretKey
Source§const IS_DYNAMIC: bool = true
const IS_DYNAMIC: bool = true
true, the type has a heap size that can vary at runtime, depending on the actual value.Source§const STATIC_HEAP_SIZE: usize = 0usize
const STATIC_HEAP_SIZE: usize = 0usize
IS_DYNAMIC is false, this is
the total amount of heap memory occupied by the value. Otherwise this is a lower bound.Source§fn estimate_heap_size(&self) -> usize
fn estimate_heap_size(&self) -> usize
Source§impl Ord for SecretKey
Available on crate feature testing only.
impl Ord for SecretKey
testing only.Source§impl PartialOrd for SecretKey
Available on crate feature testing only.
impl PartialOrd for SecretKey
testing only.impl Eq for SecretKey
testing only.Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more