Struct threema_gateway::E2eApi
source · pub struct E2eApi { /* private fields */ }
Expand description
Struct to talk to the E2E API (with end-to-end encryption).
Implementations
sourceimpl E2eApi
impl E2eApi
sourcepub fn encrypt_raw(
&self,
data: &[u8],
recipient_key: &RecipientKey
) -> EncryptedMessage
pub fn encrypt_raw(
&self,
data: &[u8],
recipient_key: &RecipientKey
) -> EncryptedMessage
Encrypt raw bytes for the specified recipient public key.
sourcepub fn encrypt_text_msg(
&self,
text: &str,
recipient_key: &RecipientKey
) -> EncryptedMessage
pub fn encrypt_text_msg(
&self,
text: &str,
recipient_key: &RecipientKey
) -> EncryptedMessage
Encrypt a text message for the specified recipient public key.
sourcepub fn encrypt_image_msg(
&self,
blob_id: &BlobId,
img_size_bytes: u32,
image_data_nonce: &[u8; 24],
recipient_key: &RecipientKey
) -> EncryptedMessage
pub fn encrypt_image_msg(
&self,
blob_id: &BlobId,
img_size_bytes: u32,
image_data_nonce: &[u8; 24],
recipient_key: &RecipientKey
) -> EncryptedMessage
Encrypt an image message for the specified recipient public key.
Before calling this function, you need to encrypt the image data (JPEG
format) with encrypt_raw
and
upload the ciphertext to the blob server.
The image size needs to be specified in bytes. Note that the size is only used for download size displaying purposes and has no security implications.
sourcepub fn encrypt_file_msg(
&self,
file_blob_id: &BlobId,
thumbnail_blob_id: Option<&BlobId>,
blob_encryption_key: &Key,
mime_type: &Mime,
file_name: Option<&str>,
file_size_bytes: u32,
description: Option<&str>,
recipient_key: &RecipientKey
) -> EncryptedMessage
pub fn encrypt_file_msg(
&self,
file_blob_id: &BlobId,
thumbnail_blob_id: Option<&BlobId>,
blob_encryption_key: &Key,
mime_type: &Mime,
file_name: Option<&str>,
file_size_bytes: u32,
description: Option<&str>,
recipient_key: &RecipientKey
) -> EncryptedMessage
Encrypt a file message for the specified recipient public key.
Before calling this function, you need to symetrically encrypt the file
data (libsodium secretbox, random key) and upload the ciphertext to the
blob server. If you also want to set a thumbnail, do the same with the
update data (in JPEG format) and use the same key. Use the nonce
000...1
for the file and 000...2
for the thumbnail.
The file size needs to be specified in bytes. Note that the size is only used for download size displaying purposes and has no security implications.
sourcepub fn send(
&self,
to: &str,
message: &EncryptedMessage
) -> Result<String, ApiError>
pub fn send(
&self,
to: &str,
message: &EncryptedMessage
) -> Result<String, ApiError>
Send an encrypted E2E message to the specified Threema ID.
Cost: 1 credit.
sourcepub fn lookup_pubkey(&self, id: &str) -> Result<String, ApiError>
pub fn lookup_pubkey(&self, id: &str) -> Result<String, ApiError>
Fetch the public key for the specified Threema ID.
For the end-to-end encrypted mode, you need the public key of the recipient in order to encrypt a message. While it’s best to obtain this directly from the recipient (extract it from the QR code), this may not be convenient, and therefore you can also look up the key associated with a given ID from the server.
It is strongly recommended that you cache the public keys to avoid querying the API for each message.
sourcepub fn lookup_id(&self, criterion: &LookupCriterion) -> Result<String, ApiError>
pub fn lookup_id(&self, criterion: &LookupCriterion) -> Result<String, ApiError>
Look up a Threema ID in the directory.
An ID can be looked up either by a phone number or an e-mail
address, in plaintext or hashed form. You can specify one of those
criteria using the LookupCriterion
enum.
sourcepub fn lookup_capabilities(&self, id: &str) -> Result<Capabilities, ApiError>
pub fn lookup_capabilities(&self, id: &str) -> Result<Capabilities, ApiError>
Look up the capabilities of a certain Threema ID.
Before you send a file to a Threema ID using the blob upload (+file message), you may want to check whether the recipient uses a Threema version that supports receiving files. The receiver may be using an old version, or a platform where file reception is not supported.
sourcepub fn lookup_credits(&self) -> Result<i64, ApiError>
pub fn lookup_credits(&self) -> Result<i64, ApiError>
Look up a remaining gateway credits.
sourcepub fn blob_upload(&self, data: &EncryptedMessage) -> Result<BlobId, ApiError>
pub fn blob_upload(&self, data: &EncryptedMessage) -> Result<BlobId, ApiError>
Upload encrypted data to the blob server.
Cost: 1 credit.
Trait Implementations
impl Eq for E2eApi
impl StructuralEq for E2eApi
impl StructuralPartialEq for E2eApi
Auto Trait Implementations
impl RefUnwindSafe for E2eApi
impl Send for E2eApi
impl Sync for E2eApi
impl Unpin for E2eApi
impl UnwindSafe for E2eApi
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.