Struct fuel_crypto::SecretKey
source · [−]#[repr(transparent)]pub struct SecretKey(_);
Expand description
Asymmetric secret key
Implementations
sourceimpl SecretKey
impl SecretKey
sourcepub unsafe fn is_slice_in_field_unchecked(slice: &[u8]) -> bool
pub unsafe fn is_slice_in_field_unchecked(slice: &[u8]) -> bool
Check if the provided slice represents a scalar that fits the field.
Safety
This function extends the unsafety of
SecretKey::as_ref_unchecked
.
sourcepub fn is_in_field(&self) -> bool
pub fn is_in_field(&self) -> bool
Check if the secret key representation fits the scalar field.
sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Return the curve representation of this secret.
The discrete logarithm property guarantees this is a one-way function.
sourceimpl SecretKey
impl SecretKey
sourcepub unsafe fn from_bytes_unchecked(bytes: [u8; 32]) -> Self
pub unsafe fn from_bytes_unchecked(bytes: [u8; 32]) -> Self
Add a conversion from arbitrary slices into owned
Safety
There is no guarantee the provided bytes will fit the field. The field
security can be checked with SecretKey::is_in_field
.
sourcepub unsafe fn from_slice_unchecked(bytes: &[u8]) -> Self
pub unsafe fn from_slice_unchecked(bytes: &[u8]) -> Self
Add a conversion from arbitrary slices into owned
Safety
This function will not panic if the length of the slice is smaller than
Self::LEN
. Instead, it will cause undefined behavior and read random
disowned bytes.
There is no guarantee the provided bytes will fit the field.
Methods from Deref<Target = [u8; 32]>
1.57.0 · sourcepub fn as_slice(&self) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn as_slice(&self) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Returns a slice containing the entire array. Equivalent to &s[..]
.
sourcepub fn each_ref(&self) -> [&T; N]
🔬 This is a nightly-only experimental API. (array_methods
)
pub fn each_ref(&self) -> [&T; N]
array_methods
)Borrows each element and returns an array of references with the same
size as self
.
Example
#![feature(array_methods)]
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
This method is particularly useful if combined with other methods, like
map
. This way, you can avoid moving the original
array if its elements are not Copy
.
#![feature(array_methods)]
let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);
// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬 This is a nightly-only experimental API. (split_array
)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
split_array
)Divides one array reference into two at an index.
The first will contain all indices from [0, M)
(excluding
the index M
itself) and the second will contain all
indices from [M, N)
(excluding the index N
itself).
Panics
Panics if M > N
.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.split_array_ref::<0>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<2>();
assert_eq!(left, &[1, 2]);
assert_eq!(right, &[3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<6>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬 This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
split_array
)Divides one array reference into two at an index from the end.
The first will contain all indices from [0, N - M)
(excluding
the index N - M
itself) and the second will contain all
indices from [N - M, N)
(excluding the index N
itself).
Panics
Panics if M > N
.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.rsplit_array_ref::<0>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
{
let (left, right) = v.rsplit_array_ref::<2>();
assert_eq!(left, &[1, 2, 3, 4]);
assert_eq!(right, &[5, 6]);
}
{
let (left, right) = v.rsplit_array_ref::<6>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
Trait Implementations
sourceimpl Borrow<SecretKey> for SecretKey
impl Borrow<SecretKey> for SecretKey
sourcefn borrow(&self) -> &Secp256k1SecretKey
fn borrow(&self) -> &Secp256k1SecretKey
Immutably borrows from an owned value. Read more
sourceimpl Ord for SecretKey
impl Ord for SecretKey
sourceimpl PartialOrd<SecretKey> for SecretKey
impl PartialOrd<SecretKey> for SecretKey
sourcefn partial_cmp(&self, other: &SecretKey) -> Option<Ordering>
fn partial_cmp(&self, other: &SecretKey) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for SecretKey
impl Eq for SecretKey
impl StructuralEq for SecretKey
impl StructuralPartialEq for SecretKey
Auto Trait Implementations
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more