/// Invalid message. #[error("Invalid message: Does not contain sufficient bytes")]
InvalidMessage,
}
/// An incoming end-to-end encrypted Threema message with additional end-to-end encrypted metadata. /// /// Note: Only the outer shell has been decoded here. The incoming message task is responsible for decrypting /// and decoding the inner layers. #[derive(Educe)] #[educe(Debug)] pub(crate) struct IncomingMessageWithMetadataBox { /// Raw bytes of the payload #[educe(Debug(method(debug_slice_length)))] pub(super) bytes: Vec<u8>,
/// The sender's Threema ID. pub(super) sender_identity: ThreemaId,
/// The receiver's Threema ID. pub(super) receiver_identity: ThreemaId,
/// The ID of the message pub(super) id: MessageId,
/// (Legacy) UNIX timestamp in seconds for when the message has been created. /// /// Note: This timestamp is also present in the `metadata` field and should be preferred from /// there. pub(super) legacy_created_at: u32,
// Skip the message ID (we already have it)
reader.skip(MessageId::LENGTH)?;
// Decode legacy _created at_ timestamp let legacy_created_at = reader.read_u32_le()?;
// Skip flags (we already have it) and reserved bytes
reader.skip(2)?;
// Decode metadata length let metadata_length = reader.read_u16_le()?;
// Decode and trim zero-padded legacy sender nickname (if any) let legacy_sender_nickname = { let nickname = reader.read_fixed::<{ LEGACY_SENDER_NICKNAME_LENGTH as usize }>()?; let length = nickname
.iter()
.position(|&character| character == b'\0')
.unwrap_or(nickname.len()); if length > 0 { let nickname = nickname
.get(..length)
.expect("calculated legacy sender nickname length must be in bounds"); let nickname =
str::from_utf8(nickname).map_err(IncomingMessagePayloadError::InvalidNickname)?;
Some(nickname.trim().to_owned())
} else {
None
}
};
// Decode metadata (if any) let metadata = if metadata_length > 0 {
Some(
reader.read_encrypted_data_range_tag_ahead(
(metadata_length as usize)
.checked_sub(salsa20::TAG_LENGTH)
.ok_or(IncomingMessagePayloadError::InvalidMessage)?,
)?,
)
} else {
None
};
// Decode nonce let nonce = Nonce::from(reader.read_fixed::<{ Nonce::LENGTH }>()?);
/// An error occurred while encoding an outgoing message payload. #[derive(Debug, thiserror::Error)] pub(crate) enum OutgoingMessagePayloadError { /// Decoding the message failed. #[error("Encoding message failed: {0}")]
EncodingFailed(#[from] ByteWriterError),
/// Metadata too large. #[error("Metadata too large")]
MetadataTooLarge,
}
/// An outgoing end-to-end encrypted Threema message with additional end-to-end encrypted metadata. #[derive(Educe)] #[educe(Debug)] pub(crate) struct OutgoingMessageWithMetadataBox { /// The sender's Threema ID. pub(super) sender_identity: ThreemaId,
/// The receiver's Threema ID. pub(super) receiver_identity: ThreemaId,
/// The ID of the message. pub(super) id: MessageId,
/// (Legacy) UNIX timestamp in seconds for when the message has been created. /// /// Note: This timestamp is also present in the `metadata` field and should be preferred from /// there. pub(super) legacy_created_at: u32,
/// Legacy sender nickname (nickname from metadata should be preferred). /// /// Note 1: The creator of the struct is responsible for omitting this field when sending a message to /// non-Gateway IDs. /// /// Note 2: Only 32 bytes of the UTF-8 string will be encoded, so prior truncation at UTF-8 codepoints is /// advised. pub(super) legacy_sender_nickname: Option<String>,
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.