Enum massa_signature::signature_impl::PublicKey
source · pub enum PublicKey {
PublicKeyV0(PublicKeyV0),
}
Expand description
Public key used to check if a message was encoded
by the corresponding PublicKey
.
Generated from the KeyPair
using SignatureEngine
Variants§
PublicKeyV0(PublicKeyV0)
Implementations§
source§impl PublicKey
impl PublicKey
sourcepub fn verify_signature(
&self,
hash: &Hash,
signature: &Signature,
) -> Result<(), MassaSignatureError>
pub fn verify_signature( &self, hash: &Hash, signature: &Signature, ) -> Result<(), MassaSignatureError>
Checks if the Signature
associated with data bytes
was produced with the KeyPair
associated to given PublicKey
sourcepub fn to_bytes(&self) -> Vec<u8>
pub fn to_bytes(&self) -> Vec<u8>
Serialize a PublicKey
as bytes.
§Example
let keypair = KeyPair::generate(0).unwrap();
let serialize = keypair.get_public_key().to_bytes();
sourcepub fn get_ser_len(&self) -> usize
pub fn get_ser_len(&self) -> usize
Return the total length after serialization
sourcepub fn from_bytes(data: &[u8]) -> Result<PublicKey, MassaSignatureError>
pub fn from_bytes(data: &[u8]) -> Result<PublicKey, MassaSignatureError>
Deserialize a PublicKey
from bytes.
§Example
let keypair = KeyPair::generate(0).unwrap();
let serialized = keypair.get_public_key().to_bytes();
let deserialized: PublicKey = PublicKey::from_bytes(&serialized).unwrap();
Trait Implementations§
source§impl<'de> Deserialize<'de> for PublicKey
impl<'de> Deserialize<'de> for PublicKey
source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<PublicKey, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<PublicKey, D::Error>
::serde::Deserialize
trait for PublicKey
if the deserializer is human readable,
deserialization is done using deserialize_bs58_check
else, it uses deserialize_binary
§Example
Human readable deserialization :
let keypair = KeyPair::generate(0).unwrap();
let serialized = serde_json::to_string(&keypair.get_public_key()).unwrap();
let deserialized: PublicKey = serde_json::from_str(&serialized).unwrap();
source§impl Deserializer<PublicKey> for PublicKeyDeserializer
impl Deserializer<PublicKey> for PublicKeyDeserializer
source§fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
&self,
buffer: &'a [u8],
) -> IResult<&'a [u8], PublicKey, E>
fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( &self, buffer: &'a [u8], ) -> IResult<&'a [u8], PublicKey, E>
use massa_signature::{PublicKey, PublicKeyDeserializer, KeyPair};
use massa_serialization::{DeserializeError, Deserializer};
use massa_hash::Hash;
let keypair = KeyPair::generate(0).unwrap();
let public_key = keypair.get_public_key();
let serialized = public_key.to_bytes();
let (rest, deser_public_key) = PublicKeyDeserializer::new().deserialize::<DeserializeError>(&serialized).unwrap();
assert!(rest.is_empty());
assert_eq!(keypair.get_public_key(), deser_public_key);
source§impl FromStr for PublicKey
impl FromStr for PublicKey
source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
§Example
let pubkey = KeyPair::generate(0).unwrap().get_public_key();
let string = pubkey.to_string();
let pubkey_2 = PublicKey::from_str(&string).unwrap();
assert_eq!(pubkey.to_string(), pubkey_2.to_string());
§type Err = MassaSignatureError
type Err = MassaSignatureError
The associated error which can be returned from parsing.
source§impl Ord for PublicKey
impl Ord for PublicKey
source§impl PartialEq for PublicKey
impl PartialEq for PublicKey
source§impl PartialOrd for PublicKey
impl PartialOrd for PublicKey
1.0.0 · source§fn 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 moresource§impl Serialize for PublicKey
impl Serialize for PublicKey
source§fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>
::serde::Serialize
trait for PublicKey
if the serializer is human readable,
serialization is done using serialize_bs58_check
else, it uses serialize_binary
§Example
Human readable serialization :
let keypair = KeyPair::generate(0).unwrap();
let serialized: String = serde_json::to_string(&keypair.get_public_key()).unwrap();
impl Copy for PublicKey
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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)