Skip to main content

parse

Function parse 

Source
pub fn parse(header: &str) -> Option<ParsedSignature>
Expand description

Decompose an X-Tango-Signature header value.

Accepts both the canonical "sha256=<hex>" form and a bare hex string (legacy compatibility); in the bare-hex case algorithm defaults to "sha256". Returns None for empty, malformed, or non-hex inputs.

ยงExamples

use tango_webhooks::parse;

let canonical = parse("sha256=0e396369ee043c5b6b922743631745b2249cf7cb2c4722e61e802447d5d14c70")
    .expect("canonical form parses");
assert_eq!(canonical.algorithm, "sha256");
assert_eq!(canonical.signature.len(), 64);

// Bare hex (legacy) defaults to sha256.
let bare = parse("0e396369ee043c5b6b922743631745b2249cf7cb2c4722e61e802447d5d14c70")
    .expect("bare hex parses");
assert_eq!(bare.algorithm, "sha256");

// Garbage in, None out.
assert!(parse("").is_none());
assert!(parse("   ").is_none());
assert!(parse("sha256=").is_none());
assert!(parse("sha256=zzzz").is_none());
assert!(parse("not-hex").is_none());