Crate threema_gateway [] [src]

Threema Gateway SDK for Rust

Travis CI Crates.io Rust

This library makes it easy to use the Threema Gateway from Rust programs.

Documentation of the HTTP API can be found here: https://gateway.threema.ch/de/developer/api

Example: Send simple (transport encrypted) message

use threema_gateway::{Recipient, send_simple};

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

// Send
match send_simple(&from, &to, &secret, &text) {
    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::{lookup_pubkey, encrypt, send_e2e};

let from = "*YOUR_ID";
let to = "ECHOECHO";
let secret = "your-gateway-secret";
let private_key = "your-private-key";
let text = "Very secret message!";

// Fetch public key
// Note: In a real application, you should cache the public key
let public_key = lookup_pubkey(from, to, secret).unwrap();

// Encrypt
let (ciphertext, nonce) = encrypt(&text, &public_key, &private_key).unwrap();

// Send
match send_e2e(&from, &to, &secret, &nonce, &ciphertext) {
    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.

Modules

errors

Error types used in this library.

Enums

LookupCriterion
Recipient

Different ways to specify a message recipient in basic mode

Functions

encrypt

Encrypt data for the receiver.

lookup_id

Look up an ID in the Threema directory.

lookup_pubkey

Fetch the public key for the specified Threema ID.

send_e2e

Send an already encrypted E2E message to the specified receiver.

send_simple

Send a message to the specified recipient in basic mode.