Struct libp2p_core::signed_envelope::SignedEnvelope
source · [−]pub struct SignedEnvelope { /* private fields */ }
Expand description
A signed envelope contains an arbitrary byte string payload, a signature of the payload, and the public key that can be used to verify the signature.
For more details see libp2p RFC0002: https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md
Implementations
sourceimpl SignedEnvelope
impl SignedEnvelope
sourcepub fn new(
key: &Keypair,
domain_separation: String,
payload_type: Vec<u8>,
payload: Vec<u8>
) -> Result<Self, SigningError>
pub fn new(
key: &Keypair,
domain_separation: String,
payload_type: Vec<u8>,
payload: Vec<u8>
) -> Result<Self, SigningError>
Constructs a new SignedEnvelope
.
sourcepub fn verify(&self, domain_separation: String) -> bool
pub fn verify(&self, domain_separation: String) -> bool
Verify this SignedEnvelope
against the provided domain-separation string.
sourcepub fn payload_and_signing_key(
&self,
domain_separation: String,
expected_payload_type: &[u8]
) -> Result<(&[u8], &PublicKey), ReadPayloadError>
pub fn payload_and_signing_key(
&self,
domain_separation: String,
expected_payload_type: &[u8]
) -> Result<(&[u8], &PublicKey), ReadPayloadError>
Extract the payload and signing key of this SignedEnvelope
.
You must provide the correct domain-separation string and expected payload type in order to get the payload. This guards against accidental mis-use of the payload where the signature was created for a different purpose or payload type.
It is the caller’s responsibility to check that the signing key is what is expected. For example, checking that the signing key is from a certain peer.
sourcepub fn into_protobuf_encoding(self) -> Vec<u8>
pub fn into_protobuf_encoding(self) -> Vec<u8>
Encode this SignedEnvelope
using the protobuf encoding specified in the RFC.
sourcepub fn from_protobuf_encoding(bytes: &[u8]) -> Result<Self, DecodingError>
pub fn from_protobuf_encoding(bytes: &[u8]) -> Result<Self, DecodingError>
Decode a SignedEnvelope
using the protobuf encoding specified in the RFC.
Trait Implementations
sourceimpl Clone for SignedEnvelope
impl Clone for SignedEnvelope
sourcefn clone(&self) -> SignedEnvelope
fn clone(&self) -> SignedEnvelope
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for SignedEnvelope
impl Debug for SignedEnvelope
sourceimpl PartialEq<SignedEnvelope> for SignedEnvelope
impl PartialEq<SignedEnvelope> for SignedEnvelope
sourcefn eq(&self, other: &SignedEnvelope) -> bool
fn eq(&self, other: &SignedEnvelope) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &SignedEnvelope) -> bool
fn ne(&self, other: &SignedEnvelope) -> bool
This method tests for !=
.
impl StructuralPartialEq for SignedEnvelope
Auto Trait Implementations
impl RefUnwindSafe for SignedEnvelope
impl Send for SignedEnvelope
impl Sync for SignedEnvelope
impl Unpin for SignedEnvelope
impl UnwindSafe for SignedEnvelope
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