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 |
Fields
pk: PublicKey
Long-term PublicKey
.
Methods
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 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]);
pub fn new(pk: PublicKey) -> Self
[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);
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 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]
fn clone(&self) -> ToxId
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for ToxId
[src]
impl Debug for ToxId
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Eq for ToxId
[src]
impl PartialEq for ToxId
[src]
fn eq(&self, __arg_0: &ToxId) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &ToxId) -> bool
[src]
This method tests for !=
.
impl FromBytes for ToxId
[src]
fn parse_bytes(i: &[u8]) -> IResult<&[u8], Self, u32>
De-serialize from bytes.
fn parse_bytes_multiple<'a>(bytes: &'a [u8]) -> ParseResult<Vec<Self>>
[src]
De-serialize as many entities from bytes as posible. Note that even if Vec<_>
is returned, it still can be empty. Read more
fn parse_bytes_multiple_n<'a>(
bytes: &'a [u8],
times: usize
) -> ParseResult<Vec<Self>>
[src]
bytes: &'a [u8],
times: usize
) -> ParseResult<Vec<Self>>
De-serialize exact times
entities from bytes. Note that even if Vec<_>
is returned, it still can be empty. Read more
fn from_bytes(bytes: &[u8]) -> Option<Self>
[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]);
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");
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));