Struct didcomm_rs::Message[][src]

pub struct Message {
    pub jwm_header: JwmHeader,
    pub body: Vec<u8>,
    // some fields omitted
}

DIDComm message structure. Specification

Fields

jwm_header: JwmHeader

JOSE header, which is sent as public part with JWE.

body: Vec<u8>

Message payload, which can be basically anything (JSON, text, file, etc.) represented as bytes of data.

Implementations

impl Message[src]

pub fn new() -> Self[src]

Generates EMPTY default message. Use extension messages to build final one before sending.

pub fn from(self, from: &str) -> Self[src]

Setter of from header Helper method.

pub fn to(self, to: Vec<&str>) -> Self[src]

Setter of to header Helper method.

pub fn m_type(self, m_type: MessageType) -> Self[src]

Setter of m_type @type header Helper method.

pub fn body(self, body: &[u8]) -> Self[src]

Setter of the body Helper method.

pub fn kid(self, kid: &str) -> Self[src]

pub fn timed(self, expires: Option<u64>) -> Self[src]

Sets times of creation as now and, optional, expires time.

Parameters

  • expires - time in seconds since Unix Epoch when message is considered to be invalid.

pub fn is_rotation(&self) -> bool[src]

Checks if message is rotation one. Exposed for explicit checks on calling code level.

pub fn get_prior(&self) -> Result<PriorClaims, Error>[src]

If message is_rotation() true - returns from_prion claims. Errors otherwise with Error::NoRotationData

pub fn get_didcomm_header(&self) -> &DidcommHeader[src]

&DidcommHeader getter.

pub fn set_didcomm_header(self, h: DidcommHeader) -> Self[src]

Setter of didcomm_header. Replaces existing one with provided by consuming both values. Returns modified instance of Self.

pub fn add_header_field(self, key: String, value: String) -> Self[src]

Adds (or updates) custom unique header key-value pair to the header. This portion of header is not sent as JOSE header.

pub fn as_jws(self, alg: &SignatureAlgorithm) -> Self[src]

Creates set of Jwm related headers for the JWE Modifies JWM related header portion to match encryption implementation and leaves other parts unchanged. TODO + FIXME: complete implementation

pub fn as_jwe(self, alg: &CryptoAlgorithm) -> Self[src]

Creates set of Jwm related headers for the JWS Modifies JWM related header portion to match signature implementation and leaves Other parts unchanged.

For resolve feature will set kid header automatically based on the did document resolved.

pub fn as_raw_json(self) -> Result<String, Error>[src]

Serializez current state of the message into json. Consumes original message - use as raw sealing of envelope.

pub fn seal(self, ek: &[u8]) -> Result<String, Error>[src]

Seals self and returns ready to send JWE

Parameters

ek - encryption key for inner message payload JWE encryption

pub fn seal_signed(
    self,
    ek: &[u8],
    sk: &[u8],
    signing_algorithm: SignatureAlgorithm
) -> Result<String, Error>
[src]

Signs raw message and then packs it to encrypted envelope Spec

Parameters

ek - encryption key for inner message payload JWE encryption

sk - signing key for enveloped message JWS encryption

pub fn routed_by(self, ek: &[u8], to: Vec<&str>) -> Result<Self, Error>[src]

Wrap self to be mediated by some mediator. Warning: Should be called on a Message instance which is ready to be sent! If message is not properly set up for crypto - this method will propogate error from called .seal() method. Takes one mediator at a time to make sure that mediated chain preserves unchanged. This method can be chained any number of times to match all the mediators in the chain.

Parameters

ek - encryption key for inner message payload JWE encryption

to - list of destination recepients. can be empty (Optional) String::default()

form - used same as in wrapped message, fails if not present with DidResolveFailed error.

TODO: Add examples

impl Message[src]

Associated functions implementations. Possibly not required as Jwe serialization covers this.

pub fn get_iv(received: &[u8]) -> Result<Vec<u8>, Error>[src]

Parses iv value as Vec<u8> from public header. Both regular JSON and Compact representations are accepted. Returns Error on failure. TODO: Add examples

pub fn receive(
    incomming: &str,
    crypto_key: Option<&[u8]>,
    validation_key: Option<&[u8]>
) -> Result<Self, Error>
[src]

Construct a message from received data. Raw or JWE payload is accepted.

impl Message[src]

pub fn encrypt(
    self,
    crypter: SymmetricCypherMethod,
    receiver_pk: &[u8]
) -> Result<String, Error>
[src]

Encrypts current message by consuming it. Uses provided cryptography function to perform the encryption. Agnostic of actual algorythm used. Consuming is to make sure no changes are possible post packaging / sending. Returns (JwmHeader, Vec<u8>) to be sent to receiver.

pub fn decrypt(
    received_message: &[u8],
    decrypter: SymmetricCypherMethod,
    key: &[u8]
) -> Result<Self, Error>
[src]

Decrypts received cypher into instance of Message. Received message should be encrypted with our pub key. Returns Ok(Message) if decryption / deserialization succeded. Error othervice.

pub fn sign(
    self,
    signer: SigningMethod,
    signing_key: &[u8]
) -> Result<String, Error>
[src]

Signs message and turns it into Jws envelope. Err is returned if message is not properly prepared or data is malformed. Jws enveloped payload is base64_url encoded

pub fn verify(jws: &[u8], key: &[u8]) -> Result<Message, Error>[src]

Verifyes signature and returns payload message on verification success. Err return if signature invalid or data is malformed. Expects Jws’s payload to be a valid serialized Message and base64_url encoded.

Trait Implementations

impl Clone for Message[src]

impl Debug for Message[src]

impl<'de> Deserialize<'de> for Message[src]

impl PartialEq<Message> for Message[src]

impl Serialize for Message[src]

impl StructuralPartialEq for Message[src]

Auto Trait Implementations

impl RefUnwindSafe for Message

impl Send for Message

impl Sync for Message

impl Unpin for Message

impl UnwindSafe for Message

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,