cmw

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2025 License: Apache-2.0 Imports: 15 Imported by: 8

README

RATS Conceptual Message Wrappers

Package cmw is a golang implementation of draft-ietf-rats-msg-wrap.

Documentation

Overview

auto-generated (see utils/README.md)

Example (Decode_CBOR_record)
var o CMW

b := mustHexDecode(`83781d6170706c69636174696f6e2f7369676e65642d636f72696d2b63626f724dd901f6d28440a044d901f5a04003`)

if err := o.UnmarshalCBOR(b); err != nil {
	log.Fatalf("unmarshal CBOR record failed: %v", err)
}

fmt.Printf("CMW format: %s\n", o.GetFormat())
actualType, _ := o.GetMonadType()
fmt.Printf("type: %s\n", actualType)
actualValue, _ := o.GetMonadValue()
fmt.Printf("value (hex): %x\n", actualValue)
actualIndicator, _ := o.GetMonadIndicator()
fmt.Printf("indicator: %s\n", actualIndicator)
Output:

CMW format: CBOR record
type: application/signed-corim+cbor
value (hex): d901f6d28440a044d901f5a040
indicator: endorsements, reference values
Example (Decode_JSON_record)
var o CMW

err := o.UnmarshalJSON([]byte(`[ "application/vnd.example.rats-conceptual-msg", "I0faVQ", 3 ]`))
if err != nil {
	log.Fatalf("unmarshal JSON record failed: %v", err)
}

fmt.Printf("CMW format: %s\n", o.GetFormat())
actualType, _ := o.GetMonadType()
fmt.Printf("type: %s\n", actualType)
actualValue, _ := o.GetMonadValue()
fmt.Printf("value (hex): %x\n", actualValue)
actualIndicator, _ := o.GetMonadIndicator()
fmt.Printf("indicator: %s\n", actualIndicator)
Output:

CMW format: JSON record
type: application/vnd.example.rats-conceptual-msg
value (hex): 2347da55
indicator: endorsements, reference values
Example (Encode_CBOR_collection)
root := makeCMWCollection()

b, err := root.MarshalCBOR()
if err != nil {
	log.Fatalf("marshal to CBOR failed: %v", err)
}

edn, _ := cbor.Diagnose(b)

fmt.Println(edn)
Output:

{"__cmwc_t": "tag:ietf.org,2024:X", "murmurless": {"__cmwc_t": "tag:ietf.org,2024:Y", "polyscopic": ["application/eat-ucs+json", h'7b226561745f6e6f6e6365223a202e2e2e7d', 8]}, "bretwaldadom": ["application/eat-ucs+cbor", h'a10a'], "photoelectrograph": ["application/eat-ucs+cbor", h'827818', 3]}
Example (Encode_JSON_collection)
root := makeCMWCollection()

b, err := root.MarshalJSON()
if err != nil {
	log.Fatalf("marshal to JSON failed: %v", err)
}

fmt.Println(string(b))
Output:

{"__cmwc_t":"tag:ietf.org,2024:X","bretwaldadom":["application/eat-ucs+cbor","oQo"],"murmurless":{"__cmwc_t":"tag:ietf.org,2024:Y","polyscopic":["application/eat-ucs+json","eyJlYXRfbm9uY2UiOiAuLi59",8]},"photoelectrograph":["application/eat-ucs+cbor","gngY",3]}
Example (Get_meta)
root := makeCMWCollection()

meta, _ := root.GetCollectionMeta()

for _, m := range meta {
	fmt.Printf("%s: %s\n", m.Key, m.Kind)
}
Output:

bretwaldadom: monad
murmurless: collection
photoelectrograph: monad
Example (Roundtrip_JSON_collection)
var o CMW

ex := []byte(`{
  "bretwaldadom": [
    "application/eat-ucs+cbor",
    "oQo"
  ],
  "__cmwc_t": "tag:ietf.org,2024:X",
  "json-raw": [
    "application/vnd.my.ref-val",
    "e30K"
  ],
  "murmurless": {
    "__cmwc_t": "tag:ietf.org,2024:Y",
    "polyscopic": [
      "application/eat-ucs+json",
      "eyJlYXRfbm9uY2UiOiAuLi59",
      8
    ]
  },
  "photoelectrograph": [
    "application/eat-ucs+cbor",
    "gngY",
    3
  ]
}`)

err := o.Deserialize(ex)
if err != nil {
	log.Fatalf("unmarshal JSON collection failed: %v", err)
}

b, err := o.MarshalJSON()
if err != nil {
	log.Fatalf("marshal collection to JSON failed: %v", err)
}

fmt.Println(string(b))
Output:

{"__cmwc_t":"tag:ietf.org,2024:X","bretwaldadom":["application/eat-ucs+cbor","oQo"],"json-raw":["application/vnd.my.ref-val","e30K"],"murmurless":{"__cmwc_t":"tag:ietf.org,2024:Y","polyscopic":["application/eat-ucs+json","eyJlYXRfbm9uY2UiOiAuLi59",8]},"photoelectrograph":["application/eat-ucs+cbor","gngY",3]}

Index

Examples

Constants

View Source
const (
	KindUnknown = Kind(iota)
	KindMonad
	KindCollection
)
View Source
const (
	FormatUnknown = Format(iota)
	// JSON formats
	FormatJSONRecord
	FormatJSONCollection
	// CBOR formats
	FormatCBORRecord
	FormatCBORCollection
	FormatCBORTag
)
View Source
const (
	ReferenceValues = 1 << iota
	Endorsements
	Evidence
	AttestationResults
	TrustAnchors
)
View Source
const (
	CfMin = uint16(0)
	CfMax = uint16(65024)
)
View Source
const (
	TnMin = uint64(1668546817)
	TnMax = uint64(1668612095)
)
View Source
const (
	ChoiceJson = Choice(iota)
	ChoiceCbor
)
View Source
const CmwCType string = "__cmwc_t"
View Source
const IndicatorNone = 0

