pub trait ChatResolvers: JmapBackend {
// Required method
fn attachment_blob(
&self,
caller: &Self::CallerCtx,
account_id: &Id,
blob_id: &Id,
) -> impl Future<Output = Result<Result<Option<AttachmentBlob>, SetError>, Self::Error>> + Send;
// Provided method
fn filenode_attachment(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_chat: &Chat,
_attachment: &AttachmentCreate,
) -> impl Future<Output = Result<Result<Option<Attachment>, SetError>, Self::Error>> + Send { ... }
}Expand description
Lookups outside chat storage: attachment blobs and FileNode attachments.
Part of ChatBackend (docs/design/chat-backend-split.md).
Required Methods§
Sourcefn attachment_blob(
&self,
caller: &Self::CallerCtx,
account_id: &Id,
blob_id: &Id,
) -> impl Future<Output = Result<Result<Option<AttachmentBlob>, SetError>, Self::Error>> + Send
fn attachment_blob( &self, caller: &Self::CallerCtx, account_id: &Id, blob_id: &Id, ) -> impl Future<Output = Result<Result<Option<AttachmentBlob>, SetError>, Self::Error>> + Send
Blob lookup consulted by handle_message_set for each Attachment
of a Message create.
Per draft-atwood-jmap-chat-00 §Attachment at jmap-chat-spec 77c3474,
size L374: “Servers SHOULD verify against actual content”, and
sha256 L377: “Servers SHOULD verify”. By choice, the handler
compares the returned AttachmentBlob
against the Attachment and rejects a mismatch with an
invalidProperties SetError naming attachments (§Input
Validation). The sha256 comparison is constant-time
(subtle::ConstantTimeEq), so implementations return the digest
rather than comparing it themselves.
§When the handler calls this
Once per Attachment, AFTER the maxAttachmentsPerMessage and
maxAttachmentBytes checks (§Denial of Service: “Enforce
maxBodyBytes and maxAttachmentBytes at parse time, before any
fetch or storage”) and BEFORE create_object.
§Return mapping
Ok(Ok(Some(blob))): compare the Attachment againstblob.Ok(Ok(None)): the backend does not verify this blob; accept.Ok(Err(set_error)): reject the create withset_error, e.g.invalidPropertiesnamingattachmentsfor an unknownblobId(RFC 8620 §5.3 definesblobNotFoundonly for upload paths).Err(e):serverFail.
Required: the size check is a MUST, so a backend that cannot
verify blobs says so explicitly by returning Ok(Ok(None)).
§CustomEmoji images
handle_emoji_set also calls this for the blobId of a create,
and of an update that sets blobId, when
ChatLimits::max_custom_emoji_bytes is a limit, to compare the
blob’s size with it (overQuota when larger). There Ok(Ok(None))
skips the check, and Ok(Err(_)) rejects the emoji with an
invalidProperties SetError naming blobId.
Provided Methods§
Sourcefn filenode_attachment(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_chat: &Chat,
_attachment: &AttachmentCreate,
) -> impl Future<Output = Result<Result<Option<Attachment>, SetError>, Self::Error>> + Send
fn filenode_attachment( &self, _caller: &Self::CallerCtx, _account_id: &Id, _chat: &Chat, _attachment: &AttachmentCreate, ) -> impl Future<Output = Result<Result<Option<Attachment>, SetError>, Self::Error>> + Send
FileNode resolution consulted by handle_message_set for each
create Attachment that carries filenodeId.
Per draft-atwood-jmap-chat-filenode-00 §filenodeId: “When
filenodeId is present on an Attachment, the fields blobId,
filename, contentType, size, and sha256 become OPTIONAL for
that Attachment entry; the server MUST populate any absent fields
from the referenced FileNode’s properties before storage”, and the
server “MUST verify that the referenced FileNode exists and belongs
to the same Space” and that “the sender has at least read access”.
chat is the message’s target Chat. A deployment offering
urn:ietf:params:jmap:chat:filenode implements this with
jmap_chat_filenode_server::resolve_filenode_attachment.
§When the handler calls this
Once per such Attachment, AFTER the maxAttachmentsPerMessage
check and the may_send_message gate, and BEFORE the
draft-atwood-jmap-chat-00 §Input Validation checks, the
maxAttachmentBytes check and Self::attachment_blob, which all
apply to the returned Attachment.
§Return mapping
Ok(Ok(Some(attachment))): storeattachment, the entry with its absent fields filled.Ok(Ok(None)): the extension is not active; the entry must carry all five fields, as an Attachment withoutfilenodeIddoes.Ok(Err(set_error)): reject the create withset_error.Err(e):serverFail.
§Default implementation
Returns Ok(Ok(None)): no FileNode store, matching the fail-open
hooks above.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<C: MemoryCaller> ChatResolvers for MemoryBackend<C>
memory only.