wolfcose 0.1.0

Safe Rust API for wolfSSL wolfCOSE.
#![allow(missing_docs)]

use wolfcose::{Algorithm, CoseKey, CoseKeyBuilder, CoseKeyView, Error};

fn aes_key() -> CoseKey {
    CoseKeyBuilder::symmetric([0x11; 16])
        .algorithm(Algorithm::A128GCM)
        .kid(b"aes")
        .build()
        .unwrap()
}

#[test]
fn cose_key_encode_decode_and_metadata_round_trip() {
    let mut key = aes_key();
    let mut encoded = [0; 256];
    let encoded = key.encode_into(&mut encoded).unwrap().to_vec();
    assert_eq!(key.encode_to_vec().unwrap(), encoded);

    let mut decoded = CoseKey::new().unwrap();
    decoded.decode(&encoded).unwrap();
    let view = CoseKeyView::from_key(&decoded);
    assert_eq!(view.algorithm, Algorithm::A128GCM);
    assert_eq!(view.symmetric_len, None);

    let mut too_small = [0; 1];
    assert_eq!(key.encode_into(&mut too_small), Err(Error::BufferTooSmall));
    assert_eq!(
        CoseKey::new().unwrap().decode(b"not-cbor"),
        Err(Error::CborMalformed)
    );
}