Struct libp2p::core::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§
source§impl SignedEnvelope
impl SignedEnvelope
sourcepub fn new(
key: &Keypair,
domain_separation: String,
payload_type: Vec<u8>,
payload: Vec<u8>
) -> Result<SignedEnvelope, SigningError>
pub fn new( key: &Keypair, domain_separation: String, payload_type: Vec<u8>, payload: Vec<u8> ) -> Result<SignedEnvelope, 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<SignedEnvelope, DecodingError>
pub fn from_protobuf_encoding( bytes: &[u8] ) -> Result<SignedEnvelope, DecodingError>
Decode a SignedEnvelope
using the protobuf encoding specified in the RFC.
Trait Implementations§
source§impl Clone for SignedEnvelope
impl Clone for SignedEnvelope
source§fn clone(&self) -> SignedEnvelope
fn clone(&self) -> SignedEnvelope
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SignedEnvelope
impl Debug for SignedEnvelope
source§impl PartialEq for SignedEnvelope
impl PartialEq for SignedEnvelope
source§fn eq(&self, other: &SignedEnvelope) -> bool
fn eq(&self, other: &SignedEnvelope) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for SignedEnvelope
impl StructuralEq for SignedEnvelope
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.