Struct didcomm_rs::Message [−][src]
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 send
ing.
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]
self,
ek: &[u8],
sk: &[u8],
signing_algorithm: SignatureAlgorithm
) -> Result<String, Error>
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]
incomming: &str,
crypto_key: Option<&[u8]>,
validation_key: Option<&[u8]>
) -> Result<Self, Error>
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]
self,
crypter: SymmetricCypherMethod,
receiver_pk: &[u8]
) -> Result<String, Error>
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]
received_message: &[u8],
decrypter: SymmetricCypherMethod,
key: &[u8]
) -> Result<Self, Error>
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]
self,
signer: SigningMethod,
signing_key: &[u8]
) -> Result<String, Error>
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]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl PartialEq<Message> for Message
[src]
impl Serialize for Message
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Conv for T
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> FmtForward for T
pub fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Self: Binary,
pub fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Self: Display,
pub fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Self: LowerExp,
pub fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Self: LowerHex,
pub fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Self: Octal,
pub fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Self: Pointer,
pub fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Self: UpperExp,
pub fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Self: UpperHex,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pipe for T
impl<T> PipeAsRef for T
pub fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
Self: AsRef<T>,
T: 'a,
R: 'a,
pub fn pipe_as_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: AsMut<T>,
T: 'a,
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: AsMut<T>,
T: 'a,
R: 'a,
impl<T> PipeBorrow for T
pub fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
Self: Borrow<T>,
T: 'a,
R: 'a,
pub fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
T: 'a,
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
T: 'a,
R: 'a,
impl<T> PipeDeref for T
pub fn pipe_deref<'a, R>(
&'a self,
func: impl FnOnce(&'a Self::Target) -> R
) -> R where
Self: Deref,
R: 'a,
&'a self,
func: impl FnOnce(&'a Self::Target) -> R
) -> R where
Self: Deref,
R: 'a,
pub fn pipe_deref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
Self: DerefMut,
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
Self: DerefMut,
R: 'a,
impl<T> PipeRef for T
pub fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
R: 'a,
pub fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
R: 'a,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> Tap for T
pub fn tap<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
F: FnOnce(&Self) -> R,
pub fn tap_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
F: FnOnce(&Self) -> R,
pub fn tap_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
F: FnOnce(&mut Self) -> R,
pub fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
F: FnOnce(&mut Self) -> R,
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
U: ?Sized,
pub fn tap_ref<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Self: AsRef<T>,
F: FnOnce(&T) -> R,
pub fn tap_ref_dbg<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Self: AsRef<T>,
F: FnOnce(&T) -> R,
pub fn tap_ref_mut<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
pub fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
impl<T, U> TapBorrow<U> for T where
U: ?Sized,
U: ?Sized,
pub fn tap_borrow<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Self: Borrow<T>,
F: FnOnce(&T) -> R,
pub fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Self: Borrow<T>,
F: FnOnce(&T) -> R,
pub fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
pub fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
impl<T> TapDeref for T
pub fn tap_deref<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Self: Deref,
F: FnOnce(&Self::Target) -> R,
pub fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Self: Deref,
F: FnOnce(&Self::Target) -> R,
pub fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
pub fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> TryConv for T
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,