Variables

View Source
var OidExtCmw = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 1, 35}

Functions

func CF

func CF(tn uint64) (uint16, error)

CF computes CoAP Content-Format IDs from CBOR Tag numbers

func TN

func TN(cf uint16) (uint64, error)

TN computes CBOR Tag numbers from CoAP Content-Format IDs

Types

type CMW

type CMW struct {
	// contains filtered or unexported fields
}

CMW holds the internal representation of a RATS conceptual message wrapper

func DecodeX509Extension added in v0.2.0

func DecodeX509Extension(extn pkix.Extension) (*CMW, error)

DecodeX509Extension extracts and decodes the CMW from the supplied id-pe-cmw extension.

func NewCollection added in v0.2.0

func NewCollection(cmwct string) (*CMW, error)

NewCollection instantiate a new Collection CMW with the supplied __cmwc_t Pass an empty string to avoid setting __cmwc_t

func NewMonad added in v0.2.0

func NewMonad(mediaType any, value []byte, indicators ...Indicator) (*CMW, error)

func (*CMW) AddCollectionItem added in v0.2.0

func (o *CMW) AddCollectionItem(key any, node *CMW) error

func (*CMW) Deserialize

func (o *CMW) Deserialize(b []byte) error

func (CMW) EncodeX509Extension added in v0.2.0

func (o CMW) EncodeX509Extension(choice Choice, critical bool) (*pkix.Extension, error)

EncodeX509Extension encodes the target CMW as either JSON or CBOR (according to the specified choice), and wraps it in a X509 extension that can be used in Certificates, CSRs, or other PKIX data items. Unless you really know what you are doing, critical SHOULD be set to false.

func (CMW) GetCollectionItem added in v0.2.0

func (o CMW) GetCollectionItem(key any) (*CMW, error)

func (*CMW) GetCollectionMeta added in v0.2.0

func (o *CMW) GetCollectionMeta() ([]Meta, error)

GetCollectionMeta retrieves a (sorted) list of keys and associated types in a collection

func (CMW) GetCollectionType added in v0.2.0

func (o CMW) GetCollectionType() (string, error)

GetCollectionType returns the Collection CMW's __cmwc_t If __cmwc_t is not set, an empty string is returned

func (CMW) GetFormat added in v0.2.0

func (o CMW) GetFormat() Format

func (CMW) GetKind added in v0.2.0

func (o CMW) GetKind() Kind

func (CMW) GetMonadIndicator added in v0.2.0

func (o CMW) GetMonadIndicator() (Indicator, error)

func (CMW) GetMonadType added in v0.2.0

func (o CMW) GetMonadType() (string, error)

func (CMW) GetMonadValue added in v0.2.0

func (o CMW) GetMonadValue() ([]byte, error)

func (CMW) MarshalCBOR

func (o CMW) MarshalCBOR() ([]byte, error)

func (CMW) MarshalJSON

func (o CMW) MarshalJSON() ([]byte, error)

func (*CMW) UnmarshalCBOR

func (o *CMW) UnmarshalCBOR(b []byte) error

func (*CMW) UnmarshalJSON

func (o *CMW) UnmarshalJSON(b []byte) error

func (*CMW) UseCBORTagFormat added in v0.2.0

func (o *CMW) UseCBORTagFormat()

func (CMW) ValidateCollection added in v0.2.0

func (o CMW) ValidateCollection() error

type Choice added in v0.2.0

type Choice uint

type Format added in v0.2.0

type Format uint

func Sniff added in v0.2.0

func Sniff(b []byte) Format

func (Format) String added in v0.2.0

func (o Format) String() string

type Indicator

type Indicator uint

Indicator is the internal representation of the `ind` bit map

func (*Indicator) Clear

func (o *Indicator) Clear(v Indicator)

func (Indicator) Empty

func (o Indicator) Empty() bool

func (Indicator) Has

func (o Indicator) Has(v Indicator) bool

func (*Indicator) Set

func (o *Indicator) Set(v Indicator)

func (Indicator) String added in v0.2.0

func (o Indicator) String() string

func (*Indicator) Toggle

func (o *Indicator) Toggle(v Indicator)

type Kind added in v0.2.0

type Kind uint

func (Kind) String added in v0.2.0

func (o Kind) String() string

type Meta added in v0.2.0

type Meta struct {
	Key  any
	Kind Kind
}

type Type

type Type struct {
	// contains filtered or unexported fields
}

func (Type) IsSet

func (o Type) IsSet() bool

func (Type) MarshalCBOR

func (o Type) MarshalCBOR() ([]byte, error)

func (Type) MarshalJSON

func (o Type) MarshalJSON() ([]byte, error)

func (*Type) Set

func (o *Type) Set(v any) error

func (Type) String

func (o Type) String() string

func (Type) TagNumber

func (o Type) TagNumber() (uint64, error)

func (*Type) UnmarshalCBOR

func (o *Type) UnmarshalCBOR(b []byte) error

func (*Type) UnmarshalJSON

func (o *Type) UnmarshalJSON(b []byte) error

type Value

type Value []byte

func (Value) IsSet

func (o Value) IsSet() bool

func (Value) MarshalCBOR

func (o Value) MarshalCBOR() ([]byte, error)

func (Value) MarshalJSON

func (o Value) MarshalJSON() ([]byte, error)

func (*Value) Set

func (o *Value) Set(v []byte) error

func (*Value) UnmarshalCBOR

func (o *Value) UnmarshalCBOR(b []byte) error

func (*Value) UnmarshalJSON

func (o *Value) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL