[−][src]Struct tox_packet::toxid::ToxId
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
.
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]
pub fn to_bytes<'a>(
&self,
buf: (&'a mut [u8], usize)
) -> Result<(&'a mut [u8], usize), GenError>
[src]
&self,
buf: (&'a mut [u8], usize)
) -> Result<(&'a mut [u8], usize), GenError>
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
impl RefUnwindSafe for ToxId
[src]
impl Send for ToxId
[src]
impl Sync for ToxId
[src]
impl Unpin for ToxId
[src]
impl UnwindSafe for ToxId
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,