gose/cose/key

COSE_Key encoding and decoding (RFC 9052).

Converts between gose/key.Key and COSE_Key CBOR representations.

Example

import gose/cose/key as cose_key
import gose/key
import kryptos/ec

// Generate an EC key and attach a binary kid (COSE uses BitArray kids)
let k =
  key.generate_ec(ec.P256)
  |> key.with_kid_bits(<<"my-key":utf8>>)

// Serialize to CBOR
let assert Ok(bytes) = cose_key.to_cbor(k)

// Parse from CBOR
let assert Ok(parsed) = cose_key.from_cbor(bytes)
let assert Ok(kid) = key.kid(parsed)
assert kid == <<"my-key":utf8>>

Types

A key with a COSE-compatible binary kid.

pub type Key =
  key.Key(BitArray)

Values

pub fn from_cbor(
  data: BitArray,
) -> Result(key.Key(BitArray), gose.GoseError)

Decode COSE_Key from CBOR bytes to a Key.

pub fn from_cbor_map(
  map: List(#(cbor.Value, cbor.Value)),
) -> Result(key.Key(BitArray), gose.GoseError)

Decode from CBOR map entries.

pub fn to_cbor(
  k: key.Key(BitArray),
) -> Result(BitArray, gose.GoseError)

Encode a Key to COSE_Key CBOR bytes.

pub fn to_cbor_map(
  k: key.Key(BitArray),
) -> Result(List(#(cbor.Value, cbor.Value)), gose.GoseError)

Encode to CBOR map entries (for embedding in larger CBOR structures).

Search Document