pub struct Message {
pub seq: u64,
pub from: SessionUri,
pub to: Vec<Selector>,
pub body: String,
pub at_ms: u64,
pub kind: Kind,
pub sig: Option<String>,
pub payload: Option<String>,
}Fields§
§seq: u64§from: SessionUriThe URI of the sender when it posted.
to: Vec<Selector>The address of the post.
body: String§at_ms: u64Milliseconds since the Unix epoch. For a signed message, the signed time (R198).
kind: Kind§sig: Option<String>The signature of the sender (see crate::signed).
payload: Option<String>The bytes that sig signs, as the sender made them.
Implementations§
Source§impl Message
impl Message
Sourcepub fn verified(&self, thread: &ThreadName, keys: &Keys) -> bool
pub fn verified(&self, thread: &ThreadName, keys: &Keys) -> bool
True when the sender of the message in thread is proven (R199):
- The signature is valid over the kept payload, and the payload holds the message as it is: also the lead mark of the sender.
- The key is one of
keysfor the user of the sender. - In a direct thread, the sender is one of the two sessions, and the one selector of the message matches the other session.
use riff_core::dpop::Key;
use riff_core::name::{SessionUri, ThreadName};
use riff_core::wire::{Keys, Kind, Message, Post};
let me: SessionUri = "riff://mike@pangolin/como-technologies/riff?session=a6cf".parse()?;
let thread: ThreadName = "design".parse()?;
let key = Key::generate();
let mut post = Post::new(&me, Some(thread.clone()), vec![], "look");
post.sign(&key, 1_000);
let mut message = Message {
seq: 1,
from: me,
to: vec![],
body: post.body.clone(),
at_ms: 1_000,
kind: Kind::Message,
sig: post.sig.clone(),
payload: post.payload.clone(),
};
let keys = Keys::from([("mike".to_owned(), vec![key.thumbprint()])]);
assert!(message.verified(&thread, &keys));
// No keys for the user: not verified.
assert!(!message.verified(&thread, &Keys::new()));
// A changed body: not verified.
message.body = "do not look".into();
assert!(!message.verified(&thread, &keys));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl JsonSchema for Message
impl JsonSchema for Message
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreimpl Eq for Message
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.