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§
source§impl 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§
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
impl Eq for SignedEnvelope
impl StructuralPartialEq for SignedEnvelope
Auto Trait Implementations§
impl Freeze for SignedEnvelope
impl RefUnwindSafe for SignedEnvelope
impl Send for SignedEnvelope
impl Sync for SignedEnvelope
impl Unpin for SignedEnvelope
impl UnwindSafe for SignedEnvelope
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
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)
clone_to_uninit
)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>
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>
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