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
pk: PublicKey
Long-term PublicKey
.
Methods
impl ToxId
[src]
impl ToxId
pub fn checksum(PublicKey: &PublicKey, nospam: NoSpam) -> [u8; 2]
[src]
pub fn checksum(PublicKey: &PublicKey, nospam: NoSpam) -> [u8; 2]
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]
pub fn new(pk: PublicKey) -> Self
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]
pub fn new_nospam(&mut self, nospam: Option<NoSpam>)
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]
impl Clone for ToxId
fn clone(&self) -> ToxId
[src]
fn clone(&self) -> ToxId
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Copy for ToxId
[src]
impl Copy for ToxId
impl Debug for ToxId
[src]
impl Debug for ToxId
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Eq for ToxId
[src]
impl Eq for ToxId
impl PartialEq for ToxId
[src]
impl PartialEq for ToxId
fn eq(&self, other: &ToxId) -> bool
[src]
fn eq(&self, other: &ToxId) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &ToxId) -> bool
[src]
fn ne(&self, other: &ToxId) -> bool
This method tests for !=
.
impl FromBytes for ToxId
[src]
impl FromBytes for ToxId
fn from_bytes<'a>(i: &'a [u8]) -> IResult<&'a [u8], ToxId, u32>
fn from_bytes<'a>(i: &'a [u8]) -> IResult<&'a [u8], ToxId, u32>
Deserialize struct using nom
from raw bytes
impl ToBytes for ToxId
[src]
impl ToBytes for ToxId
fn to_bytes<'a>(
&self,
buf: (&'a mut [u8], usize)
) -> Result<(&'a mut [u8], usize), GenError>
[src]
fn to_bytes<'a>(
&self,
buf: (&'a mut [u8], usize)
) -> Result<(&'a mut [u8], usize), GenError>
Serialize struct into raw bytes using cookie_factory
impl UpperHex for ToxId
[src]
impl UpperHex for ToxId
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]
impl Display for ToxId
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));