Skip to main content

Crate threema_gateway

Crate threema_gateway 

Source
Expand description

§Threema Gateway SDK for Rust

This is the official Rust SDK for Threema Gateway.

Documentation of the HTTP API can be found at gateway.threema.ch.

§Example: Send simple (transport encrypted) message

use threema_gateway::{ApiBuilder, Recipient, ThreemaId};

let from = ThreemaId::try_from("*YOUR0ID").unwrap();
let to = Recipient::new_email("user@example.com");
let secret = "your-gateway-secret";
let text = "Very secret message!";

// Send
let api = ApiBuilder::new(from, secret).into_simple();
match api.send(&to, &text).await {
    Ok(msg_id) => println!("Sent. Message id is {}.", msg_id),
    Err(e) => println!("Could not send message: {:?}", e),
}

§Example: Send end-to-end encrypted message

use threema_gateway::{ApiBuilder, E2eMessage, RecipientKey, ThreemaId};

let from = ThreemaId::try_from("*YOUR0ID").unwrap();
let to = ThreemaId::try_from("ECHOECHO").unwrap();
let secret = "your-gateway-secret";
let private_key = "your-private-key";
let text = "Very secret message!";

// Create E2eApi instance
let api = ApiBuilder::new(from, secret)
    .with_private_key_str(private_key)
    .and_then(|builder| builder.into_e2e())
    .unwrap();

// Fetch recipient public key
// Note: In a real application, you should cache the public key
let recipient_key = api.lookup_pubkey(&to).await.unwrap();

// Encrypt
let msg = E2eMessage::Text(text.into());
let encrypted = api.encode_and_encrypt(&msg, &recipient_key)
    .expect("Could not encrypt message");

// Send
match api.send(&to, &encrypted, false).await {
    Ok(msg_id) => println!("Sent. Message id is {}.", msg_id),
    Err(e) => println!("Could not send message: {:?}", e),
}

For more examples, see the examples/ directory.

Re-exports§

pub use crate::protocol::ThreemaId;
pub use crate::protocol::ThreemaIdError;
pub use crate::protocol::e2e::E2eMessage;

Modules§

cache
Cache-related functionality.
errors
Error types used in this library.
protocol
Types related to the Threema messaging protocol.

Structs§

ApiBuilder
A convenient way to set up the API object.
BulkE2eMessage
An end-to-end encrypted message for a specific recipient.
BulkIdentityPublicKey
Result returned by a bulk ID lookup.
Capabilities
A struct containing flags according to the capabilities of a Threema ID.
E2eApi
Struct to talk to the E2E API (with end-to-end encryption).
EncryptedFileData
Encrypted bytes of a file and optionally a thumbnail.
EncryptedMessage
An encrypted message. Contains both the ciphertext and the nonce.
FileData
Raw unencrypted bytes of a file and optionally a thumbnail.
IncomingMessagereceive
An incoming message received from Threema Gateway.
Key
Key type used for nacl secretbox cryptography
PublicKey
A crypto_box public key.
RecipientKey
The public key of a recipient.
SecretKey
A crypto_box secret key.
SimpleApi
Struct to talk to the simple API (without end-to-end encryption).

Enums§

BulkE2eMessageSendStatus
Response to an E2E bulk message sending request.
LookupCriterion
Different ways to look up a Threema ID in the directory.
Recipient
Different ways to specify a message recipient in basic mode.

Functions§

decrypt_file_data
Decrypt file data and optional thumbnail data with the provided symmetric key.
encrypt
Encrypt a message with the specified msgtype for the recipient.
encrypt_file_data
Encrypt file data and an optional thumbnail using a randomly generated symmetric key.
encrypt_raw
Encrypt raw data for the recipient.

Type Aliases§

Nonce
Nonce type.