[][src]Struct tox_packet::toxid::ToxId

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

Tox ID.

LengthContents
32long term PublicKey
4NoSpam
2Checksum

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

Fields

pk: PublicKey

Long-term PublicKey.

Implementations

impl ToxId[src]

pub fn checksum(PublicKey: &PublicKey, nospam: NoSpam) -> [u8; 2][src]

Checksum of PublicKey and NoSpam.

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

E.g.

use tox_crypto::{
        gen_keypair,
        PublicKey,
        PUBLICKEYBYTES,
};
use tox_packet::toxid::{NoSpam, NOSPAMBYTES, ToxId};

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

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]);

pub fn new(pk: PublicKey) -> Self[src]

Create new ToxId.

E.g.

use tox_crypto::gen_keypair;
use tox_packet::toxid::ToxId;

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

pub fn new_nospam(&mut self, nospam: Option<NoSpam>)[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 tox_crypto::gen_keypair;
use tox_packet::toxid::{NoSpam, ToxId};

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

assert_ne!(toxid, toxid2);
assert_eq!(toxid.pk, toxid2.pk);

let mut toxid3 = toxid;

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

Trait Implementations

impl Clone for ToxId[src]

impl Copy for ToxId[src]

impl Debug for ToxId[src]

impl Display for ToxId[src]

Same as UpperHex.

E.g.

use tox_crypto::gen_keypair;
use tox_packet::toxid::ToxId;

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

impl Eq for ToxId[src]

impl FromBytes for ToxId[src]

impl PartialEq<ToxId> for ToxId[src]

impl StructuralEq for ToxId[src]

impl StructuralPartialEq for ToxId[src]

impl ToBytes for ToxId[src]

impl UpperHex for ToxId[src]

The default formatting for ToxId.

E.g.

use tox_crypto::{PublicKey, PUBLICKEYBYTES};
use tox_packet::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");

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.