NAME

Web::Authn::CBOR - Small CTAP2-oriented CBOR codec

SYNOPSIS

my $bin = Web::Authn::CBOR::encode({ 1 => 2, 3 => -7, -2 => \$bytes });
my ($value, $consumed) = Web::Authn::CBOR::decode($bin);

DESCRIPTION

WebAuthn attestation objects, authenticator data public keys, and attestation statements are CBOR. This codec covers the subset CTAP2 uses: unsigned and negative integers, byte strings, text strings, arrays, maps (integer or string keys), and tags (decoded, tag number discarded).

Duplicate map keys are rejected, as CTAP2 requires.

FUNCTIONS

decode

my $value = Web::Authn::CBOR::decode( $bin );
my( $value, $consumed ) = Web::Authn::CBOR::decode( $bin );

Decodes a CBOR blob. In list context it returns ($value, $bytes_consumed); in scalar context it returns only the value. Pass the raw CBOR bytes. The function dies with Web::Authn::Exception::InvalidStructure on truncated or illegal input.

encode

my $bin = Web::Authn::CBOR::encode({ 1 => 2, 3 => -7, -2 => \$bytes });

Encodes a Perl structure to CBOR. Pass an undef, an integer, a string, a scalar reference (to force a major-type-2 byte string), an array, or a hash. Plain strings that look printable are emitted as text strings. Blessed objects that overload "" are stringified first.

encode_bstr

my $bin = Web::Authn::CBOR::encode_bstr( $octets );

Encodes raw octets as a CBOR major-type-2 byte string. Pass the byte string to wrap.

THREAD & PROCESS SAFETY

This module is designed to be fully thread-safe and process-safe, ensuring data integrity across Perl ithreads and mod_perl’s threaded Multi-Processing Modules (MPMs) such as Worker or Event.

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

RFC 8949, FIDO CTAP2 canonical CBOR, Web::Authn::Parse

COPYRIGHT & LICENSE

Copyright(c) 2026 DEGUEST Pte. Ltd.

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.