pub fn encode(&mut self, message: &[u8]) -> Result<String, BrancaError> {
        // A timestamp has not been manually set, so we create one automatically.
        let mut timestamp = self.timestamp;
        if timestamp == 0 {
            // Generate a timestamp instead of a zero supplied one.
            let ts = SystemTime::now()
                .duration_since(SystemTime::UNIX_EPOCH)
                .expect("Failed to obtain timestamp from system clock.");
            timestamp = ts.as_secs() as u32;
        }

        // Generate Nonce (24 bytes in length)
        let mut nonce = [0; XCHACHA_NONCESIZE];
        secure_rand_bytes(&mut nonce).unwrap();
        self.nonce = nonce.to_vec();

        encode_with_nonce(message, &self.key, &Nonce::from(nonce), timestamp)
    }
/// Encodes the message with the created Branca struct.
///
/// This panics if unable to securely generate random bytes or if unable to obtain current system time.
///
/// If the `timestamp` hasn't been set, the current system time is used. If `timestamp` has been set and is not `0`,
/// that value is used for all tokens created with this function (until changed).
///
/// The contents of the message can be of any arbitrary sequence of bytes, ie. text, JSON, Protobuf, JWT or a MessagePack, etc.
///
/// `message` - The data to be encoded as a Branca token.
///
/// # Example
/// ```rust
/// extern crate getrandom;
/// extern crate branca;
/// use branca::Branca;
///
/// fn main() {
///     let mut key = [0u8; 32];
///     getrandom::getrandom(&mut key).unwrap();
///     let mut token = Branca::new(&key).unwrap();
///
///     let ciphertext = token.encode(b"Hello World!").unwrap();
///     // Branca token is now in 'ciphertext' as a String.
/// }
/// ```
Encodes the message with the created Branca struct.
This panics if unable to securely generate random bytes or if unable to obtain current system time.

If the `timestamp` hasn't been set, the current system time is used. If `timestamp` has been set and is not `0`,
that value is used for all tokens created with this function (until changed).

The contents of the message can be of any arbitrary sequence of bytes, ie. text, JSON, Protobuf, JWT or a MessagePack, etc.

`message` - The data to be encoded as a Branca token.
Encodes the message with the created Branca struct . This panics if unable to securely generate random bytes or if unable to obtain current system time . If the ` timestamp ` hasn ' t been set the current system time is used . If ` timestamp ` has been set and is not ` 0 ` that value is used for all tokens created with this function ( until changed ) . The contents of the message can be of any arbitrary sequence of bytes ie . text JSON Protobuf JWT or a MessagePack etc . ` message ` - The data to be encoded as a Branca token .
pub fn encode(&mut self, message: &[u8]) -> Result<String, BrancaError> {
        // A timestamp has not been manually set, so we create one automatically.
        let mut timestamp = self.timestamp;
        if timestamp == 0 {
            // Generate a timestamp instead of a zero supplied one.
            let ts = SystemTime::now()
                .duration_since(SystemTime::UNIX_EPOCH)
                .expect("Failed to obtain timestamp from system clock.");
            timestamp = ts.as_secs() as u32;
        }
        // Generate Nonce (24 bytes in length)
        let mut nonce = [0; XCHACHA_NONCESIZE];
        secure_rand_bytes(&mut nonce).unwrap();
        self.nonce = nonce.to_vec();
        encode_with_nonce(message, &self.key, &Nonce::from(nonce), timestamp)
    }
pub fn encode ( & mut self , message : & [ u8 ] ) -> Result < String , BrancaError > { // A timestamp has not been manually set, so we create one automatically. let mut timestamp = self . timestamp ; if timestamp == 0 { // Generate a timestamp instead of a zero supplied one. let ts = SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) . expect ( " " ) ; timestamp = ts . as_secs ( ) as u32 ; } // Generate Nonce (24 bytes in length) let mut nonce = [ 0 ; XCHACHA_NONCESIZE ] ; secure_rand_bytes ( & mut nonce ) . unwrap ( ) ; self . nonce = nonce . to_vec ( ) ; encode_with_nonce ( message , & self . key , & Nonce :: from ( nonce ) , timestamp ) }
Encodes the message with the created Branca struct.
Encodes the message with the created Branca struct .
&mut self
message
&[u8]
example
```rust
extern crate getrandom;
extern crate branca;
use branca::Branca.

fn main() {
let mut key = [0u8; 32];
getrandom::getrandom(&mut key).unwrap();
let mut token = Branca::new(&key).unwrap().

let ciphertext = token.encode(b"Hello World!").unwrap();
Branca token is now in 'ciphertext' as a String.
` ` ` rust extern crate getrandom ; extern crate branca ; use branca :: Branca . fn main () { let mut key = [ 0u8 ; 32 ] ; getrandom :: getrandom ( &mut key ) . unwrap () ; let mut token = Branca :: new ( &key ) . unwrap () . let ciphertext = token . encode ( b " Hello World! " ) . unwrap () ; Branca token is now in ' ciphertext ' as a String .