#[non_exhaustive]pub enum PublicKey {
System,
Ed25519(VerifyingKey),
Secp256k1(VerifyingKey),
}
Expand description
A public asymmetric key.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
System
System public key.
Ed25519(VerifyingKey)
Ed25519 public key.
Secp256k1(VerifyingKey)
secp256k1 public key.
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub const SYSTEM_LENGTH: usize = 0usize
pub const SYSTEM_LENGTH: usize = 0usize
The length in bytes of a system public key.
Sourcepub const ED25519_LENGTH: usize = 32usize
pub const ED25519_LENGTH: usize = 32usize
The length in bytes of an Ed25519 public key.
Sourcepub const SECP256K1_LENGTH: usize = 33usize
pub const SECP256K1_LENGTH: usize = 33usize
The length in bytes of a secp256k1 public key.
Sourcepub fn to_account_hash(&self) -> AccountHash
pub fn to_account_hash(&self) -> AccountHash
Creates an AccountHash
from a given PublicKey
instance.
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Hexadecimal representation of the key.
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 PublicKey
.
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 PublicKey
.
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 PublicKey
.
Trait Implementations§
Source§impl AsymmetricType<'_> for PublicKey
impl AsymmetricType<'_> for PublicKey
Source§fn ed25519_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, Error>
fn ed25519_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, Error>
Constructs a new ed25519 variant from a byte slice.
Source§fn secp256k1_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, Error>
fn secp256k1_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, Error>
Constructs a new secp256k1 variant from a byte slice.
Source§impl DataSize for PublicKey
impl DataSize for PublicKey
Source§const IS_DYNAMIC: bool = true
const IS_DYNAMIC: bool = true
If
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
The amount of space a value of the type always occupies. If
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
Estimates the size of heap memory taken up by this value. Read more
Source§impl<'de> Deserialize<'de> for PublicKey
impl<'de> Deserialize<'de> for PublicKey
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl Distribution<PublicKey> for Standard
Available on crate feature testing
only.
impl Distribution<PublicKey> for Standard
Available on crate feature
testing
only.Source§impl From<&PublicKey> for AccountHash
impl From<&PublicKey> for AccountHash
Source§impl From<&PublicKey> for DelegatorKind
impl From<&PublicKey> for DelegatorKind
Source§impl From<&PublicKey> for PackageHash
impl From<&PublicKey> for PackageHash
Source§impl From<PublicKey> for DelegatorKind
impl From<PublicKey> for DelegatorKind
Source§impl From<PublicKey> for InitiatorAddr
impl From<PublicKey> for InitiatorAddr
Source§impl From<PublicKey> for TransferTarget
impl From<PublicKey> for TransferTarget
Source§impl JsonSchema for PublicKey
Available on crate feature json-schema
only.
impl JsonSchema for PublicKey
Available on crate feature
json-schema
only.Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read moreSource§impl Ord for PublicKey
impl Ord for PublicKey
Source§impl PartialOrd for PublicKey
impl PartialOrd for PublicKey
Source§impl ToBytes for PublicKey
impl ToBytes for PublicKey
Source§fn serialized_length(&self) -> usize
fn serialized_length(&self) -> usize
Returns the length of the
Vec<u8>
which would be returned from a successful call to
to_bytes()
or into_bytes()
. The data is not actually serialized, so this call is
relatively cheap.impl Eq for PublicKey
impl StructuralPartialEq for PublicKey
Auto Trait Implementations§
impl Freeze for PublicKey
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnwindSafe for PublicKey
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
Compare self to
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
Compare self to
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>
Converts
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>
Converts
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