Skip to main content

decode

Function decode 

Source
pub fn decode(token: &str) -> Result<Token>
Expand description

Decodes a pairing token, or reports why the input is not one.

Lenient about operator formatting: surrounding whitespace is trimmed, ASCII case is folded and the leading SP: is optional. Everything else follows the spec: the first remaining character is the version, it must be one this crate defines, and the payload must be at least as long as that version defines. Bytes past that length are reserved for future extension and are dropped, so Token::payload always has exactly the version’s length. Errors name a rule or a length and never echo the input.

§Example

use syncspin_core::pairing::token::decode;

// The spec's version-1 vector for the code 0xe0..=0xf7.
let token = decode("SP:14DQ6FY7E4XTOP9HJ5LV6Z3PO57YPD4XT6T97N5Y").expect("version 1");
assert_eq!(token.version, 1);
assert_eq!(token.payload, (0xe0..=0xf7).collect::<Vec<u8>>());