[client] Reactions and replies: a message is named by its author and seq, a reply carries its reference, a reaction sets or removes, a newer kind is Unsupported
This commit is contained in:
@@ -148,6 +148,12 @@ fixed_bytes!(
|
||||
InviteId,
|
||||
16
|
||||
);
|
||||
fixed_bytes!(
|
||||
/// A message's author: the 16 random bytes in their MLS credential, made on their device, never
|
||||
/// a name. With the author's `seq` it names a message (`PROTOCOL.md` §4, reactions and replies).
|
||||
Author,
|
||||
16
|
||||
);
|
||||
fixed_bytes!(
|
||||
/// SHA-256 of a token, or of a blob when it is acknowledged. The relay stores token hashes only.
|
||||
Sha256Hash,
|
||||
@@ -193,7 +199,7 @@ macro_rules! debug_as_wire {
|
||||
}
|
||||
)*};
|
||||
}
|
||||
debug_as_wire!(MailboxId, InviteId, Sha256Hash);
|
||||
debug_as_wire!(MailboxId, InviteId, Sha256Hash, Author);
|
||||
|
||||
/// The SHA-256 of a blob: how its recipient acknowledges it.
|
||||
pub fn blob_hash(blob: &[u8]) -> Sha256Hash {
|
||||
|
||||
@@ -145,6 +145,7 @@ proptest! {
|
||||
let _ = InviteId::parse(&text);
|
||||
let _ = Sha256Hash::parse(&text);
|
||||
let _ = Token::parse(&text);
|
||||
let _ = Author::parse(&text);
|
||||
let _ = Token::from_bearer(&text);
|
||||
let _ = WireBytes::parse(&text, MAX_BLOB_BYTES);
|
||||
}
|
||||
@@ -172,7 +173,10 @@ proptest! {
|
||||
#[test]
|
||||
fn whatever_parses_has_one_spelling(text in "[A-Za-z0-9_-]{22}") {
|
||||
if let Ok(id) = MailboxId::parse(&text) {
|
||||
prop_assert_eq!(id.to_wire(), text);
|
||||
prop_assert_eq!(&id.to_wire(), &text);
|
||||
}
|
||||
if let Ok(author) = Author::parse(&text) {
|
||||
prop_assert_eq!(&author.to_wire(), &text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,3 +268,24 @@ proptest! {
|
||||
let _ = PushEndpoint::parse(&format!("https://{text}"));
|
||||
}
|
||||
}
|
||||
|
||||
// Reactions and replies (`.agents/features/reactions-replies.md` §2.1): a message's author.
|
||||
#[test]
|
||||
fn an_author_is_16_bytes_in_22_canonical_characters_and_prints_as_its_wire() {
|
||||
let author = Author::from_bytes([0x5A; 16]);
|
||||
let wire = author.to_wire();
|
||||
assert_eq!(wire.len(), 22);
|
||||
assert_eq!(Author::parse(&wire), Ok(author));
|
||||
assert_eq!(
|
||||
serde_json::to_string(&author).expect("json"),
|
||||
format!("\"{wire}\"")
|
||||
);
|
||||
assert!(Author::parse(&wire[..21]).is_err());
|
||||
assert!(Author::parse(&Token::from_bytes([1; 32]).to_wire()).is_err());
|
||||
let zero = Author::from_bytes([0; 16]).to_wire();
|
||||
assert_eq!(
|
||||
Author::parse(&format!("{}B", &zero[..21])),
|
||||
Err(ParseError::Encoding)
|
||||
);
|
||||
assert_eq!(format!("{author:?}"), format!("Author({wire})"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user