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
impl DynamicCode
Sourcepub fn derive(
h: &[u8; 32],
nonce_a: &[u8; 32],
nonce_b: &[u8; 32],
) -> DynamicCode
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.
Sourcepub fn digits(&self) -> [u8; 6]
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");Sourcepub fn digits_text(&self) -> String
pub fn digits_text(&self) -> String
Returns the six digits as text, ready for a display or a speaker.
Sourcepub fn qr_payload(&self) -> [u8; 24]
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.