crystal-cbor-fido

Deterministic Canonical CBOR (RFC 8949/CTAP2) encoder and decoder
0.1.1 released

crystal-cbor-fido

CI License: AGPL v3

A high-performance, strictly compliant, and constant-time Canonical CBOR (RFC 8949) encoder and decoder implementation for Crystal, tailored for FIDO2 and CTAP2 hardware security keys.

Features

  • Strict Canonical CBOR Compliance: Enforces deterministic key ordering (length first, then lexicographical order) and rejects duplicate map keys.
  • IEEE 754 Half-Precision (Float16) Support: Full bitwise manipulation with exact conversion and representation verification.
  • Constant-Time Security: Safe byte comparisons and bounds checking to mitigate timing side-channels.
  • Hash-DoS Protection: Employs SipHash-2-4 for dictionary key hashing.
  • Zero Allocations & Overflow Safety: Wrapping arithmetic (&+, &-) and explicit memory boundaries.

Installation

Add this to your application's shard.yml:

dependencies:
  crystal-cbor-fido:
    github: renich/crystal-cbor-fido
    version: ~> 0.1.1

Then run:

shards install

Usage

require "crystal-cbor-fido"

# Encoding a canonical CBOR payload
io = IO::Memory.new
encoder = Crystal::Cbor::Fido::Encoder.new(io)

data = {} of Crystal::Cbor::Fido::Value => Crystal::Cbor::Fido::Value
data["user_id"] = 100_i64
data["challenge"] = "rand123"

encoder.encode(data)
bytes = io.to_slice
puts "Encoded CBOR (Hex): #{bytes.hexstring}"

# Decoding canonical CBOR payload
decoder = Crystal::Cbor::Fido::Decoder.new(IO::Memory.new(bytes))
decoded_data = decoder.decode
puts "Decoded Data: #{decoded_data.inspect}"

Development & Verification

Build targets and test suites are managed via GNU Make:

make all      # Runs linting (Ameba & Flaw) and the full test suite
make test     # Executes crystal spec
make lint     # Executes Ameba static analysis and Flaw scanner
make docs     # Generates API documentation into docs/technical/api

Documentation

License

This project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later).

crystal-cbor-fido:
  gitlab: renich/crystal-cbor-fido
  version: ~> 0.1.1
Crystal >= 1.19.1

Authors

Dependencies 0

Development Dependencies 2

  • ameba
    {'github' => 'crystal-ameba/ameba'}
  • flaw
    {'github' => 'kdairatchi/flaw'}

Dependents 0

Last synced .
search fire star recently