Skip to main content

co_didcomm/messages/
out_of_band.rs

1use super::{AttachmentBuilder, Message, MessageType};
2use crate::Result;
3
4impl Message {
5    /// Transforms given `Message` into out_of_band invitation
6    /// with given body and optional attachments.
7    ///
8    /// # Parameters
9    ///
10    /// * `body` - bytes of JSON serialized message body
11    /// * `attachments` - optional set of `AttachmentBuilder` to be attached
12    pub fn as_out_of_band_invitation(
13        mut self,
14        body: impl AsRef<[u8]>,
15        attachments: Option<Vec<AttachmentBuilder>>,
16    ) -> Result<Self> {
17        self.jwm_header.typ = MessageType::DidCommRaw;
18        self.didcomm_header.m_type = serde_json::to_value(&MessageType::DidCommInvitation)
19            .unwrap()
20            .as_str()
21            .unwrap()
22            .to_string();
23        if let Some(attachments) = attachments {
24            for attachment in attachments {
25                self.append_attachment(attachment);
26            }
27        }
28        self.body(std::str::from_utf8(body.as_ref()).unwrap())
29    }
30}