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, Global>,
payload: Vec<u8, Global>
) -> Result<SignedEnvelope, SigningError>
pub fn new( key: &Keypair, domain_separation: String, payload_type: Vec<u8, Global>, payload: Vec<u8, Global> ) -> 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, Global> ⓘ
pub fn into_protobuf_encoding(self) -> Vec<u8, Global> ⓘ
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<SignedEnvelope> for SignedEnvelope
impl PartialEq<SignedEnvelope> 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 ==
.