Skip to main content

DynamicCode

Struct DynamicCode 

Source
pub struct DynamicCode { /* private fields */ }
Expand description

The digest both sides derive the pairing code from.

One value serves both emission formats, so neither side has to know which format the client chose before it derives. The digest does not include the emission format: the digits code and the qr_code code of one digest are two views of the same binding.

Implementations§

Source§

impl DynamicCode

Source

pub fn derive( h: &[u8; 32], nonce_a: &[u8; 32], nonce_b: &[u8; 32], ) -> DynamicCode

Derives the digest from the handshake hash and the two nonces.

All three are raw, concatenated after the label without a separator. h is the Noise handshake hash, nonce_a the server’s nonce from the first round’s server/pair-init and nonce_b this client’s own nonce, which stays private until client/pair-confirm.

Source

pub fn digits(&self) -> [u8; 6]

Returns the six ASCII digits of the digits emission format.

The digest is read as an unsigned big-endian 256-bit integer and reduced modulo 10^6, then written left-padded with zeroes to exactly six characters. Those six bytes are also the code’s CPace PRS.

use syncspin_core::pairing::code::DynamicCode;

// Fixed inputs, so the digits are a vector: h = 0x00..=0x1f, nonce_A = 0x40..=0x5f,
// nonce_B = 0x80..=0x9f.
let code = DynamicCode::derive(
    &std::array::from_fn(|index| index as u8),
    &std::array::from_fn(|index| 0x40 + index as u8),
    &std::array::from_fn(|index| 0x80 + index as u8),
);
assert_eq!(code.digits_text(), "782070");
Source

pub fn digits_text(&self) -> String

Returns the six digits as text, ready for a display or a speaker.

Source

pub fn qr_payload(&self) -> [u8; 24]

Returns the 24-byte code of the qr_code emission format.

These are digest[0..24], raw: they are the code’s CPace PRS and the payload of the version-1 token a display renders.

Source

pub fn qr_token(&self) -> String

Returns the qr_code emission of the code: a version-1 pairing token string.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.