Struct tox::toxcore::toxid::ToxId [] [src]

pub struct ToxId {
    pub pk: PublicKey,
    // some fields omitted
}

Tox ID.

Length Contents
32 long term PublicKey
4 NoSpam
2 Checksum

https://zetok.github.io/tox-spec/#tox-id

Fields

Long-term PublicKey.

Methods

impl ToxId
[src]

[src]

Checksum of PublicKey and NoSpam.

https://zetok.github.io/tox-spec/#tox-id , 4th paragraph.

E.g.

use self::tox::toxcore::crypto_core::{
           gen_keypair,
           PublicKey,
           PUBLICKEYBYTES,
   };
   use self::tox::toxcore::toxid::{NoSpam, NOSPAMBYTES, ToxId};

   let (pk, _) = gen_keypair();
   let nospam = NoSpam::new();

   let _checksum = ToxId::checksum(&pk, &nospam);

   assert_eq!(ToxId::checksum(&PublicKey([0; PUBLICKEYBYTES]),
              &NoSpam([0; NOSPAMBYTES])), [0; 2]);
   assert_eq!(ToxId::checksum(&PublicKey([0xff; PUBLICKEYBYTES]),
              &NoSpam([0xff; NOSPAMBYTES])), [0; 2]);

[src]

Create new ToxId.

E.g.

use self::tox::toxcore::crypto_core::gen_keypair;
   use self::tox::toxcore::toxid::ToxId;

   let (pk, _) = gen_keypair();
   let _toxid = ToxId::new(pk);

[src]

Change NoSpam. If provided, change to provided value. If not provided (None), generate random NoSpam.

After NoSpam change PublicKey is always the same, but NoSpam and checksum differ:

use self::tox::toxcore::crypto_core::gen_keypair;
use self::tox::toxcore::toxid::{NoSpam, ToxId};

let (pk, _) = gen_keypair();
let toxid = ToxId::new(pk);
let mut toxid2 = toxid;
toxid2.new_nospam(None);

assert!(toxid != toxid2);
assert_eq!(toxid.pk, toxid2.pk);

let mut toxid3 = toxid;

// with same `NoSpam` IDs are identical
let nospam = NoSpam::new();
toxid2.new_nospam(Some(nospam));
toxid3.new_nospam(Some(nospam));
assert_eq!(toxid2, toxid3);

Trait Implementations

impl Clone for ToxId
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for ToxId
[src]

impl Debug for ToxId
[src]

[src]

Formats the value using the given formatter. Read more

impl Eq for ToxId
[src]

impl PartialEq for ToxId
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl FromBytes for ToxId
[src]

De-serialize from bytes.

[src]

De-serialize as many entities from bytes as posible. Note that even if Vec<_> is returned, it still can be empty. Read more

[src]

De-serialize exact times entities from bytes. Note that even if Vec<_> is returned, it still can be empty. Read more

[src]

De-serialize from bytes, or return None if de-serialization failed. Note: Some is returned even if there are remaining bytes left. Read more

impl ToBytes for ToxId
[src]

E.g.

use self::tox::toxcore::binary_io::ToBytes;
use self::tox::toxcore::crypto_core::{gen_keypair, PublicKey, PUBLICKEYBYTES};
use self::tox::toxcore::toxid::{NoSpam, NOSPAMBYTES, ToxId, TOXIDBYTES};

// create a `0` Tox ID
let mut toxid = ToxId::new(PublicKey([0; PUBLICKEYBYTES]));
toxid.new_nospam(Some(NoSpam([0; NOSPAMBYTES])));
let toxid_bytes = toxid.to_bytes();
assert_eq!([0; TOXIDBYTES].to_vec(), toxid_bytes);


// and a random one
let (pk, _) = gen_keypair();
let PublicKey(ref pk_bytes) = pk;
let toxid_bytes = ToxId::new(pk).to_bytes();
assert_eq!(pk_bytes, &toxid_bytes[..PUBLICKEYBYTES]);

[src]

Serialize into bytes.

impl UpperHex for ToxId
[src]

The default formatting for ToxId.

E.g.

use self::tox::toxcore::crypto_core::{PublicKey, PUBLICKEYBYTES};
use self::tox::toxcore::toxid::{NoSpam, NOSPAMBYTES, ToxId};

let mut toxid = ToxId::new(PublicKey([0; PUBLICKEYBYTES]));
toxid.new_nospam(Some(NoSpam([0; NOSPAMBYTES])));
// 76 `0`s
assert_eq!(&format!("{:X}", toxid),
    "0000000000000000000000000000000000000000000000000000000000000000000000000000");

let mut toxid = ToxId::new(PublicKey([255; PUBLICKEYBYTES]));
toxid.new_nospam(Some(NoSpam([255; NOSPAMBYTES])));
// 72 `F`s + 4 `0`s
assert_eq!(&format!("{:X}", toxid),
    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000");

[src]

Formats the value using the given formatter.

impl Display for ToxId
[src]

Same as UpperHex.

E.g.

use self::tox::toxcore::crypto_core::gen_keypair;
use self::tox::toxcore::toxid::ToxId;

let (pk, _) = gen_keypair();
let toxid = ToxId::new(pk);
assert_eq!(format!("{}", toxid), format!("{:X}", toxid));

[src]

Formats the value using the given formatter. Read more