diff --git a/3rdparty/internal/cose-openssl/Cargo.toml b/3rdparty/internal/cose-openssl/Cargo.toml index 46684c04bccb..a4e7425a4434 100644 --- a/3rdparty/internal/cose-openssl/Cargo.toml +++ b/3rdparty/internal/cose-openssl/Cargo.toml @@ -14,5 +14,4 @@ warnings = "deny" [dependencies] openssl-sys = "0.9" -cborrs = { git = "https://github.com/project-everest/everparse.git", rev = "950bc93838ac2faae51126d8acd0637cf8c8a569" } # v2026.07.02 -cborrs-nondet = { git = "https://github.com/project-everest/everparse.git", rev = "950bc93838ac2faae51126d8acd0637cf8c8a569" } # v2026.07.02 +cbor = { package = "tee-attestation-verification-cbor", path = "../tee-attestation-verification/cbor" } diff --git a/3rdparty/internal/cose-openssl/src/cbor.rs b/3rdparty/internal/cose-openssl/src/cbor.rs deleted file mode 100644 index ba6c38507591..000000000000 --- a/3rdparty/internal/cose-openssl/src/cbor.rs +++ /dev/null @@ -1,638 +0,0 @@ -use cborrs::cbordet::*; -use cborrs_nondet::cbornondet::*; - -struct SimpleArena(std::cell::RefCell>>); - -impl SimpleArena { - fn new() -> Self { - Self(std::cell::RefCell::new(Vec::new())) - } - - fn alloc(&self, val: T) -> &mut T { - self.alloc_extend(std::iter::once(val)).first_mut().unwrap() - } - - fn alloc_extend(&self, vals: impl IntoIterator) -> &mut [T] { - let boxed: Box<[T]> = vals.into_iter().collect(); - let mut store = self.0.borrow_mut(); - store.push(boxed); - let slot = store.last_mut().unwrap(); - // SAFETY: The returned reference borrows `self`, which owns the - // backing storage. Items are never moved or removed, so the - // reference remains valid for the lifetime of the arena. - unsafe { &mut *(slot.as_mut() as *mut [T]) } - } -} - -/// An owned CBOR value supporting arbitrary nesting. -/// -/// Covers the major CBOR types: integers, simple values, byte/text strings, -/// arrays, maps, and tagged values. Unlike [`CborNondet`], this type owns -/// all its data and can be freely stored, cloned, and nested. -#[derive(Clone, PartialEq)] -pub enum CborValue { - Int(i64), - Simple(u8), - ByteString(Vec), - TextString(String), - Array(Vec), - Map(Vec<(CborValue, CborValue)>), - Tagged { tag: u64, payload: Box }, -} - -impl CborValue { - /// Parse CBOR bytes into an owned `CborValue`. - pub fn from_bytes(bytes: &[u8]) -> Result { - let (item, remainder) = cbor_nondet_parse(None, false, bytes) - .ok_or("Failed to parse CBOR bytes")?; - if !remainder.is_empty() { - return Err(format!( - "Trailing bytes: {} unconsumed byte(s)", - remainder.len() - )); - } - Self::from_raw(item) - } - - /// Serialize this value to deterministic CBOR bytes. - pub fn to_bytes(&self) -> Result, String> { - let item_arena: SimpleArena> = SimpleArena::new(); - let entry_arena: SimpleArena> = SimpleArena::new(); - let raw = self.to_raw(&item_arena, &entry_arena)?; - serialize_det(raw) - } - - /// Build a `CborDet` tree without serializing. - /// - /// Child nodes are allocated in the arenas so they stay alive long enough - /// for the parent to borrow them. The caller serializes the returned root - /// exactly once. - fn to_raw<'a>( - &'a self, - items: &'a SimpleArena>, - entries: &'a SimpleArena>, - ) -> Result, String> { - match self { - CborValue::Int(v) => { - let (kind, raw) = Self::i64_to_det_int(*v); - Ok(cbor_det_mk_int64(kind, raw)) - } - CborValue::Simple(v) => cbor_det_mk_simple_value(*v) - .ok_or("Failed to make CBOR simple value".to_string()), - CborValue::ByteString(b) => cbor_det_mk_byte_string(b) - .ok_or("Failed to make CBOR byte string".to_string()), - CborValue::TextString(s) => cbor_det_mk_text_string(s) - .ok_or("Failed to make CBOR text string".to_string()), - CborValue::Array(children) => { - let raw_children: Vec> = children - .iter() - .map(|c| c.to_raw(items, entries)) - .collect::>()?; - let slice = items.alloc_extend(raw_children); - cbor_det_mk_array(slice) - .ok_or("Failed to build CBOR array".to_string()) - } - CborValue::Map(map_entries) => { - let raw: Vec> = map_entries - .iter() - .map(|(k, v)| { - Ok(cbor_det_mk_map_entry( - k.to_raw(items, entries)?, - v.to_raw(items, entries)?, - )) - }) - .collect::>()?; - let slice = entries.alloc_extend(raw); - cbor_det_mk_map(slice) - .ok_or("Failed to build CBOR map".to_string()) - } - CborValue::Tagged { tag, payload } => { - let inner = payload.to_raw(items, entries)?; - let inner_ref = items.alloc(inner); - Ok(cbor_det_mk_tagged(*tag, inner_ref)) - } - } - } - - /// Get array element by index. Returns an error if not an array. - pub fn array_at(&self, index: usize) -> Result<&CborValue, String> { - match self { - CborValue::Array(items) => items - .get(index) - .ok_or_else(|| format!("Index {index} out of bounds")), - other => { - Err(format!("Expected Array, got {:?}", other.type_name())) - } - } - } - - /// Look up a map value by integer key. Returns an error if not a map. - pub fn map_at_int(&self, key: i64) -> Result<&CborValue, String> { - let target = CborValue::Int(key); - self.map_at(&target) - } - - /// Look up a map value by text string key. Returns an error if not a map. - pub fn map_at_str(&self, key: &str) -> Result<&CborValue, String> { - let target = CborValue::TextString(key.to_string()); - self.map_at(&target) - } - - /// Look up a map value by a CborValue key (must be Int or TextString). - /// Returns an error if not a map or if the key type is invalid. - pub fn map_at(&self, key: &CborValue) -> Result<&CborValue, String> { - match key { - CborValue::Int(_) | CborValue::TextString(_) => {} - _ => return Err("Map keys can only be Int or TextString".into()), - } - match self { - CborValue::Map(entries) => entries - .iter() - .find(|(k, _)| k == key) - .map(|(_, v)| v) - .ok_or_else(|| format!("Key {:?} not found in map", key)), - other => Err(format!("Expected Map, got {:?}", other.type_name())), - } - } - - /// Iterate over array elements. Returns an error if not an array. - pub fn iter_array( - &self, - ) -> Result, String> { - match self { - CborValue::Array(items) => Ok(items.iter()), - other => { - Err(format!("Expected Array, got {:?}", other.type_name())) - } - } - } - - /// Iterate over map entries as `(key, value)` pairs. - /// Returns an error if not a map. - pub fn iter_map( - &self, - ) -> Result, String> { - match self { - CborValue::Map(entries) => Ok(entries.iter().map(|(k, v)| (k, v))), - other => Err(format!("Expected Map, got {:?}", other.type_name())), - } - } - - /// Number of elements in an array or map. - /// Returns an error for other types. - pub fn len(&self) -> Result { - match self { - CborValue::Array(items) => Ok(items.len()), - CborValue::Map(entries) => Ok(entries.len()), - other => { - Err(format!("len() not applicable to {:?}", other.type_name())) - } - } - } - - fn type_name(&self) -> &'static str { - match self { - CborValue::Int(_) => "Int", - CborValue::Simple(_) => "Simple", - CborValue::ByteString(_) => "ByteString", - CborValue::TextString(_) => "TextString", - CborValue::Array(_) => "Array", - CborValue::Map(_) => "Map", - CborValue::Tagged { .. } => "Tagged", - } - } - - fn i64_to_det_int(v: i64) -> (CborDetIntKind, u64) { - if v >= 0 { - (CborDetIntKind::UInt64, v as u64) - } else { - (CborDetIntKind::NegInt64, (v as u64).wrapping_neg() - 1) - } - } - - fn nondet_int_to_i64( - kind: CborNondetIntKind, - value: u64, - ) -> Result { - match kind { - CborNondetIntKind::UInt64 => i64::try_from(value) - .map_err(|_| format!("CBOR uint {value} exceeds i64 range")), - CborNondetIntKind::NegInt64 => { - // CBOR negative: actual = -(value + 1) - // Compute as u64 first then reinterpret, to avoid overflow. - let neg_val = (!value) as i64; // bitwise NOT gives -(value+1) in two's complement - if value > (i64::MAX as u64) { - return Err(format!("CBOR nint exceeds i64 range")); - } - Ok(neg_val) - } - } - } - - fn from_raw(item: CborNondet) -> Result { - match cbor_nondet_destruct(item) { - CborNondetView::Int64 { kind, value } => { - Ok(CborValue::Int(Self::nondet_int_to_i64(kind, value)?)) - } - CborNondetView::SimpleValue { _0: v } => Ok(CborValue::Simple(v)), - CborNondetView::ByteString { payload } => { - Ok(CborValue::ByteString(payload.to_vec())) - } - CborNondetView::TextString { payload } => { - Ok(CborValue::TextString(payload.to_string())) - } - CborNondetView::Array { _0: arr } => { - let len = cbor_nondet_get_array_length(arr); - let mut items = Vec::with_capacity(len as usize); - for i in 0..len { - let child = cbor_nondet_get_array_item(arr, i) - .ok_or("Failed to get array item")?; - items.push(Self::from_raw(child)?); - } - Ok(CborValue::Array(items)) - } - CborNondetView::Map { _0: map } => { - let mut entries = Vec::with_capacity( - cbor_nondet_get_map_length(map) as usize, - ); - for entry in map { - let k = Self::from_raw(cbor_nondet_map_entry_key(entry))?; - let v = Self::from_raw(cbor_nondet_map_entry_value(entry))?; - entries.push((k, v)); - } - Ok(CborValue::Map(entries)) - } - CborNondetView::Tagged { tag, payload } => { - let inner = Self::from_raw(payload)?; - Ok(CborValue::Tagged { - tag, - payload: Box::new(inner), - }) - } - } - } -} - -fn serialize_det(item: CborDet) -> Result, String> { - let sz = cbor_det_size(item, usize::MAX) - .ok_or("Failed to estimate CBOR serialization size")?; - let mut buf = vec![0u8; sz]; - let written = - cbor_det_serialize(item, &mut buf).ok_or("Failed to serialize CBOR")?; - if sz != written { - return Err(format!( - "CBOR serialize mismatch: written {written} != expected {sz}" - )); - } - Ok(buf) -} - -/// A CBOR item that borrows its data, for zero-copy serialization. -pub enum CborSlice<'a> { - TextStr(&'a str), - ByteStr(&'a [u8]), -} - -/// Serialize a CBOR array of borrowed items without intermediate copies. -pub fn serialize_array(items: &[CborSlice<'_>]) -> Result, String> { - let mut raw: Vec> = items - .iter() - .map(|item| match item { - CborSlice::TextStr(s) => cbor_det_mk_text_string(s) - .ok_or("Failed to make CBOR text string".to_string()), - CborSlice::ByteStr(b) => cbor_det_mk_byte_string(b) - .ok_or("Failed to make CBOR byte string".to_string()), - }) - .collect::>()?; - let array = cbor_det_mk_array(&mut raw) - .ok_or("Failed to build CBOR array".to_string())?; - serialize_det(array) -} - -impl std::fmt::Debug for CborValue { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - CborValue::Int(v) => write!(f, "Int({})", v), - CborValue::Simple(v) => write!(f, "Simple({})", v), - CborValue::ByteString(b) => write!(f, "Bstr({} bytes)", b.len()), - CborValue::TextString(s) => write!(f, "Tstr({:?})", s), - CborValue::Array(items) => f.debug_list().entries(items).finish(), - CborValue::Map(entries) => f - .debug_map() - .entries(entries.iter().map(|(k, v)| (k, v))) - .finish(), - CborValue::Tagged { tag, payload } => { - write!(f, "Tag({}, {:?})", tag, payload) - } - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - fn round_trip(val: &CborValue) { - let bytes = val.to_bytes().unwrap(); - let parsed = CborValue::from_bytes(&bytes).unwrap(); - // Det serialization may reorder map keys, so compare the - // re-serialized bytes rather than the structural values. - let bytes2 = parsed.to_bytes().unwrap(); - assert_eq!(bytes, bytes2); - } - - // --- Int --- - - #[test] - fn round_trip_uint() { - round_trip(&CborValue::Int(42)); - } - - #[test] - fn round_trip_nint() { - round_trip(&CborValue::Int(-7)); - } - - #[test] - fn round_trip_zero() { - round_trip(&CborValue::Int(0)); - } - - #[test] - fn round_trip_i64_min() { - round_trip(&CborValue::Int(i64::MIN)); - } - - // --- Simple --- - - #[test] - fn round_trip_simple_true() { - round_trip(&CborValue::Simple(21)); // CBOR true - } - - #[test] - fn round_trip_simple_null() { - round_trip(&CborValue::Simple(22)); // CBOR null - } - - // --- ByteString --- - - #[test] - fn round_trip_bstr() { - round_trip(&CborValue::ByteString(vec![0xDE, 0xAD, 0xBE, 0xEF])); - } - - #[test] - fn round_trip_bstr_empty() { - round_trip(&CborValue::ByteString(vec![])); - } - - // --- TextString --- - - #[test] - fn round_trip_tstr() { - round_trip(&CborValue::TextString("hello world".into())); - } - - #[test] - fn round_trip_tstr_empty() { - round_trip(&CborValue::TextString(String::new())); - } - - // --- Array --- - - #[test] - fn round_trip_flat_array() { - round_trip(&CborValue::Array(vec![ - CborValue::Int(1), - CborValue::Int(2), - CborValue::Int(3), - ])); - } - - #[test] - fn round_trip_nested_array() { - round_trip(&CborValue::Array(vec![ - CborValue::Int(1), - CborValue::Array(vec![ - CborValue::Int(-1), - CborValue::Array(vec![CborValue::Int(99)]), - ]), - CborValue::Int(3), - ])); - } - - #[test] - fn round_trip_empty_array() { - round_trip(&CborValue::Array(vec![])); - } - - // --- Map --- - - #[test] - fn round_trip_map_int_keys() { - round_trip(&CborValue::Map(vec![ - (CborValue::Int(1), CborValue::TextString("one".into())), - (CborValue::Int(2), CborValue::TextString("two".into())), - ])); - } - - #[test] - fn round_trip_map_str_keys() { - round_trip(&CborValue::Map(vec![ - ( - CborValue::TextString("name".into()), - CborValue::TextString("alice".into()), - ), - (CborValue::TextString("age".into()), CborValue::Int(30)), - ])); - } - - #[test] - fn round_trip_map_nested_value() { - round_trip(&CborValue::Map(vec![( - CborValue::Int(1), - CborValue::Array(vec![ - CborValue::ByteString(vec![1, 2]), - CborValue::Simple(22), - ]), - )])); - } - - #[test] - fn round_trip_empty_map() { - round_trip(&CborValue::Map(vec![])); - } - - // --- Tagged --- - - #[test] - fn round_trip_tagged() { - round_trip(&CborValue::Tagged { - tag: 18, - payload: Box::new(CborValue::ByteString(b"payload".to_vec())), - }); - } - - #[test] - fn round_trip_tagged_nested() { - round_trip(&CborValue::Tagged { - tag: 1, - payload: Box::new(CborValue::Array(vec![ - CborValue::Int(42), - CborValue::TextString("inside tag".into()), - ])), - }); - } - - // --- Mixed nesting --- - - #[test] - fn round_trip_complex() { - round_trip(&CborValue::Array(vec![ - CborValue::ByteString(vec![0xFF]), - CborValue::Map(vec![ - ( - CborValue::Int(1), - CborValue::Tagged { - tag: 99, - payload: Box::new(CborValue::TextString( - "nested".into(), - )), - }, - ), - ( - CborValue::Int(2), - CborValue::Array(vec![CborValue::Simple(22)]), - ), - ]), - CborValue::Int(-100), - ])); - } - - // --- Accessor: get (array index) --- - - #[test] - fn array_at_item() { - let arr = - CborValue::Array(vec![CborValue::Int(10), CborValue::Int(20)]); - assert_eq!(arr.array_at(0).unwrap(), &CborValue::Int(10)); - assert_eq!(arr.array_at(1).unwrap(), &CborValue::Int(20)); - assert!(arr.array_at(2).is_err()); - } - - #[test] - fn array_at_on_non_array_is_err() { - assert!(CborValue::Int(1).array_at(0).is_err()); - assert!(CborValue::TextString("hi".into()).array_at(0).is_err()); - assert!(CborValue::Map(vec![]).array_at(0).is_err()); - } - - // --- Accessor: map lookup --- - - #[test] - fn map_at_int_key() { - let map = CborValue::Map(vec![ - (CborValue::Int(1), CborValue::TextString("one".into())), - (CborValue::Int(2), CborValue::TextString("two".into())), - ]); - assert_eq!( - map.map_at_int(1).unwrap(), - &CborValue::TextString("one".into()) - ); - assert_eq!( - map.map_at_int(2).unwrap(), - &CborValue::TextString("two".into()) - ); - assert!(map.map_at_int(3).is_err()); - } - - #[test] - fn map_at_str_key() { - let map = CborValue::Map(vec![( - CborValue::TextString("key".into()), - CborValue::Int(42), - )]); - assert_eq!(map.map_at_str("key").unwrap(), &CborValue::Int(42)); - assert!(map.map_at_str("missing").is_err()); - } - - #[test] - fn map_at_invalid_key_type() { - let map = CborValue::Map(vec![]); - let bad_key = CborValue::ByteString(vec![]); - assert!(map.map_at(&bad_key).is_err()); - } - - #[test] - fn map_at_on_non_map_is_err() { - assert!(CborValue::Int(1).map_at_int(0).is_err()); - assert!(CborValue::Array(vec![]).map_at_str("x").is_err()); - } - - // --- Iterators --- - - #[test] - fn iter_array_elements() { - let arr = CborValue::Array(vec![ - CborValue::Int(1), - CborValue::Int(2), - CborValue::Int(3), - ]); - let collected: Vec<_> = arr.iter_array().unwrap().collect(); - assert_eq!(collected.len(), 3); - assert_eq!(collected[0], &CborValue::Int(1)); - } - - #[test] - fn iter_array_on_non_array_is_err() { - assert!(CborValue::Int(1).iter_array().is_err()); - } - - #[test] - fn iter_map_entries() { - let map = CborValue::Map(vec![ - (CborValue::Int(1), CborValue::TextString("a".into())), - (CborValue::Int(2), CborValue::TextString("b".into())), - ]); - let collected: Vec<_> = map.iter_map().unwrap().collect(); - assert_eq!(collected.len(), 2); - assert_eq!(collected[0].0, &CborValue::Int(1)); - } - - #[test] - fn iter_map_on_non_map_is_err() { - assert!(CborValue::Array(vec![]).iter_map().is_err()); - } - - // --- len --- - - #[test] - fn len_array() { - let arr = CborValue::Array(vec![CborValue::Int(1)]); - assert_eq!(arr.len().unwrap(), 1); - } - - #[test] - fn len_map() { - let map = CborValue::Map(vec![(CborValue::Int(1), CborValue::Int(2))]); - assert_eq!(map.len().unwrap(), 1); - } - - #[test] - fn len_on_other_types_is_err() { - assert!(CborValue::Int(0).len().is_err()); - assert!(CborValue::TextString("x".into()).len().is_err()); - } - - // --- Debug --- - - #[test] - fn debug_format() { - let val = - CborValue::Array(vec![CborValue::Int(42), CborValue::Int(-7)]); - let s = format!("{:?}", val); - assert!(s.contains("Int(42)")); - assert!(s.contains("Int(-7)")); - } -} diff --git a/3rdparty/internal/cose-openssl/src/cose.rs b/3rdparty/internal/cose-openssl/src/cose.rs index 376208eb853a..4d248973722c 100644 --- a/3rdparty/internal/cose-openssl/src/cose.rs +++ b/3rdparty/internal/cose-openssl/src/cose.rs @@ -1,8 +1,8 @@ -use crate::cbor::{CborSlice, CborValue, serialize_array}; use crate::ossl_wrappers::{ EvpKey, KeyType, WhichEC, WhichRSA, ecdsa_der_to_fixed, ecdsa_fixed_to_der, rsa_pss_md_for_cose_alg, }; +use cbor::CborValue; #[cfg(feature = "pqc")] use crate::ossl_wrappers::WhichMLDSA; @@ -45,10 +45,7 @@ fn fully_specified_cose_alg(key: &EvpKey) -> Option { } /// Insert alg(1) into a CborValue map, return error if already exists. -fn insert_alg_value( - key: &EvpKey, - phdr: CborValue, -) -> Result { +fn insert_alg_value<'a>(key: &EvpKey, phdr: CborValue<'a>) -> Result, String> { let mut entries = match phdr { CborValue::Map(entries) => entries, _ => { @@ -70,29 +67,29 @@ fn insert_alg_value( /// To-be-signed (TBS). /// https://www.rfc-editor.org/rfc/rfc9052.html#section-4.4. /// -/// Uses `serialize_array` with borrowed slices to avoid copying -/// `phdr` and `payload` into intermediate `Vec`s. These can -/// be large (payload especially), so we serialize directly from -/// the caller's buffers. +/// The array items borrow `phdr` and `payload` rather than copying them into +/// intermediate `Vec`s; the payload especially can be large. The TBS bytes +/// are what gets signed, so they must be deterministic. fn sig_structure(phdr: &[u8], payload: &[u8]) -> Result, String> { - serialize_array(&[ - CborSlice::TextStr(SIG_STRUCTURE1_CONTEXT), - CborSlice::ByteStr(phdr), - CborSlice::ByteStr(&[]), - CborSlice::ByteStr(payload), + CborValue::Array(vec![ + CborValue::text(SIG_STRUCTURE1_CONTEXT), + CborValue::bytes(phdr), + CborValue::bytes(&[][..]), + CborValue::bytes(payload), ]) + .to_bytes_det() } /// Produce a COSE_Sign1 envelope. pub fn cose_sign1( key: &EvpKey, - phdr: CborValue, - uhdr: CborValue, + phdr: CborValue<'_>, + uhdr: CborValue<'_>, payload: &[u8], detached: bool, ) -> Result, String> { let phdr_with_alg = insert_alg_value(key, phdr)?; - let phdr_bytes = phdr_with_alg.to_bytes()?; + let phdr_bytes = phdr_with_alg.to_bytes_det()?; let tbs = sig_structure(&phdr_bytes, payload)?; let sig = crate::sign::sign(key, &tbs)?; @@ -106,20 +103,20 @@ pub fn cose_sign1( let payload_item = if detached { CborValue::Simple(CBOR_SIMPLE_VALUE_NULL) } else { - CborValue::ByteString(payload.to_vec()) + CborValue::bytes(payload) }; let envelope = CborValue::Tagged { tag: COSE_SIGN1_TAG, payload: Box::new(CborValue::Array(vec![ - CborValue::ByteString(phdr_bytes), + CborValue::bytes(phdr_bytes), uhdr, payload_item, - CborValue::ByteString(sig), + CborValue::bytes(sig), ])), }; - envelope.to_bytes() + envelope.to_bytes_det() } /// Verify a COSE_Sign1 from pre-parsed components. The caller supplies @@ -183,14 +180,14 @@ mod tests { fn sign_and_verify(key_type: KeyType) { let key = EvpKey::new(key_type).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"Good boy..."; let envelope = cose_sign1(&key, phdr, uhdr, payload, false).unwrap(); // Parse envelope to extract raw components for cose_verify1. - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -200,11 +197,11 @@ mod tests { _ => panic!("not array"), }; let phdr_raw = match &items[0] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("phdr not bstr"), }; let sig_raw = match &items[3] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("sig not bstr"), }; @@ -216,7 +213,7 @@ mod tests { fn test_insert_alg() { let key = EvpKey::new(KeyType::EC(WhichEC::P256)).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let phdr_with_alg = insert_alg_value(&key, phdr).unwrap(); let alg = phdr_with_alg.map_at_int(COSE_HEADER_ALG).unwrap(); @@ -269,14 +266,14 @@ mod tests { ] { let key = EvpKey::new(KeyType::EC(which)).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"Good boy..."; let envelope = cose_sign1(&key, phdr, uhdr, payload, false).unwrap(); - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -304,13 +301,13 @@ mod tests { fn cose_detached_payload() { let key = EvpKey::new(KeyType::EC(WhichEC::P256)).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"Good boy..."; let envelope = cose_sign1(&key, phdr, uhdr, payload, true).unwrap(); - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -320,11 +317,11 @@ mod tests { _ => panic!("not array"), }; let phdr_raw = match &items[0] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("phdr not bstr"), }; let sig_raw = match &items[3] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("sig not bstr"), }; @@ -356,14 +353,13 @@ mod tests { let verification_key = EvpKey::from_der_public(&pub_der).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"test with DER-imported key"; - let envelope = - cose_sign1(&signing_key, phdr, uhdr, payload, false).unwrap(); + let envelope = cose_sign1(&signing_key, phdr, uhdr, payload, false).unwrap(); - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -373,19 +369,16 @@ mod tests { _ => panic!("not array"), }; let phdr_raw = match &items[0] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("phdr not bstr"), }; let sig_raw = match &items[3] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("sig not bstr"), }; let alg = cose_alg(&verification_key).unwrap(); - assert!( - cose_verify1(&verification_key, alg, &phdr_raw, payload, &sig_raw) - .unwrap() - ); + assert!(cose_verify1(&verification_key, alg, &phdr_raw, payload, &sig_raw).unwrap()); } #[test] @@ -414,14 +407,13 @@ mod tests { let verification_key = EvpKey::from_der_public(&pub_der).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"RSA with DER-imported key"; - let envelope = - cose_sign1(&signing_key, phdr, uhdr, payload, false).unwrap(); + let envelope = cose_sign1(&signing_key, phdr, uhdr, payload, false).unwrap(); - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -431,32 +423,29 @@ mod tests { _ => panic!("not array"), }; let phdr_raw = match &items[0] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("phdr not bstr"), }; let sig_raw = match &items[3] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("sig not bstr"), }; let alg = cose_alg(&verification_key).unwrap(); - assert!( - cose_verify1(&verification_key, alg, &phdr_raw, payload, &sig_raw) - .unwrap() - ); + assert!(cose_verify1(&verification_key, alg, &phdr_raw, payload, &sig_raw).unwrap()); } #[test] fn cose_rsa_detached_payload() { let key = EvpKey::new(KeyType::RSA(WhichRSA::PS384)).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"RSA detached"; let envelope = cose_sign1(&key, phdr, uhdr, payload, true).unwrap(); - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -466,11 +455,11 @@ mod tests { _ => panic!("not array"), }; let phdr_raw = match &items[0] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("phdr not bstr"), }; let sig_raw = match &items[3] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("sig not bstr"), }; @@ -490,14 +479,11 @@ mod tests { // Build phdr with alg = -38 (PS384) already set. let phdr_bytes = hex_decode(TEST_PHDR); - let mut phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let mut phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); if let CborValue::Map(ref mut entries) = phdr { - entries.insert( - 0, - (CborValue::Int(COSE_HEADER_ALG), CborValue::Int(-38)), - ); + entries.insert(0, (CborValue::Int(COSE_HEADER_ALG), CborValue::Int(-38))); } - let phdr_ser = phdr.to_bytes().unwrap(); + let phdr_ser = phdr.to_bytes_det().unwrap(); // Build TBS and sign with SHA-384. let tbs = sig_structure(&phdr_ser, payload).unwrap(); @@ -514,13 +500,13 @@ mod tests { fn cose_sign1_no_double_encoding() { let key = EvpKey::new(KeyType::EC(WhichEC::P256)).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"test payload"; let envelope = cose_sign1(&key, phdr, uhdr, payload, false).unwrap(); - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -530,7 +516,7 @@ mod tests { _ => panic!("not array"), }; let payload_in_envelope = match &items[2] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("payload not bstr"), }; // The envelope payload must equal the raw data, not a @@ -565,13 +551,9 @@ mod tests { #[test] fn cose_sign1_rejects_duplicate_alg() { let key = EvpKey::new(KeyType::EC(WhichEC::P256)).unwrap(); - let phdr = CborValue::Map(vec![( - CborValue::Int(COSE_HEADER_ALG), - CborValue::Int(-7), - )]); + let phdr = CborValue::Map(vec![(CborValue::Int(COSE_HEADER_ALG), CborValue::Int(-7))]); assert_eq!( - cose_sign1(&key, phdr, CborValue::Map(vec![]), b"msg", false) - .unwrap_err(), + cose_sign1(&key, phdr, CborValue::Map(vec![]), b"msg", false).unwrap_err(), "Algorithm already set in protected header" ); } @@ -625,8 +607,7 @@ mod tests { key: std::ptr::null_mut(), typ: KeyType::RSA(WhichRSA::PS256), }; - let err = - cose_verify1(&null_key, -37, b"", b"", &[0u8; 256]).unwrap_err(); + let err = cose_verify1(&null_key, -37, b"", b"", &[0u8; 256]).unwrap_err(); assert!( err.starts_with("EVP_DigestVerifyInit returned 0: error:"), "unexpected error: {err}" @@ -644,14 +625,13 @@ mod tests { let verification_key = EvpKey::from_pem_public(&pub_pem).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"signed with PEM-imported key"; - let envelope = - cose_sign1(&signing_key, phdr, uhdr, payload, false).unwrap(); + let envelope = cose_sign1(&signing_key, phdr, uhdr, payload, false).unwrap(); - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -661,19 +641,16 @@ mod tests { _ => panic!("not array"), }; let phdr_raw = match &items[0] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("phdr not bstr"), }; let sig_raw = match &items[3] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("sig not bstr"), }; let alg = cose_alg(&verification_key).unwrap(); - assert!( - cose_verify1(&verification_key, alg, &phdr_raw, payload, &sig_raw) - .unwrap() - ); + assert!(cose_verify1(&verification_key, alg, &phdr_raw, payload, &sig_raw).unwrap()); } #[cfg(feature = "pqc")] @@ -694,8 +671,7 @@ mod tests { #[test] fn cose_mldsa_with_der_imported_key() { - let original_key = - EvpKey::new(KeyType::MLDSA(WhichMLDSA::P65)).unwrap(); + let original_key = EvpKey::new(KeyType::MLDSA(WhichMLDSA::P65)).unwrap(); let priv_der = original_key.to_der_private().unwrap(); let signing_key = EvpKey::from_der_private(&priv_der).unwrap(); @@ -704,14 +680,13 @@ mod tests { let verification_key = EvpKey::from_der_public(&pub_der).unwrap(); let phdr_bytes = hex_decode(TEST_PHDR); - let phdr = CborValue::from_bytes(&phdr_bytes).unwrap(); + let phdr = CborValue::parse_nondet(&phdr_bytes).unwrap(); let uhdr = CborValue::Map(vec![]); let payload = b"ML-DSA with DER-imported key"; - let envelope = - cose_sign1(&signing_key, phdr, uhdr, payload, false).unwrap(); + let envelope = cose_sign1(&signing_key, phdr, uhdr, payload, false).unwrap(); - let parsed = CborValue::from_bytes(&envelope).unwrap(); + let parsed = CborValue::parse_nondet(&envelope).unwrap(); let inner = match parsed { CborValue::Tagged { payload, .. } => *payload, _ => panic!("not tagged"), @@ -721,25 +696,16 @@ mod tests { _ => panic!("not array"), }; let phdr_raw = match &items[0] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("phdr not bstr"), }; let sig_raw = match &items[3] { - CborValue::ByteString(b) => b.clone(), + CborValue::ByteString(b) => b.to_vec(), _ => panic!("sig not bstr"), }; let alg = cose_alg(&verification_key).unwrap(); - assert!( - cose_verify1( - &verification_key, - alg, - &phdr_raw, - payload, - &sig_raw - ) - .unwrap() - ); + assert!(cose_verify1(&verification_key, alg, &phdr_raw, payload, &sig_raw).unwrap()); } } } diff --git a/3rdparty/internal/cose-openssl/src/lib.rs b/3rdparty/internal/cose-openssl/src/lib.rs index ede1c5eb97a6..2083d7d1c7bd 100644 --- a/3rdparty/internal/cose-openssl/src/lib.rs +++ b/3rdparty/internal/cose-openssl/src/lib.rs @@ -1,4 +1,3 @@ -mod cbor; mod cose; mod ossl_wrappers; mod sign; diff --git a/3rdparty/internal/evercbor/CBORNondet.c b/3rdparty/internal/evercbor/CBORNondet.c deleted file mode 100644 index 3aad3f542e99..000000000000 --- a/3rdparty/internal/evercbor/CBORNondet.c +++ /dev/null @@ -1,6573 +0,0 @@ - - -#include "internal/CBORNondet.h" - -#include "CBORNondetType.h" - -static uint8_t LowParse_BitFields_get_bitfield_gen8(uint8_t x, uint32_t lo, uint32_t hi) -{ - return ((uint32_t)x << (8U - hi) & 0xFFU) >> (8U - hi + lo); -} - -static uint8_t -LowParse_BitFields_set_bitfield_gen8(uint8_t x, uint32_t lo, uint32_t hi, uint8_t v) -{ - return ((uint32_t)x & (uint32_t)~(255U >> (8U - (hi - lo)) << lo)) | (uint32_t)v << lo; -} - -#define CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS (24U) - -#define CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_UNASSIGNED_MIN (28U) - -typedef struct CBOR_Spec_Raw_EverParse_initial_byte_t_s -{ - uint8_t major_type; - uint8_t additional_info; -} -CBOR_Spec_Raw_EverParse_initial_byte_t; - -#define CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_16_BITS (25U) - -#define CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_32_BITS (26U) - -#define CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_64_BITS (27U) - -#define CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue 0 -#define CBOR_Spec_Raw_EverParse_LongArgumentU8 1 -#define CBOR_Spec_Raw_EverParse_LongArgumentU16 2 -#define CBOR_Spec_Raw_EverParse_LongArgumentU32 3 -#define CBOR_Spec_Raw_EverParse_LongArgumentU64 4 -#define CBOR_Spec_Raw_EverParse_LongArgumentOther 5 - -typedef uint8_t CBOR_Spec_Raw_EverParse_long_argument_tags; - -typedef struct CBOR_Spec_Raw_EverParse_long_argument_s -{ - CBOR_Spec_Raw_EverParse_long_argument_tags tag; - union { - uint8_t case_LongArgumentSimpleValue; - uint8_t case_LongArgumentU8; - uint16_t case_LongArgumentU16; - uint32_t case_LongArgumentU32; - uint64_t case_LongArgumentU64; - } - ; -} -CBOR_Spec_Raw_EverParse_long_argument; - -typedef struct CBOR_Spec_Raw_EverParse_header_s -{ - CBOR_Spec_Raw_EverParse_initial_byte_t fst; - CBOR_Spec_Raw_EverParse_long_argument snd; -} -CBOR_Spec_Raw_EverParse_header; - -static uint64_t -CBOR_Spec_Raw_EverParse_argument_as_uint64( - CBOR_Spec_Raw_EverParse_initial_byte_t b, - CBOR_Spec_Raw_EverParse_long_argument x -) -{ - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x.tag == CBOR_Spec_Raw_EverParse_LongArgumentU8) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 1U, .value = (uint64_t)x.case_LongArgumentU8 }); - else if (x.tag == CBOR_Spec_Raw_EverParse_LongArgumentU16) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 2U, .value = (uint64_t)x.case_LongArgumentU16 }); - else if (x.tag == CBOR_Spec_Raw_EverParse_LongArgumentU32) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 3U, .value = (uint64_t)x.case_LongArgumentU32 }); - else if (x.tag == CBOR_Spec_Raw_EverParse_LongArgumentU64) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 4U, .value = x.case_LongArgumentU64 }); - else if (x.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 0U, .value = (uint64_t)b.additional_info }); - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return ite.value; -} - -static CBOR_Spec_Raw_EverParse_header -CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(uint8_t t, CBOR_Spec_Raw_Base_raw_uint64 x) -{ - if (x.size == 0U) - return - ( - (CBOR_Spec_Raw_EverParse_header){ - .fst = { .major_type = t, .additional_info = (uint8_t)x.value }, - .snd = { .tag = CBOR_Spec_Raw_EverParse_LongArgumentOther } - } - ); - else if (x.size == 1U) - return - ( - (CBOR_Spec_Raw_EverParse_header){ - .fst = { - .major_type = t, - .additional_info = CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS - }, - .snd = { - .tag = CBOR_Spec_Raw_EverParse_LongArgumentU8, - { .case_LongArgumentU8 = (uint8_t)x.value } - } - } - ); - else if (x.size == 2U) - return - ( - (CBOR_Spec_Raw_EverParse_header){ - .fst = { - .major_type = t, - .additional_info = CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_16_BITS - }, - .snd = { - .tag = CBOR_Spec_Raw_EverParse_LongArgumentU16, - { .case_LongArgumentU16 = (uint16_t)x.value } - } - } - ); - else if (x.size == 3U) - return - ( - (CBOR_Spec_Raw_EverParse_header){ - .fst = { - .major_type = t, - .additional_info = CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_32_BITS - }, - .snd = { - .tag = CBOR_Spec_Raw_EverParse_LongArgumentU32, - { .case_LongArgumentU32 = (uint32_t)x.value } - } - } - ); - else - return - ( - (CBOR_Spec_Raw_EverParse_header){ - .fst = { - .major_type = t, - .additional_info = CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_64_BITS - }, - .snd = { - .tag = CBOR_Spec_Raw_EverParse_LongArgumentU64, - { .case_LongArgumentU64 = x.value } - } - } - ); -} - -static CBOR_Spec_Raw_EverParse_header -CBOR_Spec_Raw_EverParse_simple_value_as_argument(uint8_t x) -{ - if (x <= MAX_SIMPLE_VALUE_ADDITIONAL_INFO) - return - ( - (CBOR_Spec_Raw_EverParse_header){ - .fst = { .major_type = CBOR_MAJOR_TYPE_SIMPLE_VALUE, .additional_info = x }, - .snd = { .tag = CBOR_Spec_Raw_EverParse_LongArgumentOther } - } - ); - else - return - ( - (CBOR_Spec_Raw_EverParse_header){ - .fst = { - .major_type = CBOR_MAJOR_TYPE_SIMPLE_VALUE, - .additional_info = CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS - }, - .snd = { - .tag = CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue, - { .case_LongArgumentSimpleValue = x } - } - } - ); -} - -static uint8_t CBOR_Spec_Raw_EverParse_get_header_major_type(CBOR_Spec_Raw_EverParse_header h) -{ - return h.fst.major_type; -} - -static size_t Pulse_Lib_Slice_len__uint8_t(CBOR_Pulse_Raw_Slice_byte_slice s) -{ - return s.len; -} - -static uint8_t -Pulse_Lib_Slice_op_Array_Access__uint8_t(CBOR_Pulse_Raw_Slice_byte_slice a, size_t i) -{ - return a.elt[i]; -} - -static bool CBOR_Pulse_Raw_EverParse_UTF8_impl_correct(CBOR_Pulse_Raw_Slice_byte_slice s) -{ - bool pres = true; - size_t pi = (size_t)0U; - size_t len = Pulse_Lib_Slice_len__uint8_t(s); - while (pres && pi < len) - { - size_t i = pi; - uint8_t byte1 = Pulse_Lib_Slice_op_Array_Access__uint8_t(s, i); - size_t i1 = i + (size_t)1U; - if (byte1 <= 0x7FU) - pi = i1; - else if (i1 == len) - pres = false; - else - { - uint8_t byte2 = Pulse_Lib_Slice_op_Array_Access__uint8_t(s, i1); - size_t i2 = i1 + (size_t)1U; - if (0xC2U <= byte1 && byte1 <= 0xDFU && 0x80U <= byte2 && byte2 <= 0xBFU) - pi = i2; - else if (i2 == len) - pres = false; - else - { - uint8_t byte3 = Pulse_Lib_Slice_op_Array_Access__uint8_t(s, i2); - size_t i3 = i2 + (size_t)1U; - if (!(0x80U <= byte3 && byte3 <= 0xBFU)) - pres = false; - else if (byte1 == 0xE0U) - if (0xA0U <= byte2 && byte2 <= 0xBFU) - pi = i3; - else - pres = false; - else if (byte1 == 0xEDU) - if (0x80U <= byte2 && byte2 <= 0x9FU) - pi = i3; - else - pres = false; - else if (0xE1U <= byte1 && byte1 <= 0xEFU && 0x80U <= byte2 && byte2 <= 0xBFU) - pi = i3; - else if (i3 == len) - pres = false; - else - { - uint8_t byte4 = Pulse_Lib_Slice_op_Array_Access__uint8_t(s, i3); - size_t i4 = i3 + (size_t)1U; - if (!(0x80U <= byte4 && byte4 <= 0xBFU)) - pres = false; - else if (byte1 == 0xF0U && 0x90U <= byte2 && byte2 <= 0xBFU) - pi = i4; - else if (0xF1U <= byte1 && byte1 <= 0xF3U && 0x80U <= byte2 && byte2 <= 0xBFU) - pi = i4; - else if (byte1 == 0xF4U && 0x80U <= byte2 && byte2 <= 0x8FU) - pi = i4; - else - pres = false; - } - } - } - } - return pres; -} - -static bool CBOR_Pulse_Raw_Util_eq_Some_true(FStar_Pervasives_Native_option__bool x) -{ - if (x.tag == FStar_Pervasives_Native_Some) - return x.v; - else - return false; -} - -static bool CBOR_Pulse_Raw_Util_eq_Some_false(FStar_Pervasives_Native_option__bool x) -{ - if (x.tag == FStar_Pervasives_Native_Some) - return !x.v; - else - return false; -} - -static bool CBOR_Pulse_Raw_Util_eq_Some_0sz(FStar_Pervasives_Native_option__size_t x) -{ - if (x.tag == FStar_Pervasives_Native_Some) - return x.v == (size_t)0U; - else - return false; -} - -static CBOR_Spec_Raw_Base_raw_uint64 CBOR_Spec_Raw_Optimal_mk_raw_uint64(uint64_t x) -{ - uint8_t ite; - if (x <= (uint64_t)MAX_SIMPLE_VALUE_ADDITIONAL_INFO) - ite = 0U; - else if (x < 256ULL) - ite = 1U; - else if (x < 65536ULL) - ite = 2U; - else if (x < 4294967296ULL) - ite = 3U; - else - ite = 4U; - return ((CBOR_Spec_Raw_Base_raw_uint64){ .size = ite, .value = x }); -} - -static cbor_string CBOR_Pulse_Raw_Match_cbor_string_reset_perm(cbor_string c) -{ - return - ( - (cbor_string){ - .cbor_string_type = c.cbor_string_type, - .cbor_string_size = c.cbor_string_size, - .cbor_string_ptr = c.cbor_string_ptr - } - ); -} - -static cbor_serialized CBOR_Pulse_Raw_Match_cbor_serialized_reset_perm(cbor_serialized c) -{ - return - ( - (cbor_serialized){ - .cbor_serialized_header = c.cbor_serialized_header, - .cbor_serialized_payload = c.cbor_serialized_payload - } - ); -} - -static cbor_tagged CBOR_Pulse_Raw_Match_cbor_tagged_reset_perm(cbor_tagged c) -{ - return - ((cbor_tagged){ .cbor_tagged_tag = c.cbor_tagged_tag, .cbor_tagged_ptr = c.cbor_tagged_ptr }); -} - -static cbor_array CBOR_Pulse_Raw_Match_cbor_array_reset_perm(cbor_array c) -{ - return - ( - (cbor_array){ - .cbor_array_length_size = c.cbor_array_length_size, - .cbor_array_ptr = c.cbor_array_ptr - } - ); -} - -static cbor_map CBOR_Pulse_Raw_Match_cbor_map_reset_perm(cbor_map c) -{ - return - ((cbor_map){ .cbor_map_length_size = c.cbor_map_length_size, .cbor_map_ptr = c.cbor_map_ptr }); -} - -static cbor_raw CBOR_Pulse_Raw_Match_cbor_raw_reset_perm_tot(cbor_raw c) -{ - if (c.tag == CBOR_Case_String) - return - ( - (cbor_raw){ - .tag = CBOR_Case_String, - { - .case_CBOR_Case_String = CBOR_Pulse_Raw_Match_cbor_string_reset_perm(c.case_CBOR_Case_String) - } - } - ); - else if (c.tag == CBOR_Case_Tagged) - return - ( - (cbor_raw){ - .tag = CBOR_Case_Tagged, - { - .case_CBOR_Case_Tagged = CBOR_Pulse_Raw_Match_cbor_tagged_reset_perm(c.case_CBOR_Case_Tagged) - } - } - ); - else if (c.tag == CBOR_Case_Array) - return - ( - (cbor_raw){ - .tag = CBOR_Case_Array, - { - .case_CBOR_Case_Array = CBOR_Pulse_Raw_Match_cbor_array_reset_perm(c.case_CBOR_Case_Array) - } - } - ); - else if (c.tag == CBOR_Case_Map) - return - ( - (cbor_raw){ - .tag = CBOR_Case_Map, - { .case_CBOR_Case_Map = CBOR_Pulse_Raw_Match_cbor_map_reset_perm(c.case_CBOR_Case_Map) } - } - ); - else if (c.tag == CBOR_Case_Serialized_Tagged) - return - ( - (cbor_raw){ - .tag = CBOR_Case_Serialized_Tagged, - { - .case_CBOR_Case_Serialized_Tagged = CBOR_Pulse_Raw_Match_cbor_serialized_reset_perm(c.case_CBOR_Case_Serialized_Tagged) - } - } - ); - else if (c.tag == CBOR_Case_Serialized_Array) - return - ( - (cbor_raw){ - .tag = CBOR_Case_Serialized_Array, - { - .case_CBOR_Case_Serialized_Array = CBOR_Pulse_Raw_Match_cbor_serialized_reset_perm(c.case_CBOR_Case_Serialized_Array) - } - } - ); - else if (c.tag == CBOR_Case_Serialized_Map) - return - ( - (cbor_raw){ - .tag = CBOR_Case_Serialized_Map, - { - .case_CBOR_Case_Serialized_Map = CBOR_Pulse_Raw_Match_cbor_serialized_reset_perm(c.case_CBOR_Case_Serialized_Map) - } - } - ); - else - return c; -} - -static int16_t CBOR_Pulse_Raw_Compare_Bytes_impl_uint8_compare(uint8_t x1, uint8_t x2) -{ - if (x1 < x2) - return (int16_t)-1; - else if (x1 > x2) - return (int16_t)1; - else - return (int16_t)0; -} - -static int16_t -CBOR_Pulse_Raw_Compare_Bytes_lex_compare_bytes( - CBOR_Pulse_Raw_Slice_byte_slice s1, - CBOR_Pulse_Raw_Slice_byte_slice s2 -) -{ - CBOR_Pulse_Raw_Slice_byte_slice sp1 = s1; - CBOR_Pulse_Raw_Slice_byte_slice sp2 = s2; - size_t pi1 = (size_t)0U; - size_t pi2 = (size_t)0U; - size_t n1 = Pulse_Lib_Slice_len__uint8_t(sp1); - size_t n2 = Pulse_Lib_Slice_len__uint8_t(sp2); - int16_t ite; - if ((size_t)0U < n1) - if ((size_t)0U < n2) - ite = (int16_t)0; - else - ite = (int16_t)1; - else if ((size_t)0U < n2) - ite = (int16_t)-1; - else - ite = (int16_t)0; - int16_t pres = ite; - while (pres == (int16_t)0 && pi1 < n1) - { - size_t i1 = pi1; - uint8_t x1 = Pulse_Lib_Slice_op_Array_Access__uint8_t(sp1, i1); - size_t i2 = pi2; - int16_t - c = - CBOR_Pulse_Raw_Compare_Bytes_impl_uint8_compare(x1, - Pulse_Lib_Slice_op_Array_Access__uint8_t(sp2, i2)); - if (c == (int16_t)0) - { - size_t i1_ = i1 + (size_t)1U; - size_t i2_ = i2 + (size_t)1U; - bool ci1_ = i1_ < n1; - bool ci2_ = i2_ < n2; - if (ci2_ && !ci1_) - pres = (int16_t)-1; - else if (ci1_ && !ci2_) - pres = (int16_t)1; - else - { - pi1 = i1_; - pi2 = i2_; - } - } - else - pres = c; - } - return pres; -} - -static CBOR_Spec_Raw_EverParse_initial_byte_t -CBOR_Pulse_Raw_EverParse_Format_read_initial_byte_t(CBOR_Pulse_Raw_Slice_byte_slice input) -{ - uint8_t x = Pulse_Lib_Slice_op_Array_Access__uint8_t(input, (size_t)0U); - return - ( - (CBOR_Spec_Raw_EverParse_initial_byte_t){ - .major_type = LowParse_BitFields_get_bitfield_gen8(x, 5U, 8U), - .additional_info = LowParse_BitFields_get_bitfield_gen8(x, 0U, 5U) - } - ); -} - -typedef struct K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice_s -{ - CBOR_Pulse_Raw_Slice_byte_slice fst; - CBOR_Pulse_Raw_Slice_byte_slice snd; -} -K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice; - -static K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice -Pulse_Lib_Slice_split__uint8_t(CBOR_Pulse_Raw_Slice_byte_slice s, size_t i) -{ - return - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = { .elt = s.elt, .len = i }, - .snd = { .elt = s.elt + i, .len = s.len - i } - } - ); -} - -static CBOR_Spec_Raw_EverParse_header -CBOR_Pulse_Raw_EverParse_Format_read_header(CBOR_Pulse_Raw_Slice_byte_slice input) -{ - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, (size_t)1U); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - CBOR_Pulse_Raw_Slice_byte_slice input2 = scrut1.snd; - CBOR_Spec_Raw_EverParse_initial_byte_t - x1 = CBOR_Pulse_Raw_EverParse_Format_read_initial_byte_t(scrut1.fst); - CBOR_Spec_Raw_EverParse_long_argument ite; - if (x1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS) - if (x1.major_type == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - ite = - ( - (CBOR_Spec_Raw_EverParse_long_argument){ - .tag = CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue, - { - .case_LongArgumentSimpleValue = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, - (size_t)0U) - } - } - ); - else - ite = - ( - (CBOR_Spec_Raw_EverParse_long_argument){ - .tag = CBOR_Spec_Raw_EverParse_LongArgumentU8, - { .case_LongArgumentU8 = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)0U) } - } - ); - else if (x1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_16_BITS) - { - uint8_t last = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)1U); - ite = - ( - (CBOR_Spec_Raw_EverParse_long_argument){ - .tag = CBOR_Spec_Raw_EverParse_LongArgumentU16, - { - .case_LongArgumentU16 = (uint32_t)(uint16_t)last + - (uint32_t)(uint16_t)Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)0U) * - 256U - } - } - ); - } - else if (x1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_32_BITS) - { - uint8_t last = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)3U); - uint8_t last1 = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)3U - (size_t)1U); - uint8_t - last2 = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)3U - (size_t)1U - (size_t)1U); - ite = - ( - (CBOR_Spec_Raw_EverParse_long_argument){ - .tag = CBOR_Spec_Raw_EverParse_LongArgumentU32, - { - .case_LongArgumentU32 = (uint32_t)last + - ((uint32_t)last1 + - ((uint32_t)last2 + - (uint32_t)Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)0U) * 256U) - * 256U) - * 256U - } - } - ); - } - else if (x1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_64_BITS) - { - uint8_t last = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)7U); - uint8_t last1 = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)7U - (size_t)1U); - uint8_t - last2 = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)7U - (size_t)1U - (size_t)1U); - uint8_t - last3 = - Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, - (size_t)7U - (size_t)1U - (size_t)1U - (size_t)1U); - size_t pos_4 = (size_t)7U - (size_t)1U - (size_t)1U - (size_t)1U - (size_t)1U; - uint8_t last4 = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, pos_4); - size_t pos_5 = pos_4 - (size_t)1U; - uint8_t last5 = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, pos_5); - uint8_t last6 = Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, pos_5 - (size_t)1U); - ite = - ( - (CBOR_Spec_Raw_EverParse_long_argument){ - .tag = CBOR_Spec_Raw_EverParse_LongArgumentU64, - { - .case_LongArgumentU64 = (uint64_t)last + - ((uint64_t)last1 + - ((uint64_t)last2 + - ((uint64_t)last3 + - ((uint64_t)last4 + - ((uint64_t)last5 + - ((uint64_t)last6 + - (uint64_t)Pulse_Lib_Slice_op_Array_Access__uint8_t(input2, (size_t)0U) * - 256ULL) - * 256ULL) - * 256ULL) - * 256ULL) - * 256ULL) - * 256ULL) - * 256ULL - } - } - ); - } - else - ite = - ((CBOR_Spec_Raw_EverParse_long_argument){ .tag = CBOR_Spec_Raw_EverParse_LongArgumentOther }); - return ((CBOR_Spec_Raw_EverParse_header){ .fst = x1, .snd = ite }); -} - -static bool -CBOR_Pulse_Raw_EverParse_Format_validate_header( - CBOR_Pulse_Raw_Slice_byte_slice input, - size_t *poffset -) -{ - size_t offset1 = *poffset; - size_t offset2 = *poffset; - size_t offset30 = *poffset; - bool ite0; - if (Pulse_Lib_Slice_len__uint8_t(input) - offset30 < (size_t)1U) - ite0 = false; - else - { - *poffset = offset30 + (size_t)1U; - ite0 = true; - } - bool ite1; - if (ite0) - { - size_t off = *poffset; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, offset2); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - off - offset2); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - CBOR_Spec_Raw_EverParse_initial_byte_t - x = - CBOR_Pulse_Raw_EverParse_Format_read_initial_byte_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst); - bool ite; - if (x.major_type == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - ite = x.additional_info <= CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS; - else - ite = true; - ite1 = ite && x.additional_info < CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_UNASSIGNED_MIN; - } - else - ite1 = false; - if (ite1) - { - size_t off = *poffset; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = Pulse_Lib_Slice_split__uint8_t(input, offset1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut0.fst, - .snd = scrut0.snd - } - ).snd, - off - offset1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Spec_Raw_EverParse_initial_byte_t - x = - CBOR_Pulse_Raw_EverParse_Format_read_initial_byte_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).fst); - if (x.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS) - if (x.major_type == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - { - size_t offset2 = *poffset; - size_t offset3 = *poffset; - bool ite; - if (Pulse_Lib_Slice_len__uint8_t(input) - offset3 < (size_t)1U) - ite = false; - else - { - *poffset = offset3 + (size_t)1U; - ite = true; - } - if (ite) - { - size_t off1 = *poffset; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, offset2); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - off1 - offset2); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - return - MIN_SIMPLE_VALUE_LONG_ARGUMENT <= - Pulse_Lib_Slice_op_Array_Access__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst, - (size_t)0U); - } - else - return false; - } - else - { - size_t offset2 = *poffset; - if (Pulse_Lib_Slice_len__uint8_t(input) - offset2 < (size_t)1U) - return false; - else - { - *poffset = offset2 + (size_t)1U; - return true; - } - } - else if (x.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_16_BITS) - { - size_t offset2 = *poffset; - if (Pulse_Lib_Slice_len__uint8_t(input) - offset2 < (size_t)2U) - return false; - else - { - *poffset = offset2 + (size_t)2U; - return true; - } - } - else if (x.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_32_BITS) - { - size_t offset2 = *poffset; - if (Pulse_Lib_Slice_len__uint8_t(input) - offset2 < (size_t)4U) - return false; - else - { - *poffset = offset2 + (size_t)4U; - return true; - } - } - else if (x.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_64_BITS) - { - size_t offset2 = *poffset; - if (Pulse_Lib_Slice_len__uint8_t(input) - offset2 < (size_t)8U) - return false; - else - { - *poffset = offset2 + (size_t)8U; - return true; - } - } - else - return true; - } - else - return false; -} - -static size_t -CBOR_Pulse_Raw_EverParse_Format_jump_header( - CBOR_Pulse_Raw_Slice_byte_slice input, - size_t offset -) -{ - size_t off1 = offset + (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, offset); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - off1 - offset); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - CBOR_Spec_Raw_EverParse_initial_byte_t - x = - CBOR_Pulse_Raw_EverParse_Format_read_initial_byte_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst); - if (x.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS) - return off1 + (size_t)1U; - else if (x.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_16_BITS) - return off1 + (size_t)2U; - else if (x.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_32_BITS) - return off1 + (size_t)4U; - else if (x.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_64_BITS) - return off1 + (size_t)8U; - else - return off1; -} - -static bool -CBOR_Pulse_Raw_EverParse_Format_validate_recursive_step_count_leaf( - CBOR_Pulse_Raw_Slice_byte_slice a, - size_t bound, - size_t *prem -) -{ - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(a, - CBOR_Pulse_Raw_EverParse_Format_jump_header(a, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - CBOR_Spec_Raw_EverParse_header - h = - CBOR_Pulse_Raw_EverParse_Format_read_header(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut0.fst, - .snd = scrut0.snd - } - ).fst); - uint8_t typ = CBOR_Spec_Raw_EverParse_get_header_major_type(h); - if (typ == CBOR_MAJOR_TYPE_ARRAY) - { - uint64_t arg64 = CBOR_Spec_Raw_EverParse_argument_as_uint64(h.fst, h.snd); - bool ite; - if (bound / (size_t)32768U / (size_t)32768U / (size_t)32768U / (size_t)32768U >= (size_t)16U) - ite = true; - else - ite = arg64 <= (uint64_t)bound; - if (ite) - { - *prem = (size_t)arg64; - return false; - } - else - return true; - } - else if (typ == CBOR_MAJOR_TYPE_MAP) - { - uint64_t arg64 = CBOR_Spec_Raw_EverParse_argument_as_uint64(h.fst, h.snd); - bool ite; - if (bound / (size_t)32768U / (size_t)32768U / (size_t)32768U / (size_t)32768U >= (size_t)16U) - ite = true; - else - ite = arg64 <= (uint64_t)bound; - if (ite) - { - size_t arg = (size_t)arg64; - if (bound - arg < arg) - return true; - else - { - *prem = arg + arg; - return false; - } - } - else - return true; - } - else if (typ == CBOR_MAJOR_TYPE_TAGGED) - { - *prem = (size_t)1U; - return false; - } - else - { - *prem = (size_t)0U; - return false; - } -} - -static size_t -CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header( - CBOR_Spec_Raw_EverParse_header h -) -{ - uint8_t typ = CBOR_Spec_Raw_EverParse_get_header_major_type(h); - if (typ == CBOR_MAJOR_TYPE_ARRAY) - return (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h.fst, h.snd); - else if (typ == CBOR_MAJOR_TYPE_MAP) - { - size_t arg = (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h.fst, h.snd); - return arg + arg; - } - else if (typ == CBOR_MAJOR_TYPE_TAGGED) - return (size_t)1U; - else - return (size_t)0U; -} - -static size_t -CBOR_Pulse_Raw_EverParse_Format_jump_recursive_step_count_leaf( - CBOR_Pulse_Raw_Slice_byte_slice a -) -{ - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(a, - CBOR_Pulse_Raw_EverParse_Format_jump_header(a, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - return - CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header(CBOR_Pulse_Raw_EverParse_Format_read_header(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut0.fst, - .snd = scrut0.snd - } - ).fst)); -} - -static bool -CBOR_Pulse_Raw_EverParse_Format_validate_raw_data_item( - CBOR_Pulse_Raw_Slice_byte_slice input, - size_t *poffset -) -{ - size_t pn = (size_t)1U; - bool pres = true; - while (pres && pn > (size_t)0U) - { - size_t off = *poffset; - size_t n = pn; - if (n > Pulse_Lib_Slice_len__uint8_t(input) - off) - pres = false; - else - { - size_t offset1 = *poffset; - bool ite0; - if (CBOR_Pulse_Raw_EverParse_Format_validate_header(input, poffset)) - { - size_t off1 = *poffset; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = Pulse_Lib_Slice_split__uint8_t(input, offset1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut0.fst, - .snd = scrut0.snd - } - ).snd, - off1 - offset1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Spec_Raw_EverParse_header - x = - CBOR_Pulse_Raw_EverParse_Format_read_header(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).fst); - CBOR_Spec_Raw_EverParse_initial_byte_t b = x.fst; - if - (b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING) - { - size_t offset2 = *poffset; - size_t offset3 = *poffset; - size_t remaining = Pulse_Lib_Slice_len__uint8_t(input) - offset3; - bool ite1; - if - ( - remaining / (size_t)32768U / (size_t)32768U / (size_t)32768U / (size_t)32768U >= - (size_t)16U - ) - ite1 = true; - else - { - uint64_t b64 = (uint64_t)remaining; - ite1 = CBOR_Spec_Raw_EverParse_argument_as_uint64(x.fst, x.snd) <= b64; - } - bool ite; - if (ite1) - { - *poffset = offset3 + (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(x.fst, x.snd); - ite = true; - } - else - ite = false; - if (ite) - { - size_t off2 = *poffset; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, offset2); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - off2 - offset2); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - x1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst; - if (CBOR_Spec_Raw_EverParse_get_header_major_type(x) == CBOR_MAJOR_TYPE_BYTE_STRING) - ite0 = true; - else - ite0 = CBOR_Pulse_Raw_EverParse_UTF8_impl_correct(x1); - } - else - ite0 = false; - } - else - ite0 = true; - } - else - ite0 = false; - if (!ite0) - pres = false; - else - { - size_t offset1 = *poffset; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, off); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - offset1 - off); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - input1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst; - size_t bound = Pulse_Lib_Slice_len__uint8_t(input) - off - n; - bool - res2 = - CBOR_Pulse_Raw_EverParse_Format_validate_recursive_step_count_leaf(input1, - bound, - &pn); - size_t count = pn; - if (res2 || count > bound) - pres = false; - else - pn = n - (size_t)1U + count; - } - } - } - return pres; -} - -static size_t -CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item( - CBOR_Pulse_Raw_Slice_byte_slice input, - size_t offset -) -{ - size_t poffset = offset; - size_t pn = (size_t)1U; - while (pn > (size_t)0U) - { - size_t off = poffset; - size_t off10 = CBOR_Pulse_Raw_EverParse_Format_jump_header(input, off); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = Pulse_Lib_Slice_split__uint8_t(input, off); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut0.fst, - .snd = scrut0.snd - } - ).snd, - off10 - off); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Spec_Raw_EverParse_header - x = - CBOR_Pulse_Raw_EverParse_Format_read_header(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).fst); - CBOR_Spec_Raw_EverParse_initial_byte_t b = x.fst; - size_t off1; - if (b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING) - off1 = off10 + (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(x.fst, x.snd); - else - off1 = off10; - poffset = off1; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, off); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - off1 - off); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - input1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut4.fst, - .snd = scrut4.snd - } - ).fst; - size_t n = pn; - size_t unused = Pulse_Lib_Slice_len__uint8_t(input) - off1; - KRML_MAYBE_UNUSED_VAR(unused); - pn = n - (size_t)1U + CBOR_Pulse_Raw_EverParse_Format_jump_recursive_step_count_leaf(input1); - } - return poffset; -} - -static cbor_raw -CBOR_Pulse_Raw_EverParse_Serialized_Base_cbor_read(CBOR_Pulse_Raw_Slice_byte_slice input) -{ - CBOR_Spec_Raw_EverParse_header - ph = - { - .fst = { .major_type = CBOR_MAJOR_TYPE_SIMPLE_VALUE, .additional_info = 0U }, - .snd = { .tag = CBOR_Spec_Raw_EverParse_LongArgumentOther } - }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(input, - CBOR_Pulse_Raw_EverParse_Format_jump_header(input, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - CBOR_Pulse_Raw_Slice_byte_slice outc = scrut1.snd; - ph = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut1.fst); - CBOR_Pulse_Raw_Slice_byte_slice pc = outc; - CBOR_Spec_Raw_EverParse_header h = ph; - uint8_t typ = h.fst.major_type; - if (typ == CBOR_MAJOR_TYPE_UINT64 || typ == CBOR_MAJOR_TYPE_NEG_INT64) - { - CBOR_Spec_Raw_EverParse_initial_byte_t b = h.fst; - CBOR_Spec_Raw_EverParse_long_argument l = h.snd; - CBOR_Spec_Raw_Base_raw_uint64 i; - if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU8) - i = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 1U, .value = (uint64_t)l.case_LongArgumentU8 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU16) - i = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 2U, .value = (uint64_t)l.case_LongArgumentU16 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU32) - i = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 3U, .value = (uint64_t)l.case_LongArgumentU32 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU64) - i = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 4U, .value = l.case_LongArgumentU64 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - i = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 0U, .value = (uint64_t)b.additional_info }); - else - i = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return - ( - (cbor_raw){ - .tag = CBOR_Case_Int, - { - .case_CBOR_Case_Int = { - .cbor_int_type = typ, - .cbor_int_size = i.size, - .cbor_int_value = i.value - } - } - } - ); - } - else if (typ == CBOR_MAJOR_TYPE_TEXT_STRING || typ == CBOR_MAJOR_TYPE_BYTE_STRING) - { - CBOR_Spec_Raw_EverParse_initial_byte_t b = h.fst; - CBOR_Spec_Raw_EverParse_long_argument l = h.snd; - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU8) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 1U, .value = (uint64_t)l.case_LongArgumentU8 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU16) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 2U, .value = (uint64_t)l.case_LongArgumentU16 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU32) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 3U, .value = (uint64_t)l.case_LongArgumentU32 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU64) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 4U, .value = l.case_LongArgumentU64 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 0U, .value = (uint64_t)b.additional_info }); - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return - ( - (cbor_raw){ - .tag = CBOR_Case_String, - { - .case_CBOR_Case_String = { - .cbor_string_type = typ, - .cbor_string_size = ite.size, - .cbor_string_ptr = pc - } - } - } - ); - } - else if (typ == CBOR_MAJOR_TYPE_TAGGED) - { - CBOR_Spec_Raw_EverParse_initial_byte_t b = h.fst; - CBOR_Spec_Raw_EverParse_long_argument l = h.snd; - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU8) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 1U, .value = (uint64_t)l.case_LongArgumentU8 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU16) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 2U, .value = (uint64_t)l.case_LongArgumentU16 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU32) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 3U, .value = (uint64_t)l.case_LongArgumentU32 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU64) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 4U, .value = l.case_LongArgumentU64 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 0U, .value = (uint64_t)b.additional_info }); - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return - ( - (cbor_raw){ - .tag = CBOR_Case_Serialized_Tagged, - { - .case_CBOR_Case_Serialized_Tagged = { - .cbor_serialized_header = ite, - .cbor_serialized_payload = pc - } - } - } - ); - } - else if (typ == CBOR_MAJOR_TYPE_ARRAY) - { - CBOR_Spec_Raw_EverParse_initial_byte_t b = h.fst; - CBOR_Spec_Raw_EverParse_long_argument l = h.snd; - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU8) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 1U, .value = (uint64_t)l.case_LongArgumentU8 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU16) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 2U, .value = (uint64_t)l.case_LongArgumentU16 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU32) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 3U, .value = (uint64_t)l.case_LongArgumentU32 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU64) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 4U, .value = l.case_LongArgumentU64 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 0U, .value = (uint64_t)b.additional_info }); - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return - ( - (cbor_raw){ - .tag = CBOR_Case_Serialized_Array, - { - .case_CBOR_Case_Serialized_Array = { - .cbor_serialized_header = ite, - .cbor_serialized_payload = pc - } - } - } - ); - } - else if (typ == CBOR_MAJOR_TYPE_MAP) - { - CBOR_Spec_Raw_EverParse_initial_byte_t b = h.fst; - CBOR_Spec_Raw_EverParse_long_argument l = h.snd; - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU8) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 1U, .value = (uint64_t)l.case_LongArgumentU8 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU16) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 2U, .value = (uint64_t)l.case_LongArgumentU16 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU32) - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 3U, .value = (uint64_t)l.case_LongArgumentU32 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentU64) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 4U, .value = l.case_LongArgumentU64 }); - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = 0U, .value = (uint64_t)b.additional_info }); - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return - ( - (cbor_raw){ - .tag = CBOR_Case_Serialized_Map, - { - .case_CBOR_Case_Serialized_Map = { - .cbor_serialized_header = ite, - .cbor_serialized_payload = pc - } - } - } - ); - } - else - { - CBOR_Spec_Raw_EverParse_initial_byte_t b = h.fst; - CBOR_Spec_Raw_EverParse_long_argument l = h.snd; - uint8_t ite; - if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = b.additional_info; - else if (l.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - ite = l.case_LongArgumentSimpleValue; - else - ite = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - return ((cbor_raw){ .tag = CBOR_Case_Simple, { .case_CBOR_Case_Simple = ite } }); - } -} - -static cbor_raw -CBOR_Pulse_Raw_Format_Parse_cbor_parse(CBOR_Pulse_Raw_Slice_byte_slice input, size_t len) -{ - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, (size_t)0U); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - len - (size_t)0U); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - return - CBOR_Pulse_Raw_EverParse_Serialized_Base_cbor_read(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst); -} - -static cbor_raw -CBOR_Pulse_Raw_Format_Serialized_cbor_match_serialized_tagged_get_payload(cbor_serialized c) -{ - return CBOR_Pulse_Raw_EverParse_Serialized_Base_cbor_read(c.cbor_serialized_payload); -} - -static cbor_raw -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_item(cbor_serialized c, uint64_t i) -{ - size_t pi = (size_t)0U; - CBOR_Pulse_Raw_Slice_byte_slice pres = c.cbor_serialized_payload; - while (pi < (size_t)i) - { - CBOR_Pulse_Raw_Slice_byte_slice res = pres; - size_t i1 = pi; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(res, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(res, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - res2 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).snd; - pi = i1 + (size_t)1U; - pres = res2; - } - CBOR_Pulse_Raw_Slice_byte_slice res = pres; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(res, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(res, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - return - CBOR_Pulse_Raw_EverParse_Serialized_Base_cbor_read(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst); -} - -static CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_init(cbor_serialized c) -{ - return - ( - (CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator){ - .s = c.cbor_serialized_payload, - .len = c.cbor_serialized_header.value - } - ); -} - -static bool -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_is_empty( - CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator c -) -{ - return c.len == 0ULL; -} - -static uint64_t -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_length( - CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator c -) -{ - return c.len; -} - -static cbor_raw -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_next( - cbor_array_iterator *pi, - CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator i -) -{ - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(i.s, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(i.s, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Pulse_Raw_Slice_byte_slice s2 = scrut2.snd; - cbor_raw res = CBOR_Pulse_Raw_EverParse_Serialized_Base_cbor_read(scrut2.fst); - *pi = - ( - (cbor_array_iterator){ - .tag = CBOR_Raw_Iterator_Serialized, - { .case_CBOR_Raw_Iterator_Serialized = { .s = s2, .len = i.len - 1ULL } } - } - ); - return res; -} - -static CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_truncate( - CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator c, - uint64_t len -) -{ - return ((CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator){ .s = c.s, .len = len }); -} - -static CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_map_iterator_init(cbor_serialized c) -{ - return - ( - (CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator){ - .s = c.cbor_serialized_payload, - .len = c.cbor_serialized_header.value - } - ); -} - -static bool -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_map_iterator_is_empty( - CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator c -) -{ - return c.len == 0ULL; -} - -static cbor_map_entry -CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_map_iterator_next( - cbor_map_iterator *pi, - CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator i -) -{ - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(i.s, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(i.s, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(i.s, (size_t)0U))); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - CBOR_Pulse_Raw_Slice_byte_slice s1 = scrut3.fst; - CBOR_Pulse_Raw_Slice_byte_slice s2 = scrut3.snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(s1, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(s1, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = { .fst = scrut4.fst, .snd = scrut4.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - CBOR_Pulse_Raw_Slice_byte_slice s21 = scrut6.snd; - cbor_raw res1 = CBOR_Pulse_Raw_EverParse_Serialized_Base_cbor_read(scrut6.fst); - cbor_map_entry - res = - { - .cbor_map_entry_key = res1, - .cbor_map_entry_value = CBOR_Pulse_Raw_EverParse_Serialized_Base_cbor_read(s21) - }; - *pi = - ( - (cbor_map_iterator){ - .tag = CBOR_Raw_Iterator_Serialized, - { .case_CBOR_Raw_Iterator_Serialized = { .s = s2, .len = i.len - 1ULL } } - } - ); - return res; -} - -static cbor_raw CBOR_Pulse_Raw_Read_cbor_match_tagged_get_payload(cbor_raw c) -{ - if (c.tag == CBOR_Case_Serialized_Tagged) - return - CBOR_Pulse_Raw_Format_Serialized_cbor_match_serialized_tagged_get_payload(c.case_CBOR_Case_Serialized_Tagged); - else if (c.tag == CBOR_Case_Tagged) - return *c.case_CBOR_Case_Tagged.cbor_tagged_ptr; - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static cbor_raw -Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_raw( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw a, - size_t i -) -{ - return a.elt[i]; -} - -static cbor_raw CBOR_Pulse_Raw_Read_cbor_array_item(cbor_raw c, uint64_t i) -{ - if (c.tag == CBOR_Case_Serialized_Array) - return - CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_item(c.case_CBOR_Case_Serialized_Array, - i); - else if (c.tag == CBOR_Case_Array) - return - Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_raw(c.case_CBOR_Case_Array.cbor_array_ptr, - (size_t)i); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static cbor_array_iterator CBOR_Pulse_Raw_Read_cbor_array_iterator_init(cbor_raw c) -{ - if (c.tag == CBOR_Case_Serialized_Array) - return - ( - (cbor_array_iterator){ - .tag = CBOR_Raw_Iterator_Serialized, - { - .case_CBOR_Raw_Iterator_Serialized = CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_init(c.case_CBOR_Case_Serialized_Array) - } - } - ); - else if (c.tag == CBOR_Case_Array) - return - ( - (cbor_array_iterator){ - .tag = CBOR_Raw_Iterator_Slice, - { .case_CBOR_Raw_Iterator_Slice = c.case_CBOR_Case_Array.cbor_array_ptr } - } - ); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static size_t -Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw s -) -{ - return s.len; -} - -static bool CBOR_Pulse_Raw_Read_cbor_array_iterator_is_empty(cbor_array_iterator c) -{ - if (c.tag == CBOR_Raw_Iterator_Slice) - return - Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(c.case_CBOR_Raw_Iterator_Slice) == - (size_t)0U; - else if (c.tag == CBOR_Raw_Iterator_Serialized) - return - CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_is_empty(c.case_CBOR_Raw_Iterator_Serialized); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static uint64_t CBOR_Pulse_Raw_Read_cbor_array_iterator_length(cbor_array_iterator c) -{ - if (c.tag == CBOR_Raw_Iterator_Slice) - return - (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(c.case_CBOR_Raw_Iterator_Slice); - else if (c.tag == CBOR_Raw_Iterator_Serialized) - return - CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_length(c.case_CBOR_Raw_Iterator_Serialized); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -typedef struct -K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_s -{ - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw fst; - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw snd; -} -K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw; - -static K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw -Pulse_Lib_Slice_split__CBOR_Pulse_Raw_Type_cbor_raw( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw s, - size_t i -) -{ - return - ( - (K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw){ - .fst = { .elt = s.elt, .len = i }, - .snd = { .elt = s.elt + i, .len = s.len - i } - } - ); -} - -static cbor_raw CBOR_Pulse_Raw_Read_cbor_array_iterator_next(cbor_array_iterator *pi) -{ - cbor_array_iterator scrut = *pi; - if (scrut.tag == CBOR_Raw_Iterator_Slice) - { - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw i1 = scrut.case_CBOR_Raw_Iterator_Slice; - cbor_raw res = Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_raw(i1, (size_t)0U); - *pi = - ( - (cbor_array_iterator){ - .tag = CBOR_Raw_Iterator_Slice, - { - .case_CBOR_Raw_Iterator_Slice = Pulse_Lib_Slice_split__CBOR_Pulse_Raw_Type_cbor_raw(i1, - (size_t)1U).snd - } - } - ); - return res; - } - else if (scrut.tag == CBOR_Raw_Iterator_Serialized) - return - CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_next(pi, - scrut.case_CBOR_Raw_Iterator_Serialized); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static cbor_array_iterator -CBOR_Pulse_Raw_Read_cbor_array_iterator_truncate(cbor_array_iterator c, uint64_t len) -{ - if (c.tag == CBOR_Raw_Iterator_Slice) - { - K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw - scrut = - Pulse_Lib_Slice_split__CBOR_Pulse_Raw_Type_cbor_raw(c.case_CBOR_Raw_Iterator_Slice, - (size_t)len); - return - ( - (cbor_array_iterator){ - .tag = CBOR_Raw_Iterator_Slice, - { - .case_CBOR_Raw_Iterator_Slice = ( - (K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).fst - } - } - ); - } - else if (c.tag == CBOR_Raw_Iterator_Serialized) - return - ( - (cbor_array_iterator){ - .tag = CBOR_Raw_Iterator_Serialized, - { - .case_CBOR_Raw_Iterator_Serialized = CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_array_iterator_truncate(c.case_CBOR_Raw_Iterator_Serialized, - len) - } - } - ); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static cbor_map_iterator CBOR_Pulse_Raw_Read_cbor_map_iterator_init(cbor_raw c) -{ - if (c.tag == CBOR_Case_Serialized_Map) - return - ( - (cbor_map_iterator){ - .tag = CBOR_Raw_Iterator_Serialized, - { - .case_CBOR_Raw_Iterator_Serialized = CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_map_iterator_init(c.case_CBOR_Case_Serialized_Map) - } - } - ); - else if (c.tag == CBOR_Case_Map) - return - ( - (cbor_map_iterator){ - .tag = CBOR_Raw_Iterator_Slice, - { .case_CBOR_Raw_Iterator_Slice = c.case_CBOR_Case_Map.cbor_map_ptr } - } - ); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static size_t -Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry s -) -{ - return s.len; -} - -static bool CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(cbor_map_iterator c) -{ - if (c.tag == CBOR_Raw_Iterator_Slice) - return - Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(c.case_CBOR_Raw_Iterator_Slice) == - (size_t)0U; - else if (c.tag == CBOR_Raw_Iterator_Serialized) - return - CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_map_iterator_is_empty(c.case_CBOR_Raw_Iterator_Serialized); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static cbor_map_entry -Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_map_entry( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry a, - size_t i -) -{ - return a.elt[i]; -} - -typedef struct -K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry_s -{ - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry fst; - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry snd; -} -K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry; - -static K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry -Pulse_Lib_Slice_split__CBOR_Pulse_Raw_Type_cbor_map_entry( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry s, - size_t i -) -{ - return - ( - (K___Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry_Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry){ - .fst = { .elt = s.elt, .len = i }, - .snd = { .elt = s.elt + i, .len = s.len - i } - } - ); -} - -static cbor_map_entry CBOR_Pulse_Raw_Read_cbor_map_iterator_next(cbor_map_iterator *pi) -{ - cbor_map_iterator scrut = *pi; - if (scrut.tag == CBOR_Raw_Iterator_Slice) - { - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry - i1 = scrut.case_CBOR_Raw_Iterator_Slice; - cbor_map_entry - res = Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_map_entry(i1, (size_t)0U); - *pi = - ( - (cbor_map_iterator){ - .tag = CBOR_Raw_Iterator_Slice, - { - .case_CBOR_Raw_Iterator_Slice = Pulse_Lib_Slice_split__CBOR_Pulse_Raw_Type_cbor_map_entry(i1, - (size_t)1U).snd - } - } - ); - return res; - } - else if (scrut.tag == CBOR_Raw_Iterator_Serialized) - return - CBOR_Pulse_Raw_Format_Serialized_cbor_serialized_map_iterator_next(pi, - scrut.case_CBOR_Raw_Iterator_Serialized); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static CBOR_Spec_Raw_EverParse_initial_byte_t -Prims___proj__Mkdtuple2__item___1__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument( - CBOR_Spec_Raw_EverParse_header pair -) -{ - return pair.fst; -} - -static CBOR_Spec_Raw_EverParse_initial_byte_t -FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument( - CBOR_Spec_Raw_EverParse_header t -) -{ - return - Prims___proj__Mkdtuple2__item___1__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(t); -} - -static void -Pulse_Lib_Slice_op_Array_Assignment__uint8_t( - CBOR_Pulse_Raw_Slice_byte_slice a, - size_t i, - uint8_t v -) -{ - a.elt[i] = v; -} - -static CBOR_Spec_Raw_EverParse_long_argument -Prims___proj__Mkdtuple2__item___2__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument( - CBOR_Spec_Raw_EverParse_header pair -) -{ - return pair.snd; -} - -static CBOR_Spec_Raw_EverParse_long_argument -FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument( - CBOR_Spec_Raw_EverParse_header t -) -{ - return - Prims___proj__Mkdtuple2__item___2__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(t); -} - -static size_t -CBOR_Pulse_Raw_Format_Serialize_write_header( - CBOR_Spec_Raw_EverParse_header x, - CBOR_Pulse_Raw_Slice_byte_slice out, - size_t offset -) -{ - CBOR_Spec_Raw_EverParse_initial_byte_t - xh1 = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(x); - size_t pos_ = offset + (size_t)1U; - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, - pos_ - (size_t)1U, - LowParse_BitFields_set_bitfield_gen8(LowParse_BitFields_set_bitfield_gen8(0U, - 0U, - 5U, - xh1.additional_info), - 5U, - 8U, - xh1.major_type)); - size_t res1 = pos_; - CBOR_Spec_Raw_EverParse_long_argument - x2_ = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(x); - if (xh1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS) - if (xh1.major_type == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - { - size_t pos_ = res1 + (size_t)1U; - uint8_t ite; - if (x2_.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - ite = x2_.case_LongArgumentSimpleValue; - else - ite = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_ - (size_t)1U, ite); - return pos_; - } - else - { - size_t pos_ = res1 + (size_t)1U; - uint8_t ite; - if (x2_.tag == CBOR_Spec_Raw_EverParse_LongArgumentU8) - ite = x2_.case_LongArgumentU8; - else - ite = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_ - (size_t)1U, ite); - return pos_; - } - else if (xh1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_16_BITS) - { - size_t pos_ = res1 + (size_t)2U; - uint16_t ite0; - if (x2_.tag == CBOR_Spec_Raw_EverParse_LongArgumentU16) - ite0 = x2_.case_LongArgumentU16; - else - ite0 = KRML_EABORT(uint16_t, "unreachable (pattern matches are exhaustive in F*)"); - uint8_t lo = (uint8_t)ite0; - size_t pos_1 = pos_ - (size_t)1U; - uint16_t ite; - if (x2_.tag == CBOR_Spec_Raw_EverParse_LongArgumentU16) - ite = x2_.case_LongArgumentU16; - else - ite = KRML_EABORT(uint16_t, "unreachable (pattern matches are exhaustive in F*)"); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, - pos_1 - (size_t)1U, - (uint8_t)((uint32_t)ite / 256U)); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_1, lo); - return pos_; - } - else if (xh1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_32_BITS) - { - size_t pos_ = res1 + (size_t)4U; - uint32_t ite0; - if (x2_.tag == CBOR_Spec_Raw_EverParse_LongArgumentU32) - ite0 = x2_.case_LongArgumentU32; - else - ite0 = KRML_EABORT(uint32_t, "unreachable (pattern matches are exhaustive in F*)"); - uint8_t lo = (uint8_t)ite0; - uint32_t ite; - if (x2_.tag == CBOR_Spec_Raw_EverParse_LongArgumentU32) - ite = x2_.case_LongArgumentU32; - else - ite = KRML_EABORT(uint32_t, "unreachable (pattern matches are exhaustive in F*)"); - uint32_t hi = ite / 256U; - size_t pos_1 = pos_ - (size_t)1U; - uint8_t lo1 = (uint8_t)hi; - uint32_t hi1 = hi / 256U; - size_t pos_2 = pos_1 - (size_t)1U; - uint8_t lo2 = (uint8_t)hi1; - size_t pos_3 = pos_2 - (size_t)1U; - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_3 - (size_t)1U, (uint8_t)(hi1 / 256U)); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_3, lo2); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_2, lo1); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_1, lo); - return pos_; - } - else if (xh1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_64_BITS) - { - size_t pos_ = res1 + (size_t)8U; - uint64_t ite0; - if (x2_.tag == CBOR_Spec_Raw_EverParse_LongArgumentU64) - ite0 = x2_.case_LongArgumentU64; - else - ite0 = KRML_EABORT(uint64_t, "unreachable (pattern matches are exhaustive in F*)"); - uint8_t lo = (uint8_t)ite0; - uint64_t ite; - if (x2_.tag == CBOR_Spec_Raw_EverParse_LongArgumentU64) - ite = x2_.case_LongArgumentU64; - else - ite = KRML_EABORT(uint64_t, "unreachable (pattern matches are exhaustive in F*)"); - uint64_t hi = ite / 256ULL; - size_t pos_1 = pos_ - (size_t)1U; - uint8_t lo1 = (uint8_t)hi; - uint64_t hi1 = hi / 256ULL; - size_t pos_2 = pos_1 - (size_t)1U; - uint8_t lo2 = (uint8_t)hi1; - uint64_t hi2 = hi1 / 256ULL; - size_t pos_3 = pos_2 - (size_t)1U; - uint8_t lo3 = (uint8_t)hi2; - uint64_t hi3 = hi2 / 256ULL; - size_t pos_4 = pos_3 - (size_t)1U; - uint8_t lo4 = (uint8_t)hi3; - uint64_t hi4 = hi3 / 256ULL; - size_t pos_5 = pos_4 - (size_t)1U; - uint8_t lo5 = (uint8_t)hi4; - uint64_t hi5 = hi4 / 256ULL; - size_t pos_6 = pos_5 - (size_t)1U; - uint8_t lo6 = (uint8_t)hi5; - size_t pos_7 = pos_6 - (size_t)1U; - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_7 - (size_t)1U, (uint8_t)(hi5 / 256ULL)); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_7, lo6); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_6, lo5); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_5, lo4); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_4, lo3); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_3, lo2); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_2, lo1); - Pulse_Lib_Slice_op_Array_Assignment__uint8_t(out, pos_1, lo); - return pos_; - } - else - return res1; -} - -static bool -CBOR_Pulse_Raw_Format_Serialize_size_header(CBOR_Spec_Raw_EverParse_header x, size_t *out) -{ - CBOR_Spec_Raw_EverParse_initial_byte_t - xh1 = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(x); - size_t capacity = *out; - bool ite; - if (capacity < (size_t)1U) - ite = false; - else - { - *out = capacity - (size_t)1U; - ite = true; - } - if (ite) - { - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(x); - if (xh1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_8_BITS) - { - size_t capacity = *out; - if (capacity < (size_t)1U) - return false; - else - { - *out = capacity - (size_t)1U; - return true; - } - } - else if (xh1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_16_BITS) - { - size_t capacity = *out; - if (capacity < (size_t)2U) - return false; - else - { - *out = capacity - (size_t)2U; - return true; - } - } - else if (xh1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_32_BITS) - { - size_t capacity = *out; - if (capacity < (size_t)4U) - return false; - else - { - *out = capacity - (size_t)4U; - return true; - } - } - else if (xh1.additional_info == CBOR_SPEC_RAW_EVERPARSE_ADDITIONAL_INFO_LONG_ARGUMENT_64_BITS) - { - size_t capacity = *out; - if (capacity < (size_t)8U) - return false; - else - { - *out = capacity - (size_t)8U; - return true; - } - } - else - return true; - } - else - return false; -} - -static CBOR_Spec_Raw_EverParse_header -CBOR_Pulse_Raw_Format_Serialize_cbor_raw_get_header(cbor_raw xl) -{ - if (xl.tag == CBOR_Case_Int) - { - uint8_t ty; - if (xl.tag == CBOR_Case_Int) - ty = xl.case_CBOR_Case_Int.cbor_int_type; - else - ty = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (xl.tag == CBOR_Case_Int) - { - cbor_int c_ = xl.case_CBOR_Case_Int; - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = c_.cbor_int_size, .value = c_.cbor_int_value }); - } - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(ty, ite); - } - else if (xl.tag == CBOR_Case_String) - { - uint8_t ty; - if (xl.tag == CBOR_Case_String) - ty = xl.case_CBOR_Case_String.cbor_string_type; - else - ty = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (xl.tag == CBOR_Case_String) - { - cbor_string c_ = xl.case_CBOR_Case_String; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_string_size, - .value = (uint64_t)Pulse_Lib_Slice_len__uint8_t(c_.cbor_string_ptr) - } - ); - } - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(ty, ite); - } - else if (xl.tag == CBOR_Case_Tagged) - { - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (xl.tag == CBOR_Case_Tagged) - ite = xl.case_CBOR_Case_Tagged.cbor_tagged_tag; - else if (xl.tag == CBOR_Case_Serialized_Tagged) - ite = xl.case_CBOR_Case_Serialized_Tagged.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(CBOR_MAJOR_TYPE_TAGGED, ite); - } - else if (xl.tag == CBOR_Case_Serialized_Tagged) - { - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (xl.tag == CBOR_Case_Tagged) - ite = xl.case_CBOR_Case_Tagged.cbor_tagged_tag; - else if (xl.tag == CBOR_Case_Serialized_Tagged) - ite = xl.case_CBOR_Case_Serialized_Tagged.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(CBOR_MAJOR_TYPE_TAGGED, ite); - } - else if (xl.tag == CBOR_Case_Array) - { - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (xl.tag == CBOR_Case_Array) - { - cbor_array c_ = xl.case_CBOR_Case_Array; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_array_length_size, - .value = (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(c_.cbor_array_ptr) - } - ); - } - else if (xl.tag == CBOR_Case_Serialized_Array) - ite = xl.case_CBOR_Case_Serialized_Array.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(CBOR_MAJOR_TYPE_ARRAY, ite); - } - else if (xl.tag == CBOR_Case_Serialized_Array) - { - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (xl.tag == CBOR_Case_Array) - { - cbor_array c_ = xl.case_CBOR_Case_Array; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_array_length_size, - .value = (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(c_.cbor_array_ptr) - } - ); - } - else if (xl.tag == CBOR_Case_Serialized_Array) - ite = xl.case_CBOR_Case_Serialized_Array.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(CBOR_MAJOR_TYPE_ARRAY, ite); - } - else if (xl.tag == CBOR_Case_Map) - { - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (xl.tag == CBOR_Case_Map) - { - cbor_map c_ = xl.case_CBOR_Case_Map; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_map_length_size, - .value = (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(c_.cbor_map_ptr) - } - ); - } - else if (xl.tag == CBOR_Case_Serialized_Map) - ite = xl.case_CBOR_Case_Serialized_Map.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(CBOR_MAJOR_TYPE_MAP, ite); - } - else if (xl.tag == CBOR_Case_Serialized_Map) - { - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (xl.tag == CBOR_Case_Map) - { - cbor_map c_ = xl.case_CBOR_Case_Map; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_map_length_size, - .value = (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(c_.cbor_map_ptr) - } - ); - } - else if (xl.tag == CBOR_Case_Serialized_Map) - ite = xl.case_CBOR_Case_Serialized_Map.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_raw_uint64_as_argument(CBOR_MAJOR_TYPE_MAP, ite); - } - else if (xl.tag == CBOR_Case_Simple) - { - uint8_t ite; - if (xl.tag == CBOR_Case_Simple) - ite = xl.case_CBOR_Case_Simple; - else - ite = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Spec_Raw_EverParse_simple_value_as_argument(ite); - } - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static CBOR_Spec_Raw_EverParse_header -CBOR_Pulse_Raw_Format_Serialize_cbor_raw_with_perm_get_header(cbor_raw xl) -{ - return CBOR_Pulse_Raw_Format_Serialize_cbor_raw_get_header(xl); -} - -static void -Pulse_Lib_Slice_copy__uint8_t( - CBOR_Pulse_Raw_Slice_byte_slice dst, - CBOR_Pulse_Raw_Slice_byte_slice src -) -{ - memcpy(dst.elt, src.elt, src.len * sizeof (uint8_t)); -} - -typedef struct -FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_s -{ - FStar_Pervasives_Native_option__bool_tags tag; - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw v; -} -FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw; - -typedef struct -FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry_s -{ - FStar_Pervasives_Native_option__bool_tags tag; - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry v; -} -FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry; - -size_t -CBOR_Pulse_Raw_Format_Serialize_ser_( - cbor_raw x_, - CBOR_Pulse_Raw_Slice_byte_slice out, - size_t offset -) -{ - CBOR_Spec_Raw_EverParse_header - xh1 = CBOR_Pulse_Raw_Format_Serialize_cbor_raw_with_perm_get_header(x_); - size_t res1 = CBOR_Pulse_Raw_Format_Serialize_write_header(xh1, out, offset); - CBOR_Spec_Raw_EverParse_initial_byte_t b = xh1.fst; - if (b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING) - { - cbor_raw scrut = x_; - CBOR_Pulse_Raw_Slice_byte_slice x2_; - if (scrut.tag == CBOR_Case_String) - x2_ = scrut.case_CBOR_Case_String.cbor_string_ptr; - else - x2_ = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - size_t length = Pulse_Lib_Slice_len__uint8_t(x2_); - Pulse_Lib_Slice_copy__uint8_t(Pulse_Lib_Slice_split__uint8_t(Pulse_Lib_Slice_split__uint8_t(out, - res1).snd, - length).fst, - x2_); - return res1 + length; - } - else if (xh1.fst.major_type == CBOR_MAJOR_TYPE_ARRAY) - { - bool ite; - if (x_.tag == CBOR_Case_Array) - ite = true; - else - ite = false; - if (ite) - { - cbor_raw scrut0 = x_; - FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw - scrut; - if (scrut0.tag == CBOR_Case_Array) - scrut = - ( - (FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw){ - .tag = FStar_Pervasives_Native_Some, - .v = scrut0.case_CBOR_Case_Array.cbor_array_ptr - } - ); - else - scrut = - ( - (FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw){ - .tag = FStar_Pervasives_Native_None - } - ); - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw a; - if (scrut.tag == FStar_Pervasives_Native_Some) - a = scrut.v; - else - a = - KRML_EABORT(Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw, - "unreachable (pattern matches are exhaustive in F*)"); - size_t pres = res1; - size_t pi = (size_t)0U; - size_t len = Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(a); - while (pi < len) - { - size_t i = pi; - size_t off = pres; - size_t i_ = i + (size_t)1U; - size_t - res = - CBOR_Pulse_Raw_Format_Serialize_ser_(Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_raw(a, - i), - out, - off); - pi = i_; - pres = res; - } - return pres; - } - else - { - cbor_raw scrut = x_; - CBOR_Pulse_Raw_Slice_byte_slice x2_; - if (scrut.tag == CBOR_Case_Serialized_Array) - x2_ = scrut.case_CBOR_Case_Serialized_Array.cbor_serialized_payload; - else - x2_ = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - size_t length = Pulse_Lib_Slice_len__uint8_t(x2_); - Pulse_Lib_Slice_copy__uint8_t(Pulse_Lib_Slice_split__uint8_t(Pulse_Lib_Slice_split__uint8_t(out, - res1).snd, - length).fst, - x2_); - return res1 + length; - } - } - else if (xh1.fst.major_type == CBOR_MAJOR_TYPE_MAP) - { - bool ite; - if (x_.tag == CBOR_Case_Map) - ite = true; - else - ite = false; - if (ite) - { - cbor_raw scrut0 = x_; - FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry - scrut; - if (scrut0.tag == CBOR_Case_Map) - scrut = - ( - (FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry){ - .tag = FStar_Pervasives_Native_Some, - .v = scrut0.case_CBOR_Case_Map.cbor_map_ptr - } - ); - else - scrut = - ( - (FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry){ - .tag = FStar_Pervasives_Native_None - } - ); - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry a; - if (scrut.tag == FStar_Pervasives_Native_Some) - a = scrut.v; - else - a = - KRML_EABORT(Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry, - "unreachable (pattern matches are exhaustive in F*)"); - size_t pres = res1; - size_t pi = (size_t)0U; - size_t len = Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(a); - while (pi < len) - { - size_t i = pi; - size_t off = pres; - cbor_map_entry - e = Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_map_entry(a, i); - size_t i_ = i + (size_t)1U; - size_t - res = - CBOR_Pulse_Raw_Format_Serialize_ser_(e.cbor_map_entry_value, - out, - CBOR_Pulse_Raw_Format_Serialize_ser_(e.cbor_map_entry_key, out, off)); - pi = i_; - pres = res; - } - return pres; - } - else - { - cbor_raw scrut = x_; - CBOR_Pulse_Raw_Slice_byte_slice x2_; - if (scrut.tag == CBOR_Case_Serialized_Map) - x2_ = scrut.case_CBOR_Case_Serialized_Map.cbor_serialized_payload; - else - x2_ = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - size_t length = Pulse_Lib_Slice_len__uint8_t(x2_); - Pulse_Lib_Slice_copy__uint8_t(Pulse_Lib_Slice_split__uint8_t(Pulse_Lib_Slice_split__uint8_t(out, - res1).snd, - length).fst, - x2_); - return res1 + length; - } - } - else if (xh1.fst.major_type == CBOR_MAJOR_TYPE_TAGGED) - { - bool ite0; - if (x_.tag == CBOR_Case_Tagged) - ite0 = true; - else - ite0 = false; - if (ite0) - { - cbor_raw scrut = x_; - cbor_raw ite; - if (scrut.tag == CBOR_Case_Tagged) - ite = *scrut.case_CBOR_Case_Tagged.cbor_tagged_ptr; - else - ite = KRML_EABORT(cbor_raw, "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Pulse_Raw_Format_Serialize_ser_(ite, out, res1); - } - else - { - cbor_raw scrut = x_; - CBOR_Pulse_Raw_Slice_byte_slice x2_; - if (scrut.tag == CBOR_Case_Serialized_Tagged) - x2_ = scrut.case_CBOR_Case_Serialized_Tagged.cbor_serialized_payload; - else - x2_ = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - size_t length = Pulse_Lib_Slice_len__uint8_t(x2_); - Pulse_Lib_Slice_copy__uint8_t(Pulse_Lib_Slice_split__uint8_t(Pulse_Lib_Slice_split__uint8_t(out, - res1).snd, - length).fst, - x2_); - return res1 + length; - } - } - else - return res1; -} - -static size_t -CBOR_Pulse_Raw_Format_Serialize_ser( - cbor_raw x1_, - CBOR_Pulse_Raw_Slice_byte_slice out, - size_t offset -) -{ - return CBOR_Pulse_Raw_Format_Serialize_ser_(x1_, out, offset); -} - -static size_t -CBOR_Pulse_Raw_Format_Serialize_cbor_serialize( - cbor_raw x, - CBOR_Pulse_Raw_Slice_byte_slice output -) -{ - return CBOR_Pulse_Raw_Format_Serialize_ser(x, output, (size_t)0U); -} - -bool CBOR_Pulse_Raw_Format_Serialize_siz_(cbor_raw x_, size_t *out) -{ - CBOR_Spec_Raw_EverParse_header - xh1 = CBOR_Pulse_Raw_Format_Serialize_cbor_raw_with_perm_get_header(x_); - if (CBOR_Pulse_Raw_Format_Serialize_size_header(xh1, out)) - { - CBOR_Spec_Raw_EverParse_initial_byte_t b = xh1.fst; - if (b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING) - { - cbor_raw scrut = x_; - CBOR_Pulse_Raw_Slice_byte_slice ite; - if (scrut.tag == CBOR_Case_String) - ite = scrut.case_CBOR_Case_String.cbor_string_ptr; - else - ite = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - size_t length = Pulse_Lib_Slice_len__uint8_t(ite); - size_t cur = *out; - if (cur < length) - return false; - else - { - *out = cur - length; - return true; - } - } - else if (xh1.fst.major_type == CBOR_MAJOR_TYPE_ARRAY) - { - bool ite0; - if (x_.tag == CBOR_Case_Array) - ite0 = true; - else - ite0 = false; - if (ite0) - { - cbor_raw scrut0 = x_; - FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw - scrut; - if (scrut0.tag == CBOR_Case_Array) - scrut = - ( - (FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw){ - .tag = FStar_Pervasives_Native_Some, - .v = scrut0.case_CBOR_Case_Array.cbor_array_ptr - } - ); - else - scrut = - ( - (FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw){ - .tag = FStar_Pervasives_Native_None - } - ); - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw a; - if (scrut.tag == FStar_Pervasives_Native_Some) - a = scrut.v; - else - a = - KRML_EABORT(Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw, - "unreachable (pattern matches are exhaustive in F*)"); - bool pres = true; - size_t pi = (size_t)0U; - size_t len = Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(a); - while (pres && pi < len) - { - size_t i = pi; - if - ( - CBOR_Pulse_Raw_Format_Serialize_siz_(Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_raw(a, - i), - out) - ) - pi = i + (size_t)1U; - else - pres = false; - } - return pres; - } - else - { - cbor_raw scrut = x_; - CBOR_Pulse_Raw_Slice_byte_slice ite; - if (scrut.tag == CBOR_Case_Serialized_Array) - ite = scrut.case_CBOR_Case_Serialized_Array.cbor_serialized_payload; - else - ite = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - size_t length = Pulse_Lib_Slice_len__uint8_t(ite); - size_t cur = *out; - if (cur < length) - return false; - else - { - *out = cur - length; - return true; - } - } - } - else if (xh1.fst.major_type == CBOR_MAJOR_TYPE_MAP) - { - bool ite0; - if (x_.tag == CBOR_Case_Map) - ite0 = true; - else - ite0 = false; - if (ite0) - { - cbor_raw scrut0 = x_; - FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry - scrut; - if (scrut0.tag == CBOR_Case_Map) - scrut = - ( - (FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry){ - .tag = FStar_Pervasives_Native_Some, - .v = scrut0.case_CBOR_Case_Map.cbor_map_ptr - } - ); - else - scrut = - ( - (FStar_Pervasives_Native_option__LowParse_Pulse_Base_with_perm__Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry){ - .tag = FStar_Pervasives_Native_None - } - ); - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry a; - if (scrut.tag == FStar_Pervasives_Native_Some) - a = scrut.v; - else - a = - KRML_EABORT(Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry, - "unreachable (pattern matches are exhaustive in F*)"); - bool pres = true; - size_t pi = (size_t)0U; - size_t len = Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(a); - while (pres && pi < len) - { - size_t i = pi; - cbor_map_entry - e = Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_map_entry(a, i); - bool ite; - if (CBOR_Pulse_Raw_Format_Serialize_siz_(e.cbor_map_entry_key, out)) - ite = CBOR_Pulse_Raw_Format_Serialize_siz_(e.cbor_map_entry_value, out); - else - ite = false; - if (ite) - pi = i + (size_t)1U; - else - pres = false; - } - return pres; - } - else - { - cbor_raw scrut = x_; - CBOR_Pulse_Raw_Slice_byte_slice ite; - if (scrut.tag == CBOR_Case_Serialized_Map) - ite = scrut.case_CBOR_Case_Serialized_Map.cbor_serialized_payload; - else - ite = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - size_t length = Pulse_Lib_Slice_len__uint8_t(ite); - size_t cur = *out; - if (cur < length) - return false; - else - { - *out = cur - length; - return true; - } - } - } - else if (xh1.fst.major_type == CBOR_MAJOR_TYPE_TAGGED) - { - bool ite0; - if (x_.tag == CBOR_Case_Tagged) - ite0 = true; - else - ite0 = false; - if (ite0) - { - cbor_raw scrut = x_; - cbor_raw ite; - if (scrut.tag == CBOR_Case_Tagged) - ite = *scrut.case_CBOR_Case_Tagged.cbor_tagged_ptr; - else - ite = KRML_EABORT(cbor_raw, "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Pulse_Raw_Format_Serialize_siz_(ite, out); - } - else - { - cbor_raw scrut = x_; - CBOR_Pulse_Raw_Slice_byte_slice ite; - if (scrut.tag == CBOR_Case_Serialized_Tagged) - ite = scrut.case_CBOR_Case_Serialized_Tagged.cbor_serialized_payload; - else - ite = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - size_t length = Pulse_Lib_Slice_len__uint8_t(ite); - size_t cur = *out; - if (cur < length) - return false; - else - { - *out = cur - length; - return true; - } - } - } - else - return true; - } - else - return false; -} - -static bool CBOR_Pulse_Raw_Format_Serialize_siz(cbor_raw x1_, size_t *out) -{ - return CBOR_Pulse_Raw_Format_Serialize_siz_(x1_, out); -} - -static size_t CBOR_Pulse_Raw_Format_Serialize_cbor_size(cbor_raw x, size_t bound) -{ - size_t output = bound; - if (CBOR_Pulse_Raw_Format_Serialize_siz(x, &output)) - return bound - output; - else - return (size_t)0U; -} - -static uint8_t CBOR_Pulse_Raw_Compare_impl_major_type(cbor_raw x) -{ - if (x.tag == CBOR_Case_Simple) - return CBOR_MAJOR_TYPE_SIMPLE_VALUE; - else if (x.tag == CBOR_Case_Int) - if (x.tag == CBOR_Case_Int) - return x.case_CBOR_Case_Int.cbor_int_type; - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - else if (x.tag == CBOR_Case_String) - if (x.tag == CBOR_Case_String) - return x.case_CBOR_Case_String.cbor_string_type; - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - else if (x.tag == CBOR_Case_Tagged) - return CBOR_MAJOR_TYPE_TAGGED; - else if (x.tag == CBOR_Case_Serialized_Tagged) - return CBOR_MAJOR_TYPE_TAGGED; - else if (x.tag == CBOR_Case_Array) - return CBOR_MAJOR_TYPE_ARRAY; - else if (x.tag == CBOR_Case_Serialized_Array) - return CBOR_MAJOR_TYPE_ARRAY; - else if (x.tag == CBOR_Case_Map) - return CBOR_MAJOR_TYPE_MAP; - else if (x.tag == CBOR_Case_Serialized_Map) - return CBOR_MAJOR_TYPE_MAP; - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -bool -CBOR_Pulse_Raw_EverParse_Nondet_Gen_impl_check_map_depth_aux( - size_t bound, - CBOR_Pulse_Raw_Slice_byte_slice *pl, - size_t n1 -) -{ - size_t pn = n1; - bool pres = true; - while (pres && pn > (size_t)0U) - { - CBOR_Pulse_Raw_Slice_byte_slice l = *pl; - size_t n_ = pn - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(l, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl_ = scrut3.snd; - CBOR_Spec_Raw_EverParse_header h = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut3.fst); - CBOR_Spec_Raw_EverParse_initial_byte_t b = h.fst; - size_t ite; - if (b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING) - ite = (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h.fst, h.snd); - else - ite = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = Pulse_Lib_Slice_split__uint8_t(tl_, ite); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = { .fst = scrut4.fst, .snd = scrut4.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut7.fst, - .snd = scrut7.snd - } - ).snd; - uint8_t m = CBOR_Spec_Raw_EverParse_get_header_major_type(h); - if (m == CBOR_MAJOR_TYPE_TAGGED) - *pl = tl; - else if (m == CBOR_MAJOR_TYPE_ARRAY) - { - *pl = tl; - pn = CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header(h) + n_; - } - else if (m == CBOR_MAJOR_TYPE_MAP) - if (bound == (size_t)0U) - pres = false; - else - { - *pl = tl; - if - ( - CBOR_Pulse_Raw_EverParse_Nondet_Gen_impl_check_map_depth_aux(bound - (size_t)1U, - pl, - CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header(h)) - ) - pn = n_; - else - pres = false; - } - else - { - *pl = tl; - pn = n_; - } - } - return pres; -} - -static bool -CBOR_Pulse_Raw_EverParse_Nondet_Gen_impl_check_map_depth( - size_t bound, - size_t n0, - CBOR_Pulse_Raw_Slice_byte_slice l0 -) -{ - CBOR_Pulse_Raw_Slice_byte_slice buf = l0; - return CBOR_Pulse_Raw_EverParse_Nondet_Gen_impl_check_map_depth_aux(bound, &buf, n0); -} - -static bool -FStar_Pervasives_Native_uu___is_None__size_t(FStar_Pervasives_Native_option__size_t projectee) -{ - if (projectee.tag == FStar_Pervasives_Native_None) - return true; - else - return false; -} - -static bool -CBOR_Pulse_Raw_EverParse_Nondet_Gen_impl_check_map_depth_opt( - FStar_Pervasives_Native_option__size_t bound, - size_t n0, - CBOR_Pulse_Raw_Slice_byte_slice l0 -) -{ - if (FStar_Pervasives_Native_uu___is_None__size_t(bound)) - return true; - else - { - size_t ite; - if (bound.tag == FStar_Pervasives_Native_Some) - ite = bound.v; - else - ite = KRML_EABORT(size_t, "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Pulse_Raw_EverParse_Nondet_Gen_impl_check_map_depth(ite, n0, l0); - } -} - -static bool -FStar_Pervasives_Native_uu___is_None__bool(FStar_Pervasives_Native_option__bool projectee) -{ - if (projectee.tag == FStar_Pervasives_Native_None) - return true; - else - return false; -} - -FStar_Pervasives_Native_option__bool -CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_map_hd_basic( - FStar_Pervasives_Native_option__size_t map_bound, - CBOR_Pulse_Raw_Slice_byte_slice l1, - CBOR_Pulse_Raw_Slice_byte_slice l2 -) -{ - if (false) - return - ((FStar_Pervasives_Native_option__bool){ .tag = FStar_Pervasives_Native_Some, .v = true }); - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l1, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Spec_Raw_EverParse_header - h1 = - CBOR_Pulse_Raw_EverParse_Format_read_header(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).fst); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = - Pulse_Lib_Slice_split__uint8_t(l2, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l2, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = { .fst = scrut4.fst, .snd = scrut4.snd }; - CBOR_Spec_Raw_EverParse_header - h2 = - CBOR_Pulse_Raw_EverParse_Format_read_header(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut5.fst, - .snd = scrut5.snd - } - ).fst); - uint8_t mt1 = CBOR_Spec_Raw_EverParse_get_header_major_type(h1); - if - ( - mt1 == CBOR_MAJOR_TYPE_MAP && - CBOR_Spec_Raw_EverParse_get_header_major_type(h2) == CBOR_MAJOR_TYPE_MAP - ) - if (CBOR_Pulse_Raw_Util_eq_Some_0sz(map_bound)) - return ((FStar_Pervasives_Native_option__bool){ .tag = FStar_Pervasives_Native_None }); - else - { - FStar_Pervasives_Native_option__size_t map_bound_; - if (map_bound.tag == FStar_Pervasives_Native_None) - map_bound_ = - ((FStar_Pervasives_Native_option__size_t){ .tag = FStar_Pervasives_Native_None }); - else if (map_bound.tag == FStar_Pervasives_Native_Some) - map_bound_ = - ( - (FStar_Pervasives_Native_option__size_t){ - .tag = FStar_Pervasives_Native_Some, - .v = map_bound.v - (size_t)1U - } - ); - else - map_bound_ = - KRML_EABORT(FStar_Pervasives_Native_option__size_t, - "unreachable (pattern matches are exhaustive in F*)"); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l1, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - map1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).fst; - CBOR_Spec_Raw_EverParse_header ph = h1; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = - Pulse_Lib_Slice_split__uint8_t(map1, - CBOR_Pulse_Raw_EverParse_Format_jump_header(map1, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = { .fst = scrut4.fst, .snd = scrut4.snd }; - CBOR_Pulse_Raw_Slice_byte_slice outc0 = scrut5.snd; - ph = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut5.fst); - CBOR_Pulse_Raw_Slice_byte_slice c1 = outc0; - size_t - nv1 = - (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h1), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h1)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = - Pulse_Lib_Slice_split__uint8_t(l2, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l2, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - map2 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut8.fst, - .snd = scrut8.snd - } - ).fst; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = - Pulse_Lib_Slice_split__uint8_t(map2, - CBOR_Pulse_Raw_EverParse_Format_jump_header(map2, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut10 = { .fst = scrut9.fst, .snd = scrut9.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut11 = { .fst = scrut10.fst, .snd = scrut10.snd }; - CBOR_Pulse_Raw_Slice_byte_slice outc = scrut11.snd; - ph = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut11.fst); - CBOR_Pulse_Raw_Slice_byte_slice c2 = outc; - size_t - nv2 = - (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h2), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h2)); - CBOR_Pulse_Raw_Slice_byte_slice pl = c1; - size_t pn0 = nv1; - FStar_Pervasives_Native_option__bool - pres0 = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n0 = pn0; - bool cond = n0 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_true(pres0); - while (cond) - { - CBOR_Pulse_Raw_Slice_byte_slice l = pl; - size_t n_ = pn0 - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lh = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt = scrut4.snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = - Pulse_Lib_Slice_split__uint8_t(lt, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(lt, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lv = scrut9.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt_ = scrut9.snd; - CBOR_Pulse_Raw_Slice_byte_slice pll = c2; - size_t pn1 = nv2; - FStar_Pervasives_Native_option__bool - pres1 = { .tag = FStar_Pervasives_Native_Some, .v = false }; - bool pcont = true; - size_t n3 = pn1; - bool cont0 = pcont; - bool cond0 = n3 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_false(pres1) && cont0; - while (cond0) - { - CBOR_Pulse_Raw_Slice_byte_slice l3 = pll; - size_t n_1 = pn1 - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l3, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l3, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lt1 = scrut4.snd; - size_t pn2 = (size_t)1U; - CBOR_Pulse_Raw_Slice_byte_slice pl10 = lh; - CBOR_Pulse_Raw_Slice_byte_slice pl20 = scrut4.fst; - FStar_Pervasives_Native_option__bool - pres20 = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n40 = pn2; - bool cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres20) && n40 > (size_t)0U; - while (cond) - { - CBOR_Pulse_Raw_Slice_byte_slice l1_ = pl10; - CBOR_Pulse_Raw_Slice_byte_slice l2_ = pl20; - FStar_Pervasives_Native_option__bool - r = - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_map_hd_basic(map_bound_, - l1_, - l2_); - if (FStar_Pervasives_Native_uu___is_None__bool(r)) - pres20 = r; - else - { - size_t n4 = pn2; - if (CBOR_Pulse_Raw_Util_eq_Some_true(r)) - { - size_t n_2 = n4 - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl2 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut4.fst, - .snd = scrut4.snd - } - ).snd; - pn2 = n_2; - pl10 = tl1; - pl20 = tl2; - } - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl1 = scrut4.snd; - CBOR_Spec_Raw_EverParse_header - h11 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut4.fst); - uint8_t mt11 = CBOR_Spec_Raw_EverParse_get_header_major_type(h11); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl2 = scrut9.snd; - CBOR_Spec_Raw_EverParse_header - h21 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut9.fst); - if (mt11 != CBOR_Spec_Raw_EverParse_get_header_major_type(h21)) - pres20 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - else - { - CBOR_Spec_Raw_EverParse_initial_byte_t b0 = h11.fst; - size_t ite0; - if - ( - b0.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b0.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite0 = (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h11.fst, h11.snd); - else - ite0 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = Pulse_Lib_Slice_split__uint8_t(tl1, ite0); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc1 = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl1_ = scrut4.snd; - size_t - n_2 = - CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header(h11) + - n4 - (size_t)1U; - CBOR_Spec_Raw_EverParse_initial_byte_t b = h21.fst; - size_t ite1; - if - ( - b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite1 = (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h21.fst, h21.snd); - else - ite1 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = Pulse_Lib_Slice_split__uint8_t(tl2, ite1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc2 = scrut9.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl2_ = scrut9.snd; - uint8_t mt12 = CBOR_Spec_Raw_EverParse_get_header_major_type(h11); - bool ite2; - if (mt12 == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - { - CBOR_Spec_Raw_EverParse_long_argument - scrut0 = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11); - uint8_t sv1; - if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - sv1 = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11).additional_info; - else if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - sv1 = scrut0.case_LongArgumentSimpleValue; - else - sv1 = - KRML_EABORT(uint8_t, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_EverParse_long_argument - scrut = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21); - uint8_t ite; - if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21).additional_info; - else if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - ite = scrut.case_LongArgumentSimpleValue; - else - ite = - KRML_EABORT(uint8_t, - "unreachable (pattern matches are exhaustive in F*)"); - ite2 = sv1 == ite; - } - else - { - uint64_t - len = - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11)); - if - ( - len != - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21)) - ) - ite2 = false; - else if - (mt12 == CBOR_MAJOR_TYPE_BYTE_STRING || mt12 == CBOR_MAJOR_TYPE_TEXT_STRING) - ite2 = - CBOR_Pulse_Raw_Compare_Bytes_lex_compare_bytes(lc1, lc2) == (int16_t)0; - else - ite2 = mt12 != CBOR_MAJOR_TYPE_MAP; - } - if (ite2) - { - pn2 = n_2; - pl10 = tl1_; - pl20 = tl2_; - } - else - pres20 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - } - } - } - size_t n4 = pn2; - cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres20) && n4 > (size_t)0U; - } - FStar_Pervasives_Native_option__bool res = pres20; - if (FStar_Pervasives_Native_uu___is_None__bool(res)) - pres1 = res; - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(lt1, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(lt1, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lv1 = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt_1 = scrut4.snd; - bool ite0; - if (res.tag == FStar_Pervasives_Native_Some) - ite0 = res.v; - else - ite0 = KRML_EABORT(bool, "unreachable (pattern matches are exhaustive in F*)"); - if (ite0) - { - size_t pn2 = (size_t)1U; - CBOR_Pulse_Raw_Slice_byte_slice pl1 = lv; - CBOR_Pulse_Raw_Slice_byte_slice pl2 = lv1; - FStar_Pervasives_Native_option__bool - pres2 = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n40 = pn2; - bool cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres2) && n40 > (size_t)0U; - while (cond) - { - CBOR_Pulse_Raw_Slice_byte_slice l1_ = pl1; - CBOR_Pulse_Raw_Slice_byte_slice l2_ = pl2; - FStar_Pervasives_Native_option__bool - r = - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_map_hd_basic(map_bound_, - l1_, - l2_); - if (FStar_Pervasives_Native_uu___is_None__bool(r)) - pres2 = r; - else - { - size_t n4 = pn2; - if (CBOR_Pulse_Raw_Util_eq_Some_true(r)) - { - size_t n_2 = n4 - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl2 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut4.fst, - .snd = scrut4.snd - } - ).snd; - pn2 = n_2; - pl1 = tl1; - pl2 = tl2; - } - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl1 = scrut4.snd; - CBOR_Spec_Raw_EverParse_header - h11 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut4.fst); - uint8_t mt11 = CBOR_Spec_Raw_EverParse_get_header_major_type(h11); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl2 = scrut9.snd; - CBOR_Spec_Raw_EverParse_header - h21 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut9.fst); - if (mt11 != CBOR_Spec_Raw_EverParse_get_header_major_type(h21)) - pres2 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - else - { - CBOR_Spec_Raw_EverParse_initial_byte_t b0 = h11.fst; - size_t ite0; - if - ( - b0.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b0.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite0 = - (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h11.fst, h11.snd); - else - ite0 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = Pulse_Lib_Slice_split__uint8_t(tl1, ite0); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc1 = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl1_ = scrut4.snd; - size_t - n_2 = - CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header(h11) + - n4 - (size_t)1U; - CBOR_Spec_Raw_EverParse_initial_byte_t b = h21.fst; - size_t ite1; - if - ( - b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite1 = - (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h21.fst, h21.snd); - else - ite1 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = Pulse_Lib_Slice_split__uint8_t(tl2, ite1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc2 = scrut9.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl2_ = scrut9.snd; - uint8_t mt12 = CBOR_Spec_Raw_EverParse_get_header_major_type(h11); - bool ite2; - if (mt12 == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - { - CBOR_Spec_Raw_EverParse_long_argument - scrut0 = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11); - uint8_t sv1; - if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - sv1 = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11).additional_info; - else if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - sv1 = scrut0.case_LongArgumentSimpleValue; - else - sv1 = - KRML_EABORT(uint8_t, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_EverParse_long_argument - scrut = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21); - uint8_t ite; - if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21).additional_info; - else if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - ite = scrut.case_LongArgumentSimpleValue; - else - ite = - KRML_EABORT(uint8_t, - "unreachable (pattern matches are exhaustive in F*)"); - ite2 = sv1 == ite; - } - else - { - uint64_t - len = - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11)); - if - ( - len != - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21)) - ) - ite2 = false; - else if - ( - mt12 == CBOR_MAJOR_TYPE_BYTE_STRING || - mt12 == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite2 = - CBOR_Pulse_Raw_Compare_Bytes_lex_compare_bytes(lc1, lc2) == (int16_t)0; - else - ite2 = mt12 != CBOR_MAJOR_TYPE_MAP; - } - if (ite2) - { - pn2 = n_2; - pl1 = tl1_; - pl2 = tl2_; - } - else - pres2 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - } - } - } - size_t n4 = pn2; - cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres2) && n4 > (size_t)0U; - } - pres1 = pres2; - pcont = false; - } - else - { - pll = lt_1; - pn1 = n_1; - } - } - size_t n3 = pn1; - bool cont = pcont; - cond0 = n3 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_false(pres1) && cont; - } - FStar_Pervasives_Native_option__bool res = pres1; - if (CBOR_Pulse_Raw_Util_eq_Some_true(res)) - { - pl = lt_; - pn0 = n_; - } - else - pres0 = res; - size_t n = pn0; - cond = n > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_true(pres0); - } - FStar_Pervasives_Native_option__bool res = pres0; - if (CBOR_Pulse_Raw_Util_eq_Some_true(res)) - { - CBOR_Pulse_Raw_Slice_byte_slice pl = c2; - size_t pn = nv2; - FStar_Pervasives_Native_option__bool - pres = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n = pn; - bool cond = n > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_true(pres); - while (cond) - { - CBOR_Pulse_Raw_Slice_byte_slice l = pl; - size_t n_ = pn - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lh = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt = scrut4.snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = - Pulse_Lib_Slice_split__uint8_t(lt, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(lt, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lv = scrut9.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt_ = scrut9.snd; - CBOR_Pulse_Raw_Slice_byte_slice pll = c1; - size_t pn1 = nv1; - FStar_Pervasives_Native_option__bool - pres1 = { .tag = FStar_Pervasives_Native_Some, .v = false }; - bool pcont = true; - size_t n3 = pn1; - bool cont0 = pcont; - bool cond0 = n3 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_false(pres1) && cont0; - while (cond0) - { - CBOR_Pulse_Raw_Slice_byte_slice l3 = pll; - size_t n_1 = pn1 - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l3, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l3, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lt1 = scrut4.snd; - size_t pn2 = (size_t)1U; - CBOR_Pulse_Raw_Slice_byte_slice pl10 = lh; - CBOR_Pulse_Raw_Slice_byte_slice pl20 = scrut4.fst; - FStar_Pervasives_Native_option__bool - pres20 = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n40 = pn2; - bool cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres20) && n40 > (size_t)0U; - while (cond) - { - CBOR_Pulse_Raw_Slice_byte_slice l1_ = pl10; - CBOR_Pulse_Raw_Slice_byte_slice l2_ = pl20; - FStar_Pervasives_Native_option__bool - r = - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_map_hd_basic(map_bound_, - l1_, - l2_); - if (FStar_Pervasives_Native_uu___is_None__bool(r)) - pres20 = r; - else - { - size_t n4 = pn2; - if (CBOR_Pulse_Raw_Util_eq_Some_true(r)) - { - size_t n_2 = n4 - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl2 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut4.fst, - .snd = scrut4.snd - } - ).snd; - pn2 = n_2; - pl10 = tl1; - pl20 = tl2; - } - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl1 = scrut4.snd; - CBOR_Spec_Raw_EverParse_header - h11 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut4.fst); - uint8_t mt11 = CBOR_Spec_Raw_EverParse_get_header_major_type(h11); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl2 = scrut9.snd; - CBOR_Spec_Raw_EverParse_header - h21 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut9.fst); - if (mt11 != CBOR_Spec_Raw_EverParse_get_header_major_type(h21)) - pres20 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - else - { - CBOR_Spec_Raw_EverParse_initial_byte_t b0 = h11.fst; - size_t ite0; - if - ( - b0.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b0.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite0 = (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h11.fst, h11.snd); - else - ite0 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = Pulse_Lib_Slice_split__uint8_t(tl1, ite0); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc1 = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl1_ = scrut4.snd; - size_t - n_2 = - CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header(h11) + - n4 - (size_t)1U; - CBOR_Spec_Raw_EverParse_initial_byte_t b = h21.fst; - size_t ite1; - if - ( - b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite1 = (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h21.fst, h21.snd); - else - ite1 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = Pulse_Lib_Slice_split__uint8_t(tl2, ite1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc2 = scrut9.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl2_ = scrut9.snd; - uint8_t mt12 = CBOR_Spec_Raw_EverParse_get_header_major_type(h11); - bool ite2; - if (mt12 == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - { - CBOR_Spec_Raw_EverParse_long_argument - scrut0 = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11); - uint8_t sv1; - if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - sv1 = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11).additional_info; - else if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - sv1 = scrut0.case_LongArgumentSimpleValue; - else - sv1 = - KRML_EABORT(uint8_t, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_EverParse_long_argument - scrut = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21); - uint8_t ite; - if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21).additional_info; - else if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - ite = scrut.case_LongArgumentSimpleValue; - else - ite = - KRML_EABORT(uint8_t, - "unreachable (pattern matches are exhaustive in F*)"); - ite2 = sv1 == ite; - } - else - { - uint64_t - len = - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11)); - if - ( - len != - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21)) - ) - ite2 = false; - else if - (mt12 == CBOR_MAJOR_TYPE_BYTE_STRING || mt12 == CBOR_MAJOR_TYPE_TEXT_STRING) - ite2 = - CBOR_Pulse_Raw_Compare_Bytes_lex_compare_bytes(lc1, lc2) == (int16_t)0; - else - ite2 = mt12 != CBOR_MAJOR_TYPE_MAP; - } - if (ite2) - { - pn2 = n_2; - pl10 = tl1_; - pl20 = tl2_; - } - else - pres20 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - } - } - } - size_t n4 = pn2; - cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres20) && n4 > (size_t)0U; - } - FStar_Pervasives_Native_option__bool res1 = pres20; - if (FStar_Pervasives_Native_uu___is_None__bool(res1)) - pres1 = res1; - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(lt1, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(lt1, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lv1 = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt_1 = scrut4.snd; - bool ite0; - if (res1.tag == FStar_Pervasives_Native_Some) - ite0 = res1.v; - else - ite0 = KRML_EABORT(bool, "unreachable (pattern matches are exhaustive in F*)"); - if (ite0) - { - size_t pn2 = (size_t)1U; - CBOR_Pulse_Raw_Slice_byte_slice pl1 = lv; - CBOR_Pulse_Raw_Slice_byte_slice pl2 = lv1; - FStar_Pervasives_Native_option__bool - pres2 = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n40 = pn2; - bool cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres2) && n40 > (size_t)0U; - while (cond) - { - CBOR_Pulse_Raw_Slice_byte_slice l1_ = pl1; - CBOR_Pulse_Raw_Slice_byte_slice l2_ = pl2; - FStar_Pervasives_Native_option__bool - r = - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_map_hd_basic(map_bound_, - l1_, - l2_); - if (FStar_Pervasives_Native_uu___is_None__bool(r)) - pres2 = r; - else - { - size_t n4 = pn2; - if (CBOR_Pulse_Raw_Util_eq_Some_true(r)) - { - size_t n_2 = n4 - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl2 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut4.fst, - .snd = scrut4.snd - } - ).snd; - pn2 = n_2; - pl1 = tl1; - pl2 = tl2; - } - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl1 = scrut4.snd; - CBOR_Spec_Raw_EverParse_header - h11 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut4.fst); - uint8_t mt11 = CBOR_Spec_Raw_EverParse_get_header_major_type(h11); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl2 = scrut9.snd; - CBOR_Spec_Raw_EverParse_header - h21 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut9.fst); - if (mt11 != CBOR_Spec_Raw_EverParse_get_header_major_type(h21)) - pres2 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - else - { - CBOR_Spec_Raw_EverParse_initial_byte_t b0 = h11.fst; - size_t ite0; - if - ( - b0.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b0.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite0 = - (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h11.fst, h11.snd); - else - ite0 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = Pulse_Lib_Slice_split__uint8_t(tl1, ite0); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc1 = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl1_ = scrut4.snd; - size_t - n_2 = - CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header(h11) + - n4 - (size_t)1U; - CBOR_Spec_Raw_EverParse_initial_byte_t b = h21.fst; - size_t ite1; - if - ( - b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite1 = - (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h21.fst, h21.snd); - else - ite1 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = Pulse_Lib_Slice_split__uint8_t(tl2, ite1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc2 = scrut9.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl2_ = scrut9.snd; - uint8_t mt12 = CBOR_Spec_Raw_EverParse_get_header_major_type(h11); - bool ite2; - if (mt12 == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - { - CBOR_Spec_Raw_EverParse_long_argument - scrut0 = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11); - uint8_t sv1; - if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - sv1 = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11).additional_info; - else if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - sv1 = scrut0.case_LongArgumentSimpleValue; - else - sv1 = - KRML_EABORT(uint8_t, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_EverParse_long_argument - scrut = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21); - uint8_t ite; - if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21).additional_info; - else if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - ite = scrut.case_LongArgumentSimpleValue; - else - ite = - KRML_EABORT(uint8_t, - "unreachable (pattern matches are exhaustive in F*)"); - ite2 = sv1 == ite; - } - else - { - uint64_t - len = - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h11)); - if - ( - len != - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h21)) - ) - ite2 = false; - else if - ( - mt12 == CBOR_MAJOR_TYPE_BYTE_STRING || - mt12 == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite2 = - CBOR_Pulse_Raw_Compare_Bytes_lex_compare_bytes(lc1, lc2) == - (int16_t)0; - else - ite2 = mt12 != CBOR_MAJOR_TYPE_MAP; - } - if (ite2) - { - pn2 = n_2; - pl1 = tl1_; - pl2 = tl2_; - } - else - pres2 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - } - } - } - size_t n4 = pn2; - cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres2) && n4 > (size_t)0U; - } - pres1 = pres2; - pcont = false; - } - else - { - pll = lt_1; - pn1 = n_1; - } - } - size_t n3 = pn1; - bool cont = pcont; - cond0 = n3 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_false(pres1) && cont; - } - FStar_Pervasives_Native_option__bool res1 = pres1; - if (CBOR_Pulse_Raw_Util_eq_Some_true(res1)) - { - pl = lt_; - pn = n_; - } - else - pres = res1; - size_t n = pn; - cond = n > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_true(pres); - } - return pres; - } - else - return res; - } - else - return - ((FStar_Pervasives_Native_option__bool){ .tag = FStar_Pervasives_Native_Some, .v = false }); - } -} - -static FStar_Pervasives_Native_option__bool -CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_list_basic( - FStar_Pervasives_Native_option__size_t map_bound, - size_t n1, - CBOR_Pulse_Raw_Slice_byte_slice l1, - size_t n2, - CBOR_Pulse_Raw_Slice_byte_slice l2 -) -{ - if (n1 != n2) - return - ((FStar_Pervasives_Native_option__bool){ .tag = FStar_Pervasives_Native_Some, .v = false }); - else - { - size_t pn = n1; - CBOR_Pulse_Raw_Slice_byte_slice pl1 = l1; - CBOR_Pulse_Raw_Slice_byte_slice pl2 = l2; - FStar_Pervasives_Native_option__bool pres = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n0 = pn; - bool cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres) && n0 > (size_t)0U; - while (cond) - { - CBOR_Pulse_Raw_Slice_byte_slice l1_ = pl1; - CBOR_Pulse_Raw_Slice_byte_slice l2_ = pl2; - FStar_Pervasives_Native_option__bool - r = CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_map_hd_basic(map_bound, l1_, l2_); - if (FStar_Pervasives_Native_uu___is_None__bool(r)) - pres = r; - else - { - size_t n = pn; - if (CBOR_Pulse_Raw_Util_eq_Some_true(r)) - { - size_t n_ = n - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - tl2 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut4.fst, - .snd = scrut4.snd - } - ).snd; - pn = n_; - pl1 = tl1; - pl2 = tl2; - } - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l1_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l1_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl1 = scrut4.snd; - CBOR_Spec_Raw_EverParse_header - h1 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut4.fst); - uint8_t mt1 = CBOR_Spec_Raw_EverParse_get_header_major_type(h1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = - Pulse_Lib_Slice_split__uint8_t(l2_, - CBOR_Pulse_Raw_EverParse_Format_jump_header(l2_, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice tl2 = scrut9.snd; - CBOR_Spec_Raw_EverParse_header - h2 = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut9.fst); - if (mt1 != CBOR_Spec_Raw_EverParse_get_header_major_type(h2)) - pres = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - else - { - CBOR_Spec_Raw_EverParse_initial_byte_t b0 = h1.fst; - size_t ite0; - if - ( - b0.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b0.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite0 = (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h1.fst, h1.snd); - else - ite0 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = Pulse_Lib_Slice_split__uint8_t(tl1, ite0); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc1 = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl1_ = scrut4.snd; - size_t - n_ = - CBOR_Pulse_Raw_EverParse_Format_impl_remaining_data_items_header(h1) + n - (size_t)1U; - CBOR_Spec_Raw_EverParse_initial_byte_t b = h2.fst; - size_t ite1; - if - ( - b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || - b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING - ) - ite1 = (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(h2.fst, h2.snd); - else - ite1 = (size_t)0U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = Pulse_Lib_Slice_split__uint8_t(tl2, ite1); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lc2 = scrut9.fst; - CBOR_Pulse_Raw_Slice_byte_slice tl2_ = scrut9.snd; - uint8_t mt11 = CBOR_Spec_Raw_EverParse_get_header_major_type(h1); - bool ite2; - if (mt11 == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - { - CBOR_Spec_Raw_EverParse_long_argument - scrut0 = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h1); - uint8_t sv1; - if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - sv1 = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h1).additional_info; - else if (scrut0.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - sv1 = scrut0.case_LongArgumentSimpleValue; - else - sv1 = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_EverParse_long_argument - scrut = - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h2); - uint8_t ite; - if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentOther) - ite = - FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h2).additional_info; - else if (scrut.tag == CBOR_Spec_Raw_EverParse_LongArgumentSimpleValue) - ite = scrut.case_LongArgumentSimpleValue; - else - ite = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - ite2 = sv1 == ite; - } - else - { - uint64_t - len = - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h1), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h1)); - if - ( - len != - CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h2), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h2)) - ) - ite2 = false; - else if (mt11 == CBOR_MAJOR_TYPE_BYTE_STRING || mt11 == CBOR_MAJOR_TYPE_TEXT_STRING) - ite2 = CBOR_Pulse_Raw_Compare_Bytes_lex_compare_bytes(lc1, lc2) == (int16_t)0; - else - ite2 = mt11 != CBOR_MAJOR_TYPE_MAP; - } - if (ite2) - { - pn = n_; - pl1 = tl1_; - pl2 = tl2_; - } - else - pres = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - } - } - } - size_t n = pn; - cond = CBOR_Pulse_Raw_Util_eq_Some_true(pres) && n > (size_t)0U; - } - return pres; - } -} - -static FStar_Pervasives_Native_option__bool -CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_basic( - FStar_Pervasives_Native_option__size_t map_bound, - CBOR_Pulse_Raw_Slice_byte_slice l1, - CBOR_Pulse_Raw_Slice_byte_slice l2 -) -{ - return - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_list_basic(map_bound, - (size_t)1U, - l1, - (size_t)1U, - l2); -} - -static FStar_Pervasives_Native_option__bool -CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_list_for_all_with_overflow_setoid_assoc_eq_with_overflow_basic( - size_t nl1, - CBOR_Pulse_Raw_Slice_byte_slice l1, - size_t nl2, - CBOR_Pulse_Raw_Slice_byte_slice l2 -) -{ - CBOR_Pulse_Raw_Slice_byte_slice pl = l2; - size_t pn = nl2; - FStar_Pervasives_Native_option__bool pres = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n = pn; - bool cond = n > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_true(pres); - while (cond) - { - CBOR_Pulse_Raw_Slice_byte_slice l = pl; - size_t n_ = pn - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lh = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt = scrut4.snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = - Pulse_Lib_Slice_split__uint8_t(lt, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(lt, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut8 = { .fst = scrut7.fst, .snd = scrut7.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut9 = { .fst = scrut8.fst, .snd = scrut8.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lv = scrut9.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt_ = scrut9.snd; - CBOR_Pulse_Raw_Slice_byte_slice pll = l1; - size_t pn1 = nl1; - FStar_Pervasives_Native_option__bool - pres1 = { .tag = FStar_Pervasives_Native_Some, .v = false }; - bool pcont = true; - size_t n1 = pn1; - bool cont0 = pcont; - bool cond0 = n1 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_false(pres1) && cont0; - while (cond0) - { - CBOR_Pulse_Raw_Slice_byte_slice l3 = pll; - size_t n_1 = pn1 - (size_t)1U; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(l3, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l3, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lt1 = scrut4.snd; - FStar_Pervasives_Native_option__bool - res = - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_basic(( - (FStar_Pervasives_Native_option__size_t){ .tag = FStar_Pervasives_Native_None } - ), - lh, - scrut4.fst); - if (FStar_Pervasives_Native_uu___is_None__bool(res)) - pres1 = res; - else - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(lt1, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(lt1, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lv1 = scrut3.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt_1 = scrut3.snd; - bool ite; - if (res.tag == FStar_Pervasives_Native_Some) - ite = res.v; - else - ite = KRML_EABORT(bool, "unreachable (pattern matches are exhaustive in F*)"); - if (ite) - { - pres1 = - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_basic(( - (FStar_Pervasives_Native_option__size_t){ .tag = FStar_Pervasives_Native_None } - ), - lv, - lv1); - pcont = false; - } - else - { - pll = lt_1; - pn1 = n_1; - } - } - size_t n1 = pn1; - bool cont = pcont; - cond0 = n1 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_false(pres1) && cont; - } - FStar_Pervasives_Native_option__bool res = pres1; - if (CBOR_Pulse_Raw_Util_eq_Some_true(res)) - { - pl = lt_; - pn = n_; - } - else - pres = res; - size_t n = pn; - cond = n > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_true(pres); - } - return pres; -} - -static bool -CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_valid_basic( - FStar_Pervasives_Native_option__size_t map_bound, - bool strict_bound_check, - CBOR_Pulse_Raw_Slice_byte_slice l1 -) -{ - size_t pn = (size_t)1U; - bool pres = true; - CBOR_Pulse_Raw_Slice_byte_slice ppi = l1; - while (pres && pn > (size_t)0U) - { - size_t n = pn; - CBOR_Pulse_Raw_Slice_byte_slice pi = ppi; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(pi, - CBOR_Pulse_Raw_EverParse_Format_jump_header(pi, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - CBOR_Spec_Raw_EverParse_header - h = - CBOR_Pulse_Raw_EverParse_Format_read_header(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut3.fst, - .snd = scrut3.snd - } - ).fst); - bool ite0; - if (CBOR_Spec_Raw_EverParse_get_header_major_type(h) == CBOR_MAJOR_TYPE_MAP) - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(pi, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(pi, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - hd = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).fst; - CBOR_Spec_Raw_EverParse_header ph = h; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(hd, - CBOR_Pulse_Raw_EverParse_Format_jump_header(hd, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice outc = scrut4.snd; - ph = CBOR_Pulse_Raw_EverParse_Format_read_header(scrut4.fst); - CBOR_Pulse_Raw_Slice_byte_slice pl = outc; - size_t - pn1 = - (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(FStar_Pervasives_dfst__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h), - FStar_Pervasives_dsnd__CBOR_Spec_Raw_EverParse_initial_byte_t_CBOR_Spec_Raw_EverParse_long_argument(h)); - FStar_Pervasives_Native_option__bool - pres1 = { .tag = FStar_Pervasives_Native_Some, .v = true }; - size_t n1 = pn1; - bool cond = n1 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_true(pres1); - while (cond) - { - size_t n_ = pn1 - (size_t)1U; - CBOR_Pulse_Raw_Slice_byte_slice l = pl; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(l, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lh = scrut3.fst; - CBOR_Pulse_Raw_Slice_byte_slice lt = scrut3.snd; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = - Pulse_Lib_Slice_split__uint8_t(lt, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(lt, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut5 = { .fst = scrut4.fst, .snd = scrut4.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut6 = { .fst = scrut5.fst, .snd = scrut5.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut7 = { .fst = scrut6.fst, .snd = scrut6.snd }; - CBOR_Pulse_Raw_Slice_byte_slice - lt_ = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut7.fst, - .snd = scrut7.snd - } - ).snd; - CBOR_Pulse_Raw_Slice_byte_slice pl1 = lt_; - size_t pn2 = n_; - FStar_Pervasives_Native_option__bool - pres2 = { .tag = FStar_Pervasives_Native_Some, .v = false }; - size_t n2 = pn2; - bool cond0 = n2 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_false(pres2); - while (cond0) - { - size_t n_1 = pn2 - (size_t)1U; - CBOR_Pulse_Raw_Slice_byte_slice l2 = pl1; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(l2, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(l2, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - CBOR_Pulse_Raw_Slice_byte_slice lt1 = scrut3.snd; - FStar_Pervasives_Native_option__bool - res = - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_basic(map_bound, - lh, - scrut3.fst); - if (CBOR_Pulse_Raw_Util_eq_Some_false(res)) - { - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = - Pulse_Lib_Slice_split__uint8_t(lt1, - CBOR_Pulse_Raw_EverParse_Format_jump_raw_data_item(lt1, (size_t)0U)); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = { .fst = scrut.fst, .snd = scrut.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = { .fst = scrut1.fst, .snd = scrut1.snd }; - pl1 = - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut2.fst, - .snd = scrut2.snd - } - ).snd; - pn2 = n_1; - } - else - pres2 = res; - size_t n2 = pn2; - cond0 = n2 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_false(pres2); - } - FStar_Pervasives_Native_option__bool res = pres2; - if (FStar_Pervasives_Native_uu___is_None__bool(res)) - pres1 = ((FStar_Pervasives_Native_option__bool){ .tag = FStar_Pervasives_Native_None }); - else - { - bool ite; - if (res.tag == FStar_Pervasives_Native_Some) - ite = res.v; - else - ite = KRML_EABORT(bool, "unreachable (pattern matches are exhaustive in F*)"); - if (ite) - pres1 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = false - } - ); - else - { - FStar_Pervasives_Native_option__size_t ite; - if (strict_bound_check) - ite = map_bound; - else - ite = - ((FStar_Pervasives_Native_option__size_t){ .tag = FStar_Pervasives_Native_None }); - if (CBOR_Pulse_Raw_EverParse_Nondet_Gen_impl_check_map_depth_opt(ite, (size_t)1U, lh)) - { - pn1 = n_; - pl = lt_; - } - else - pres1 = - ((FStar_Pervasives_Native_option__bool){ .tag = FStar_Pervasives_Native_None }); - } - } - size_t n1 = pn1; - cond = n1 > (size_t)0U && CBOR_Pulse_Raw_Util_eq_Some_true(pres1); - } - ite0 = CBOR_Pulse_Raw_Util_eq_Some_true(pres1); - } - else - ite0 = true; - if (!ite0) - pres = false; - else - { - size_t off1 = CBOR_Pulse_Raw_EverParse_Format_jump_header(pi, (size_t)0U); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(pi, (size_t)0U); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - off1 - (size_t)0U); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - CBOR_Spec_Raw_EverParse_header - x = - CBOR_Pulse_Raw_EverParse_Format_read_header(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst); - CBOR_Spec_Raw_EverParse_initial_byte_t b = x.fst; - size_t ite; - if - (b.major_type == CBOR_MAJOR_TYPE_BYTE_STRING || b.major_type == CBOR_MAJOR_TYPE_TEXT_STRING) - ite = off1 + (size_t)CBOR_Spec_Raw_EverParse_argument_as_uint64(x.fst, x.snd); - else - ite = off1; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut2 = Pulse_Lib_Slice_split__uint8_t(pi, ite); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut3 = { .fst = scrut2.fst, .snd = scrut2.snd }; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut4 = { .fst = scrut3.fst, .snd = scrut3.snd }; - CBOR_Pulse_Raw_Slice_byte_slice ph = scrut4.fst; - CBOR_Pulse_Raw_Slice_byte_slice pc = scrut4.snd; - size_t unused = Pulse_Lib_Slice_len__uint8_t(pc); - KRML_MAYBE_UNUSED_VAR(unused); - pn = n - (size_t)1U + CBOR_Pulse_Raw_EverParse_Format_jump_recursive_step_count_leaf(ph); - ppi = pc; - } - } - return pres; -} - -static size_t -CBOR_Pulse_Raw_Format_Nondet_Validate_cbor_validate_nondet( - FStar_Pervasives_Native_option__size_t map_key_bound, - bool strict_check, - CBOR_Pulse_Raw_Slice_byte_slice input -) -{ - size_t poff = (size_t)0U; - if (CBOR_Pulse_Raw_EverParse_Format_validate_raw_data_item(input, &poff)) - { - size_t off = poff; - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut = Pulse_Lib_Slice_split__uint8_t(input, (size_t)0U); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut0 = - Pulse_Lib_Slice_split__uint8_t(( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut.fst, - .snd = scrut.snd - } - ).snd, - off - (size_t)0U); - K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice - scrut1 = { .fst = scrut0.fst, .snd = scrut0.snd }; - if - ( - CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_valid_basic(map_key_bound, - strict_check, - ( - (K___CBOR_Pulse_Raw_Slice_byte_slice_CBOR_Pulse_Raw_Slice_byte_slice){ - .fst = scrut1.fst, - .snd = scrut1.snd - } - ).fst) - ) - return off; - else - return (size_t)0U; - } - else - return (size_t)0U; -} - -static bool -CBOR_Pulse_Raw_Format_Nondet_Compare_cbor_match_equal_serialized_tagged( - cbor_serialized c1, - cbor_serialized c2 -) -{ - if (c1.cbor_serialized_header.value != c2.cbor_serialized_header.value) - return false; - else - return - CBOR_Pulse_Raw_Util_eq_Some_true(CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_basic(( - (FStar_Pervasives_Native_option__size_t){ .tag = FStar_Pervasives_Native_None } - ), - c1.cbor_serialized_payload, - c2.cbor_serialized_payload)); -} - -static bool -CBOR_Pulse_Raw_Format_Nondet_Compare_cbor_match_compare_serialized_array( - cbor_serialized c1, - cbor_serialized c2 -) -{ - return - CBOR_Pulse_Raw_Util_eq_Some_true(CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_list_basic(( - (FStar_Pervasives_Native_option__size_t){ .tag = FStar_Pervasives_Native_None } - ), - (size_t)c1.cbor_serialized_header.value, - c1.cbor_serialized_payload, - (size_t)c2.cbor_serialized_header.value, - c2.cbor_serialized_payload)); -} - -static bool -CBOR_Pulse_Raw_Format_Nondet_Compare_cbor_match_compare_serialized_map( - cbor_serialized c1, - cbor_serialized c2 -) -{ - size_t n1 = (size_t)c1.cbor_serialized_header.value; - size_t n2 = (size_t)c2.cbor_serialized_header.value; - if - ( - CBOR_Pulse_Raw_Util_eq_Some_true(CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_list_for_all_with_overflow_setoid_assoc_eq_with_overflow_basic(n2, - c2.cbor_serialized_payload, - n1, - c1.cbor_serialized_payload)) - ) - return - CBOR_Pulse_Raw_Util_eq_Some_true(CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_list_for_all_with_overflow_setoid_assoc_eq_with_overflow_basic(n1, - c1.cbor_serialized_payload, - n2, - c2.cbor_serialized_payload)); - else - return false; -} - -typedef struct K___CBOR_Pulse_Raw_Type_cbor_raw_CBOR_Pulse_Raw_Type_cbor_raw_s -{ - cbor_raw fst; - cbor_raw snd; -} -K___CBOR_Pulse_Raw_Type_cbor_raw_CBOR_Pulse_Raw_Type_cbor_raw; - -bool CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(cbor_raw x1, cbor_raw x2) -{ - uint8_t mt1 = CBOR_Pulse_Raw_Compare_impl_major_type(x1); - if (mt1 != CBOR_Pulse_Raw_Compare_impl_major_type(x2)) - return false; - else if (mt1 == CBOR_MAJOR_TYPE_SIMPLE_VALUE) - { - uint8_t w1; - if (x1.tag == CBOR_Case_Simple) - w1 = x1.case_CBOR_Case_Simple; - else - w1 = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - uint8_t ite; - if (x2.tag == CBOR_Case_Simple) - ite = x2.case_CBOR_Case_Simple; - else - ite = KRML_EABORT(uint8_t, "unreachable (pattern matches are exhaustive in F*)"); - return w1 == ite; - } - else if (mt1 == CBOR_MAJOR_TYPE_UINT64 || mt1 == CBOR_MAJOR_TYPE_NEG_INT64) - { - CBOR_Spec_Raw_Base_raw_uint64 w1; - if (x1.tag == CBOR_Case_Int) - { - cbor_int c_ = x1.case_CBOR_Case_Int; - w1 = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = c_.cbor_int_size, .value = c_.cbor_int_value }); - } - else - w1 = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x2.tag == CBOR_Case_Int) - { - cbor_int c_ = x2.case_CBOR_Case_Int; - ite = - ((CBOR_Spec_Raw_Base_raw_uint64){ .size = c_.cbor_int_size, .value = c_.cbor_int_value }); - } - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return w1.value == ite.value; - } - else if (mt1 == CBOR_MAJOR_TYPE_BYTE_STRING || mt1 == CBOR_MAJOR_TYPE_TEXT_STRING) - { - CBOR_Spec_Raw_Base_raw_uint64 len1; - if (x1.tag == CBOR_Case_String) - { - cbor_string c_ = x1.case_CBOR_Case_String; - len1 = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_string_size, - .value = (uint64_t)Pulse_Lib_Slice_len__uint8_t(c_.cbor_string_ptr) - } - ); - } - else - len1 = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_Base_raw_uint64 ite0; - if (x2.tag == CBOR_Case_String) - { - cbor_string c_ = x2.case_CBOR_Case_String; - ite0 = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_string_size, - .value = (uint64_t)Pulse_Lib_Slice_len__uint8_t(c_.cbor_string_ptr) - } - ); - } - else - ite0 = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - if (len1.value != ite0.value) - return false; - else - { - CBOR_Pulse_Raw_Slice_byte_slice w1; - if (x1.tag == CBOR_Case_String) - w1 = x1.case_CBOR_Case_String.cbor_string_ptr; - else - w1 = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Pulse_Raw_Slice_byte_slice ite; - if (x2.tag == CBOR_Case_String) - ite = x2.case_CBOR_Case_String.cbor_string_ptr; - else - ite = - KRML_EABORT(CBOR_Pulse_Raw_Slice_byte_slice, - "unreachable (pattern matches are exhaustive in F*)"); - return CBOR_Pulse_Raw_Compare_Bytes_lex_compare_bytes(w1, ite) == (int16_t)0; - } - } - else if (mt1 == CBOR_MAJOR_TYPE_TAGGED) - { - K___CBOR_Pulse_Raw_Type_cbor_raw_CBOR_Pulse_Raw_Type_cbor_raw scrut = { .fst = x1, .snd = x2 }; - bool ite0; - if - (scrut.fst.tag == CBOR_Case_Serialized_Tagged && scrut.snd.tag == CBOR_Case_Serialized_Tagged) - ite0 = true; - else - ite0 = false; - if (ite0) - if (x1.tag == CBOR_Case_Serialized_Tagged) - { - cbor_serialized cs1 = x1.case_CBOR_Case_Serialized_Tagged; - if (x2.tag == CBOR_Case_Serialized_Tagged) - return - CBOR_Pulse_Raw_Format_Nondet_Compare_cbor_match_equal_serialized_tagged(cs1, - x2.case_CBOR_Case_Serialized_Tagged); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - } - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - else - { - CBOR_Spec_Raw_Base_raw_uint64 tag1; - if (x1.tag == CBOR_Case_Tagged) - tag1 = x1.case_CBOR_Case_Tagged.cbor_tagged_tag; - else if (x1.tag == CBOR_Case_Serialized_Tagged) - tag1 = x1.case_CBOR_Case_Serialized_Tagged.cbor_serialized_header; - else - tag1 = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x2.tag == CBOR_Case_Tagged) - ite = x2.case_CBOR_Case_Tagged.cbor_tagged_tag; - else if (x2.tag == CBOR_Case_Serialized_Tagged) - ite = x2.case_CBOR_Case_Serialized_Tagged.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - if (tag1.value != ite.value) - return false; - else - { - cbor_raw w1 = CBOR_Pulse_Raw_Read_cbor_match_tagged_get_payload(x1); - return - CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(w1, - CBOR_Pulse_Raw_Read_cbor_match_tagged_get_payload(x2)); - } - } - } - else if (mt1 == CBOR_MAJOR_TYPE_ARRAY) - { - K___CBOR_Pulse_Raw_Type_cbor_raw_CBOR_Pulse_Raw_Type_cbor_raw scrut = { .fst = x1, .snd = x2 }; - bool ite0; - if (scrut.fst.tag == CBOR_Case_Serialized_Array && scrut.snd.tag == CBOR_Case_Serialized_Array) - ite0 = true; - else - ite0 = false; - if (ite0) - if (x1.tag == CBOR_Case_Serialized_Array) - { - cbor_serialized cs1 = x1.case_CBOR_Case_Serialized_Array; - if (x2.tag == CBOR_Case_Serialized_Array) - return - CBOR_Pulse_Raw_Format_Nondet_Compare_cbor_match_compare_serialized_array(cs1, - x2.case_CBOR_Case_Serialized_Array); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - } - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - else - { - CBOR_Spec_Raw_Base_raw_uint64 len1; - if (x1.tag == CBOR_Case_Array) - { - cbor_array c_ = x1.case_CBOR_Case_Array; - len1 = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_array_length_size, - .value = (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(c_.cbor_array_ptr) - } - ); - } - else if (x1.tag == CBOR_Case_Serialized_Array) - len1 = x1.case_CBOR_Case_Serialized_Array.cbor_serialized_header; - else - len1 = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x2.tag == CBOR_Case_Array) - { - cbor_array c_ = x2.case_CBOR_Case_Array; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_array_length_size, - .value = (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(c_.cbor_array_ptr) - } - ); - } - else if (x2.tag == CBOR_Case_Serialized_Array) - ite = x2.case_CBOR_Case_Serialized_Array.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - if (len1.value != ite.value) - return false; - else - { - cbor_array_iterator pi1 = CBOR_Pulse_Raw_Read_cbor_array_iterator_init(x1); - cbor_array_iterator pi2 = CBOR_Pulse_Raw_Read_cbor_array_iterator_init(x2); - bool pres = true; - bool res = pres; - bool cond = res && !CBOR_Pulse_Raw_Read_cbor_array_iterator_is_empty(pi1); - while (cond) - { - cbor_raw y1 = CBOR_Pulse_Raw_Read_cbor_array_iterator_next(&pi1); - pres = - CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(y1, - CBOR_Pulse_Raw_Read_cbor_array_iterator_next(&pi2)); - bool res = pres; - cond = res && !CBOR_Pulse_Raw_Read_cbor_array_iterator_is_empty(pi1); - } - return pres; - } - } - } - else - { - K___CBOR_Pulse_Raw_Type_cbor_raw_CBOR_Pulse_Raw_Type_cbor_raw scrut = { .fst = x1, .snd = x2 }; - bool ite; - if (scrut.fst.tag == CBOR_Case_Serialized_Map && scrut.snd.tag == CBOR_Case_Serialized_Map) - ite = true; - else - ite = false; - if (ite) - if (x1.tag == CBOR_Case_Serialized_Map) - { - cbor_serialized cs1 = x1.case_CBOR_Case_Serialized_Map; - if (x2.tag == CBOR_Case_Serialized_Map) - return - CBOR_Pulse_Raw_Format_Nondet_Compare_cbor_match_compare_serialized_map(cs1, - x2.case_CBOR_Case_Serialized_Map); - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - } - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - else - { - cbor_map_iterator i1 = CBOR_Pulse_Raw_Read_cbor_map_iterator_init(x1); - cbor_map_iterator i2 = CBOR_Pulse_Raw_Read_cbor_map_iterator_init(x2); - cbor_map_iterator pi2 = i1; - bool pres0 = true; - bool res0 = pres0; - bool cond = res0 && !CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(pi2); - while (cond) - { - cbor_map_entry x21 = CBOR_Pulse_Raw_Read_cbor_map_iterator_next(&pi2); - cbor_map_iterator pi1 = i2; - FStar_Pervasives_Native_option__bool pres1 = { .tag = FStar_Pervasives_Native_None }; - FStar_Pervasives_Native_option__bool res = pres1; - bool __anf00 = CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(pi1); - bool cond0 = FStar_Pervasives_Native_uu___is_None__bool(res) && !__anf00; - while (cond0) - { - cbor_map_entry x11 = CBOR_Pulse_Raw_Read_cbor_map_iterator_next(&pi1); - if - ( - CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(x21.cbor_map_entry_key, - x11.cbor_map_entry_key) - ) - pres1 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(x21.cbor_map_entry_value, - x11.cbor_map_entry_value) - } - ); - FStar_Pervasives_Native_option__bool res = pres1; - bool __anf0 = CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(pi1); - cond0 = FStar_Pervasives_Native_uu___is_None__bool(res) && !__anf0; - } - pres0 = CBOR_Pulse_Raw_Util_eq_Some_true(pres1); - bool res0 = pres0; - cond = res0 && !CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(pi2); - } - if (!pres0) - return false; - else - { - cbor_map_iterator pi2 = i2; - bool pres = true; - bool res0 = pres; - bool cond = res0 && !CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(pi2); - while (cond) - { - cbor_map_entry x21 = CBOR_Pulse_Raw_Read_cbor_map_iterator_next(&pi2); - cbor_map_iterator pi1 = i1; - FStar_Pervasives_Native_option__bool pres1 = { .tag = FStar_Pervasives_Native_None }; - FStar_Pervasives_Native_option__bool res = pres1; - bool __anf010 = CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(pi1); - bool cond0 = FStar_Pervasives_Native_uu___is_None__bool(res) && !__anf010; - while (cond0) - { - cbor_map_entry x11 = CBOR_Pulse_Raw_Read_cbor_map_iterator_next(&pi1); - if - ( - CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(x21.cbor_map_entry_key, - x11.cbor_map_entry_key) - ) - pres1 = - ( - (FStar_Pervasives_Native_option__bool){ - .tag = FStar_Pervasives_Native_Some, - .v = CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(x21.cbor_map_entry_value, - x11.cbor_map_entry_value) - } - ); - FStar_Pervasives_Native_option__bool res = pres1; - bool __anf01 = CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(pi1); - cond0 = FStar_Pervasives_Native_uu___is_None__bool(res) && !__anf01; - } - pres = CBOR_Pulse_Raw_Util_eq_Some_true(pres1); - bool res0 = pres; - cond = res0 && !CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(pi2); - } - return pres; - } - } - } -} - -static bool -CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_no_setoid_repeats( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry x -) -{ - size_t pn1 = (size_t)0U; - bool pres = true; - bool res0 = pres; - size_t __anf00 = pn1; - bool cond = res0 && __anf00 < Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(x); - while (cond) - { - size_t n1 = pn1; - cbor_map_entry x1 = Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_map_entry(x, n1); - size_t n2 = n1 + (size_t)1U; - pn1 = n2; - size_t pn2 = n2; - bool res = pres; - size_t __anf00 = pn2; - bool cond0 = res && __anf00 < Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(x); - while (cond0) - { - size_t n21 = pn2; - pres = - !CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(x1.cbor_map_entry_key, - Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_Raw_Type_cbor_map_entry(x, - n21).cbor_map_entry_key); - pn2 = n21 + (size_t)1U; - bool res = pres; - size_t __anf0 = pn2; - cond0 = res && __anf0 < Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(x); - } - bool res0 = pres; - size_t __anf0 = pn1; - cond = res0 && __anf0 < Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(x); - } - return pres; -} - -static size_t -CBOR_Pulse_Raw_Nondet_cbor_nondet_validate( - FStar_Pervasives_Native_option__size_t map_key_bound, - bool strict_check, - CBOR_Pulse_Raw_Slice_byte_slice input -) -{ - return - CBOR_Pulse_Raw_Format_Nondet_Validate_cbor_validate_nondet(map_key_bound, - strict_check, - input); -} - -static cbor_raw -CBOR_Pulse_Raw_Nondet_cbor_nondet_parse_valid( - CBOR_Pulse_Raw_Slice_byte_slice input, - size_t len -) -{ - return CBOR_Pulse_Raw_Format_Parse_cbor_parse(input, len); -} - -static size_t CBOR_Pulse_Raw_Nondet_cbor_nondet_size(cbor_raw x, size_t bound) -{ - return CBOR_Pulse_Raw_Format_Serialize_cbor_size(x, bound); -} - -static FStar_Pervasives_Native_option__size_t -CBOR_Pulse_Raw_Nondet_cbor_nondet_serialize(cbor_raw x, CBOR_Pulse_Raw_Slice_byte_slice output) -{ - size_t - len = CBOR_Pulse_Raw_Format_Serialize_cbor_size(x, Pulse_Lib_Slice_len__uint8_t(output)); - if (len == (size_t)0U) - return ((FStar_Pervasives_Native_option__size_t){ .tag = FStar_Pervasives_Native_None }); - else - return - ( - (FStar_Pervasives_Native_option__size_t){ - .tag = FStar_Pervasives_Native_Some, - .v = CBOR_Pulse_Raw_Format_Serialize_cbor_serialize(x, - Pulse_Lib_Slice_split__uint8_t(output, len).fst) - } - ); -} - -static uint8_t CBOR_Pulse_Raw_Nondet_cbor_nondet_major_type(cbor_raw x) -{ - return CBOR_Pulse_Raw_Compare_impl_major_type(x); -} - -static uint8_t CBOR_Pulse_Raw_Nondet_cbor_nondet_read_simple_value(cbor_raw x) -{ - if (x.tag == CBOR_Case_Simple) - return x.case_CBOR_Case_Simple; - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static uint64_t CBOR_Pulse_Raw_Nondet_cbor_nondet_read_uint64(cbor_raw x) -{ - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x.tag == CBOR_Case_Int) - { - cbor_int c_ = x.case_CBOR_Case_Int; - ite = ((CBOR_Spec_Raw_Base_raw_uint64){ .size = c_.cbor_int_size, .value = c_.cbor_int_value }); - } - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return ite.value; -} - -static uint64_t CBOR_Pulse_Raw_Nondet_cbor_nondet_get_string_length(cbor_raw x) -{ - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x.tag == CBOR_Case_String) - { - cbor_string c_ = x.case_CBOR_Case_String; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_string_size, - .value = (uint64_t)Pulse_Lib_Slice_len__uint8_t(c_.cbor_string_ptr) - } - ); - } - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return ite.value; -} - -static CBOR_Pulse_Raw_Slice_byte_slice CBOR_Pulse_Raw_Nondet_cbor_nondet_get_string(cbor_raw x) -{ - if (x.tag == CBOR_Case_String) - return x.case_CBOR_Case_String.cbor_string_ptr; - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } -} - -static uint64_t CBOR_Pulse_Raw_Nondet_cbor_nondet_get_tagged_tag(cbor_raw x) -{ - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x.tag == CBOR_Case_Tagged) - ite = x.case_CBOR_Case_Tagged.cbor_tagged_tag; - else if (x.tag == CBOR_Case_Serialized_Tagged) - ite = x.case_CBOR_Case_Serialized_Tagged.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return ite.value; -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_get_tagged_payload(cbor_raw x) -{ - return CBOR_Pulse_Raw_Read_cbor_match_tagged_get_payload(x); -} - -static uint64_t CBOR_Pulse_Raw_Nondet_cbor_nondet_get_array_length(cbor_raw x) -{ - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x.tag == CBOR_Case_Array) - { - cbor_array c_ = x.case_CBOR_Case_Array; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_array_length_size, - .value = (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(c_.cbor_array_ptr) - } - ); - } - else if (x.tag == CBOR_Case_Serialized_Array) - ite = x.case_CBOR_Case_Serialized_Array.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return ite.value; -} - -static cbor_array_iterator CBOR_Pulse_Raw_Nondet_cbor_nondet_array_iterator_start(cbor_raw x) -{ - return CBOR_Pulse_Raw_Read_cbor_array_iterator_init(x); -} - -static bool CBOR_Pulse_Raw_Nondet_cbor_nondet_array_iterator_is_empty(cbor_array_iterator x) -{ - return CBOR_Pulse_Raw_Read_cbor_array_iterator_is_empty(x); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_array_iterator_next(cbor_array_iterator *x) -{ - return CBOR_Pulse_Raw_Read_cbor_array_iterator_next(x); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_get_array_item(cbor_raw x, uint64_t i) -{ - return CBOR_Pulse_Raw_Read_cbor_array_item(x, i); -} - -static uint64_t CBOR_Pulse_Raw_Nondet_cbor_nondet_get_map_length(cbor_raw x) -{ - CBOR_Spec_Raw_Base_raw_uint64 ite; - if (x.tag == CBOR_Case_Map) - { - cbor_map c_ = x.case_CBOR_Case_Map; - ite = - ( - (CBOR_Spec_Raw_Base_raw_uint64){ - .size = c_.cbor_map_length_size, - .value = (uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(c_.cbor_map_ptr) - } - ); - } - else if (x.tag == CBOR_Case_Serialized_Map) - ite = x.case_CBOR_Case_Serialized_Map.cbor_serialized_header; - else - ite = - KRML_EABORT(CBOR_Spec_Raw_Base_raw_uint64, - "unreachable (pattern matches are exhaustive in F*)"); - return ite.value; -} - -static cbor_map_iterator CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_start(cbor_raw x) -{ - return CBOR_Pulse_Raw_Read_cbor_map_iterator_init(x); -} - -static bool CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_is_empty(cbor_map_iterator x) -{ - return CBOR_Pulse_Raw_Read_cbor_map_iterator_is_empty(x); -} - -static cbor_map_entry CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_next(cbor_map_iterator *x) -{ - return CBOR_Pulse_Raw_Read_cbor_map_iterator_next(x); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_map_entry_key(cbor_map_entry x2) -{ - return x2.cbor_map_entry_key; -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_map_entry_value(cbor_map_entry x2) -{ - return x2.cbor_map_entry_value; -} - -static bool CBOR_Pulse_Raw_Nondet_cbor_nondet_equal(cbor_raw x1, cbor_raw x2) -{ - return CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(x1, x2); -} - -typedef struct FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw_s -{ - FStar_Pervasives_Native_option__bool_tags tag; - cbor_raw v; -} -FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw; - -static FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw -CBOR_Pulse_Raw_Nondet_cbor_nondet_map_get(cbor_raw x, cbor_raw k) -{ - cbor_raw dest = k; - cbor_map_iterator i = CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_start(x); - cbor_map_iterator pi = i; - bool pres = false; - bool pcont = !CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_is_empty(i); - while (pcont && !pres) - { - cbor_map_entry y = CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_next(&pi); - if (CBOR_Pulse_Raw_Nondet_cbor_nondet_equal(y.cbor_map_entry_key, k)) - { - dest = y.cbor_map_entry_value; - pres = true; - } - else - pcont = !CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_is_empty(pi); - } - if (pres) - return - ( - (FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw){ - .tag = FStar_Pervasives_Native_Some, - .v = dest - } - ); - else - return - ( - (FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw){ - .tag = FStar_Pervasives_Native_None - } - ); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_simple_value(uint8_t v) -{ - return ((cbor_raw){ .tag = CBOR_Case_Simple, { .case_CBOR_Case_Simple = v } }); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_int64_gen(uint8_t ty, uint64_t v) -{ - return - ( - (cbor_raw){ - .tag = CBOR_Case_Int, - { - .case_CBOR_Case_Int = { - .cbor_int_type = ty, - .cbor_int_size = CBOR_Spec_Raw_Optimal_mk_raw_uint64(v).size, - .cbor_int_value = CBOR_Spec_Raw_Optimal_mk_raw_uint64(v).value - } - } - } - ); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_uint64(uint64_t v) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_int64_gen(CBOR_MAJOR_TYPE_UINT64, v); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_neg_int64(uint64_t v) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_int64_gen(CBOR_MAJOR_TYPE_NEG_INT64, v); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_int64(int64_t v) -{ - if (v < (int64_t)0) - return - CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_int64_gen(CBOR_MAJOR_TYPE_NEG_INT64, - (uint64_t)((int64_t)-1 - v)); - else - return CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_int64_gen(CBOR_MAJOR_TYPE_UINT64, (uint64_t)v); -} - -static cbor_raw -CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_string(uint8_t ty, CBOR_Pulse_Raw_Slice_byte_slice s) -{ - return - CBOR_Pulse_Raw_Match_cbor_raw_reset_perm_tot(( - (cbor_raw){ - .tag = CBOR_Case_String, - { - .case_CBOR_Case_String = { - .cbor_string_type = ty, - .cbor_string_size = CBOR_Spec_Raw_Optimal_mk_raw_uint64((uint64_t)Pulse_Lib_Slice_len__uint8_t(s)).size, - .cbor_string_ptr = s - } - } - } - )); -} - -static cbor_raw CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_tagged(uint64_t tag, cbor_raw *r) -{ - return - CBOR_Pulse_Raw_Match_cbor_raw_reset_perm_tot(( - (cbor_raw){ - .tag = CBOR_Case_Tagged, - { - .case_CBOR_Case_Tagged = { - .cbor_tagged_tag = CBOR_Spec_Raw_Optimal_mk_raw_uint64(tag), - .cbor_tagged_ptr = r - } - } - } - )); -} - -static cbor_raw -CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_array( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw a -) -{ - return - CBOR_Pulse_Raw_Match_cbor_raw_reset_perm_tot(( - (cbor_raw){ - .tag = CBOR_Case_Array, - { - .case_CBOR_Case_Array = { - .cbor_array_length_size = CBOR_Spec_Raw_Optimal_mk_raw_uint64((uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_raw(a)).size, - .cbor_array_ptr = a - } - } - } - )); -} - -static cbor_map_entry CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_map_entry(cbor_raw xk, cbor_raw xv) -{ - cbor_raw xk_ = CBOR_Pulse_Raw_Match_cbor_raw_reset_perm_tot(xk); - return - ( - (cbor_map_entry){ - .cbor_map_entry_key = xk_, - .cbor_map_entry_value = CBOR_Pulse_Raw_Match_cbor_raw_reset_perm_tot(xv) - } - ); -} - -static FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw -CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_map( - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry a -) -{ - cbor_raw dest = { .tag = CBOR_Case_Simple, { .case_CBOR_Case_Simple = 0U } }; - bool ite0; - if - ( - Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(a) / (size_t)32768U / (size_t)32768U / - (size_t)32768U - / (size_t)32768U - < (size_t)16U - ) - ite0 = true; - else - ite0 = false; - bool ite; - if (!ite0) - ite = false; - else if (CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_no_setoid_repeats(a)) - { - dest = - CBOR_Pulse_Raw_Match_cbor_raw_reset_perm_tot(( - (cbor_raw){ - .tag = CBOR_Case_Map, - { - .case_CBOR_Case_Map = { - .cbor_map_length_size = CBOR_Spec_Raw_Optimal_mk_raw_uint64((uint64_t)Pulse_Lib_Slice_len__CBOR_Pulse_Raw_Type_cbor_map_entry(a)).size, - .cbor_map_ptr = a - } - } - } - )); - ite = true; - } - else - ite = false; - if (ite) - return - ( - (FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw){ - .tag = FStar_Pervasives_Native_Some, - .v = dest - } - ); - else - return - ( - (FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw){ - .tag = FStar_Pervasives_Native_None - } - ); -} - -static CBOR_Pulse_Raw_Slice_byte_slice -Pulse_Lib_Slice_arrayptr_to_slice_intro__uint8_t(uint8_t *a, size_t alen) -{ - return ((CBOR_Pulse_Raw_Slice_byte_slice){ .elt = a, .len = alen }); -} - -bool -cbor_nondet_parse( - bool check_map_key_bound, - size_t map_key_bound, - uint8_t **pinput, - size_t *plen, - cbor_raw *dest -) -{ - if (pinput == NULL || plen == NULL || dest == NULL) - return false; - else - { - uint8_t *input1 = *pinput; - if (*pinput == NULL) - return false; - else - { - size_t len1 = *plen; - CBOR_Pulse_Raw_Slice_byte_slice - s = Pulse_Lib_Slice_arrayptr_to_slice_intro__uint8_t(input1, len1); - FStar_Pervasives_Native_option__size_t ite; - if (check_map_key_bound) - ite = - ( - (FStar_Pervasives_Native_option__size_t){ - .tag = FStar_Pervasives_Native_Some, - .v = map_key_bound - } - ); - else - ite = ((FStar_Pervasives_Native_option__size_t){ .tag = FStar_Pervasives_Native_None }); - size_t consume = CBOR_Pulse_Raw_Nondet_cbor_nondet_validate(ite, check_map_key_bound, s); - if (consume == (size_t)0U) - return false; - else - { - *pinput = input1 + consume; - *plen = len1 - consume; - *dest = - CBOR_Pulse_Raw_Nondet_cbor_nondet_parse_valid(Pulse_Lib_Slice_arrayptr_to_slice_intro__uint8_t(input1, - consume), - consume); - return true; - } - } - } -} - -size_t cbor_nondet_size(cbor_raw x, size_t bound) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_size(x, bound); -} - -size_t cbor_nondet_serialize(cbor_raw x, uint8_t *output, size_t len) -{ - if (output == NULL) - return (size_t)0U; - else - { - FStar_Pervasives_Native_option__size_t - scrut = - CBOR_Pulse_Raw_Nondet_cbor_nondet_serialize(x, - Pulse_Lib_Slice_arrayptr_to_slice_intro__uint8_t(output, len)); - if (scrut.tag == FStar_Pervasives_Native_None) - return (size_t)0U; - else if (scrut.tag == FStar_Pervasives_Native_Some) - return scrut.v; - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - } -} - -uint8_t cbor_nondet_major_type(cbor_raw x) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_major_type(x); -} - -bool cbor_nondet_read_simple_value(cbor_raw x, uint8_t *dest) -{ - if (dest == NULL) - return false; - else if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_SIMPLE_VALUE) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_read_simple_value(x); - return true; - } -} - -bool cbor_nondet_read_uint64(cbor_raw x, uint64_t *dest) -{ - if (dest == NULL) - return false; - else - { - uint8_t ty = cbor_nondet_major_type(x); - if (ty != CBOR_MAJOR_TYPE_UINT64 && ty != CBOR_MAJOR_TYPE_NEG_INT64) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_read_uint64(x); - return true; - } - } -} - -bool cbor_nondet_read_int64(cbor_raw x, int64_t *dest) -{ - if (dest == NULL) - return false; - else - { - uint8_t ty = cbor_nondet_major_type(x); - if (ty == CBOR_MAJOR_TYPE_UINT64) - { - uint64_t raw = CBOR_Pulse_Raw_Nondet_cbor_nondet_read_uint64(x); - if (raw > 9223372036854775807ULL) - return false; - else - { - *dest = (int64_t)raw; - return true; - } - } - else if (ty == CBOR_MAJOR_TYPE_NEG_INT64) - { - uint64_t raw = CBOR_Pulse_Raw_Nondet_cbor_nondet_read_uint64(x); - if (raw > 9223372036854775807ULL) - return false; - else - { - *dest = (int64_t)-1 - (int64_t)raw; - return true; - } - } - else - return false; - } -} - -static uint8_t -*Pulse_Lib_Slice_slice_to_arrayptr_intro__uint8_t(CBOR_Pulse_Raw_Slice_byte_slice s) -{ - return s.elt; -} - -bool cbor_nondet_get_string(cbor_raw x, uint8_t **dest, uint64_t *dlen) -{ - if (dest == NULL || dlen == NULL) - return false; - else - { - uint8_t ty = cbor_nondet_major_type(x); - if (ty != CBOR_MAJOR_TYPE_BYTE_STRING && ty != CBOR_MAJOR_TYPE_TEXT_STRING) - return false; - else - { - uint64_t len = CBOR_Pulse_Raw_Nondet_cbor_nondet_get_string_length(x); - uint8_t - *res = - Pulse_Lib_Slice_slice_to_arrayptr_intro__uint8_t(CBOR_Pulse_Raw_Nondet_cbor_nondet_get_string(x)); - *dlen = len; - *dest = res; - return true; - } - } -} - -bool cbor_nondet_get_byte_string(cbor_raw x, uint8_t **dest, uint64_t *dlen) -{ - if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_BYTE_STRING) - return false; - else - return cbor_nondet_get_string(x, dest, dlen); -} - -bool cbor_nondet_get_text_string(cbor_raw x, uint8_t **dest, uint64_t *dlen) -{ - if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_TEXT_STRING) - return false; - else - return cbor_nondet_get_string(x, dest, dlen); -} - -bool cbor_nondet_get_tagged(cbor_raw x, cbor_raw *dest, uint64_t *dtag) -{ - if (dest == NULL || dtag == NULL) - return false; - else if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_TAGGED) - return false; - else - { - uint64_t tag = CBOR_Pulse_Raw_Nondet_cbor_nondet_get_tagged_tag(x); - cbor_raw res = CBOR_Pulse_Raw_Nondet_cbor_nondet_get_tagged_payload(x); - *dtag = tag; - *dest = res; - return true; - } -} - -bool cbor_nondet_get_array_length(cbor_raw x, uint64_t *dest) -{ - if (dest == NULL) - return false; - else if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_ARRAY) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_get_array_length(x); - return true; - } -} - -bool cbor_nondet_array_iterator_start(cbor_raw x, cbor_array_iterator *dest) -{ - if (dest == NULL) - return false; - else if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_ARRAY) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_array_iterator_start(x); - return true; - } -} - -bool cbor_nondet_array_iterator_is_empty(cbor_array_iterator x) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_array_iterator_is_empty(x); -} - -uint64_t cbor_nondet_array_iterator_length(cbor_array_iterator x) -{ - return CBOR_Pulse_Raw_Read_cbor_array_iterator_length(x); -} - -bool cbor_nondet_array_iterator_next(cbor_array_iterator *x, cbor_raw *dest) -{ - if (x == NULL || dest == NULL) - return false; - else if (cbor_nondet_array_iterator_is_empty(*x)) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_array_iterator_next(x); - return true; - } -} - -cbor_array_iterator cbor_nondet_array_iterator_truncate(cbor_array_iterator x, uint64_t len) -{ - return CBOR_Pulse_Raw_Read_cbor_array_iterator_truncate(x, len); -} - -bool cbor_nondet_get_array_item(cbor_raw x, uint64_t i, cbor_raw *dest) -{ - if (dest == NULL) - return false; - else if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_ARRAY) - return false; - else if (CBOR_Pulse_Raw_Nondet_cbor_nondet_get_array_length(x) <= i) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_get_array_item(x, i); - return true; - } -} - -bool cbor_nondet_get_map_length(cbor_raw x, uint64_t *dest) -{ - if (dest == NULL) - return false; - else if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_MAP) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_get_map_length(x); - return true; - } -} - -bool cbor_nondet_map_iterator_start(cbor_raw x, cbor_map_iterator *dest) -{ - if (dest == NULL) - return false; - else if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_MAP) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_start(x); - return true; - } -} - -bool cbor_nondet_map_iterator_is_empty(cbor_map_iterator x) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_is_empty(x); -} - -cbor_raw cbor_nondet_map_entry_key(cbor_map_entry x) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_map_entry_key(x); -} - -cbor_raw cbor_nondet_map_entry_value(cbor_map_entry x) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_map_entry_value(x); -} - -bool -cbor_nondet_map_iterator_next(cbor_map_iterator *x, cbor_raw *dest_key, cbor_raw *dest_value) -{ - if (x == NULL || dest_key == NULL || dest_value == NULL) - return false; - else if (cbor_nondet_map_iterator_is_empty(*x)) - return false; - else - { - cbor_map_entry res = CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_next(x); - cbor_raw res_key = cbor_nondet_map_entry_key(res); - cbor_raw res_value = cbor_nondet_map_entry_value(res); - *dest_key = res_key; - *dest_value = res_value; - return true; - } -} - -bool cbor_nondet_equal(cbor_raw x1, cbor_raw x2) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_equal(x1, x2); -} - -bool cbor_nondet_map_get(cbor_raw x, cbor_raw k, cbor_raw *dest) -{ - if (dest == NULL) - return false; - else if (cbor_nondet_major_type(x) != CBOR_MAJOR_TYPE_MAP) - return false; - else - { - FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw - scrut = CBOR_Pulse_Raw_Nondet_cbor_nondet_map_get(x, k); - if (scrut.tag == FStar_Pervasives_Native_None) - return false; - else if (scrut.tag == FStar_Pervasives_Native_Some) - { - *dest = scrut.v; - return true; - } - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - } -} - -bool cbor_nondet_mk_simple_value(uint8_t v, cbor_raw *dest) -{ - if - ( - dest == NULL || !(v <= MAX_SIMPLE_VALUE_ADDITIONAL_INFO || MIN_SIMPLE_VALUE_LONG_ARGUMENT <= v) - ) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_simple_value(v); - return true; - } -} - -cbor_raw cbor_nondet_mk_uint64(uint64_t v) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_uint64(v); -} - -cbor_raw cbor_nondet_mk_neg_int64(uint64_t v) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_neg_int64(v); -} - -cbor_raw cbor_nondet_mk_int64(int64_t v) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_int64(v); -} - -bool cbor_nondet_mk_byte_string(uint8_t *a, uint64_t len, cbor_raw *dest) -{ - bool __anf0 = a == NULL; - if (__anf0 || dest == NULL) - return false; - else - { - CBOR_Pulse_Raw_Slice_byte_slice - s = Pulse_Lib_Slice_arrayptr_to_slice_intro__uint8_t(a, (size_t)len); - bool ite; - if (CBOR_MAJOR_TYPE_BYTE_STRING == CBOR_MAJOR_TYPE_TEXT_STRING) - ite = CBOR_Pulse_Raw_EverParse_UTF8_impl_correct(s); - else - ite = true; - if (ite) - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_string(CBOR_MAJOR_TYPE_BYTE_STRING, s); - return true; - } - else - return false; - } -} - -bool cbor_nondet_mk_text_string(uint8_t *a, uint64_t len, cbor_raw *dest) -{ - bool __anf0 = a == NULL; - if (__anf0 || dest == NULL) - return false; - else - { - CBOR_Pulse_Raw_Slice_byte_slice - s = Pulse_Lib_Slice_arrayptr_to_slice_intro__uint8_t(a, (size_t)len); - if (CBOR_Pulse_Raw_EverParse_UTF8_impl_correct(s)) - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_string(CBOR_MAJOR_TYPE_TEXT_STRING, s); - return true; - } - else - return false; - } -} - -bool cbor_nondet_mk_tagged(uint64_t tag, cbor_raw *r, cbor_raw *dest) -{ - if (r == NULL || dest == NULL) - return false; - else - { - *dest = CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_tagged(tag, r); - return true; - } -} - -static Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw -Pulse_Lib_Slice_arrayptr_to_slice_intro__CBOR_Pulse_Raw_Type_cbor_raw(cbor_raw *a, size_t alen) -{ - return ((Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw){ .elt = a, .len = alen }); -} - -bool cbor_nondet_mk_array(cbor_raw *a, uint64_t len, cbor_raw *dest) -{ - bool __anf0 = a == NULL; - if (__anf0 || dest == NULL) - return false; - else - { - *dest = - CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_array(Pulse_Lib_Slice_arrayptr_to_slice_intro__CBOR_Pulse_Raw_Type_cbor_raw(a, - (size_t)len)); - return true; - } -} - -cbor_map_entry cbor_nondet_mk_map_entry(cbor_raw xk, cbor_raw xv) -{ - return CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_map_entry(xk, xv); -} - -static Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry -Pulse_Lib_Slice_arrayptr_to_slice_intro__CBOR_Pulse_Raw_Type_cbor_map_entry( - cbor_map_entry *a, - size_t alen -) -{ - return ((Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry){ .elt = a, .len = alen }); -} - -bool cbor_nondet_mk_map(cbor_map_entry *a, uint64_t len, cbor_raw *dest) -{ - bool __anf0 = a == NULL; - if (__anf0 || dest == NULL) - return false; - else - { - FStar_Pervasives_Native_option__CBOR_Pulse_Raw_Type_cbor_raw - scrut = - CBOR_Pulse_Raw_Nondet_cbor_nondet_mk_map(Pulse_Lib_Slice_arrayptr_to_slice_intro__CBOR_Pulse_Raw_Type_cbor_map_entry(a, - (size_t)len)); - if (scrut.tag == FStar_Pervasives_Native_None) - return false; - else if (scrut.tag == FStar_Pervasives_Native_Some) - { - *dest = scrut.v; - return true; - } - else - { - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); - } - } -} - -typedef struct -Pulse_Lib_Slice_slice__CBOR_Pulse_API_Nondet_C_cbor_nondet_map_get_multiple_entry_t_s -{ - cbor_nondet_map_get_multiple_entry_t *elt; - size_t len; -} -Pulse_Lib_Slice_slice__CBOR_Pulse_API_Nondet_C_cbor_nondet_map_get_multiple_entry_t; - -static Pulse_Lib_Slice_slice__CBOR_Pulse_API_Nondet_C_cbor_nondet_map_get_multiple_entry_t -Pulse_Lib_Slice_arrayptr_to_slice_intro__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw( - cbor_nondet_map_get_multiple_entry_t *a, - size_t alen -) -{ - return - ( - (Pulse_Lib_Slice_slice__CBOR_Pulse_API_Nondet_C_cbor_nondet_map_get_multiple_entry_t){ - .elt = a, - .len = alen - } - ); -} - -static size_t -Pulse_Lib_Slice_len__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw( - Pulse_Lib_Slice_slice__CBOR_Pulse_API_Nondet_C_cbor_nondet_map_get_multiple_entry_t s -) -{ - return s.len; -} - -static cbor_nondet_map_get_multiple_entry_t -Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw( - Pulse_Lib_Slice_slice__CBOR_Pulse_API_Nondet_C_cbor_nondet_map_get_multiple_entry_t a, - size_t i -) -{ - return a.elt[i]; -} - -static void -Pulse_Lib_Slice_op_Array_Assignment__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw( - Pulse_Lib_Slice_slice__CBOR_Pulse_API_Nondet_C_cbor_nondet_map_get_multiple_entry_t a, - size_t i, - cbor_nondet_map_get_multiple_entry_t v -) -{ - a.elt[i] = v; -} - -bool -cbor_nondet_map_get_multiple( - cbor_raw map, - cbor_nondet_map_get_multiple_entry_t *dest, - size_t len -) -{ - if (dest == NULL) - return false; - else if (cbor_nondet_major_type(map) != CBOR_MAJOR_TYPE_MAP) - return false; - else - { - Pulse_Lib_Slice_slice__CBOR_Pulse_API_Nondet_C_cbor_nondet_map_get_multiple_entry_t - dests = - Pulse_Lib_Slice_arrayptr_to_slice_intro__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dest, - len); - size_t pi = (size_t)0U; - size_t i0 = pi; - bool - cond = - i0 < - Pulse_Lib_Slice_len__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dests); - while (cond) - { - size_t i = pi; - cbor_nondet_map_get_multiple_entry_t - x = - Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dests, - i); - Pulse_Lib_Slice_op_Array_Assignment__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dests, - i, - ((cbor_nondet_map_get_multiple_entry_t){ .key = x.key, .value = x.value, .found = false })); - pi = i + (size_t)1U; - size_t i0 = pi; - cond = - i0 < - Pulse_Lib_Slice_len__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dests); - } - cbor_map_iterator piter = CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_start(map); - size_t i1 = pi; - bool - cond0 = i1 != (size_t)0U && !CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_is_empty(piter); - while (cond0) - { - cbor_map_entry entry = CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_next(&piter); - size_t pj = (size_t)0U; - size_t j0 = pj; - size_t i0 = pi; - bool - cond = - j0 < - Pulse_Lib_Slice_len__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dests) - && i0 > (size_t)0U; - while (cond) - { - size_t j = pj; - pj = j + (size_t)1U; - cbor_nondet_map_get_multiple_entry_t - dest_entry = - Pulse_Lib_Slice_op_Array_Access__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dests, - j); - if (CBOR_Pulse_Raw_Nondet_cbor_nondet_equal(dest_entry.key, entry.cbor_map_entry_key)) - { - Pulse_Lib_Slice_op_Array_Assignment__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dests, - j, - ( - (cbor_nondet_map_get_multiple_entry_t){ - .key = dest_entry.key, - .value = CBOR_Pulse_Raw_Match_cbor_raw_reset_perm_tot(entry.cbor_map_entry_value), - .found = true - } - )); - if (!dest_entry.found) - pi = pi - (size_t)1U; - } - size_t j0 = pj; - size_t i = pi; - cond = - j0 < - Pulse_Lib_Slice_len__CBOR_Pulse_API_Base_cbor_map_get_multiple_entry_t_CBOR_Pulse_Raw_Type_cbor_raw(dests) - && i > (size_t)0U; - } - size_t i = pi; - cond0 = i != (size_t)0U && !CBOR_Pulse_Raw_Nondet_cbor_nondet_map_iterator_is_empty(piter); - } - return true; - } -} - diff --git a/3rdparty/internal/evercbor/CBORNondet.h b/3rdparty/internal/evercbor/CBORNondet.h deleted file mode 100644 index b6dec5be78fd..000000000000 --- a/3rdparty/internal/evercbor/CBORNondet.h +++ /dev/null @@ -1,134 +0,0 @@ - - -#ifndef CBORNondet_H -#define CBORNondet_H - -#if defined(__cplusplus) -extern "C" { -#endif - -#include "krmllib.h" - -#include "CBORNondetType.h" - -#define CBOR_MAJOR_TYPE_SIMPLE_VALUE (7U) - -#define CBOR_MAJOR_TYPE_UINT64 (0U) - -#define CBOR_MAJOR_TYPE_NEG_INT64 (1U) - -#define CBOR_MAJOR_TYPE_BYTE_STRING (2U) - -#define CBOR_MAJOR_TYPE_TEXT_STRING (3U) - -#define CBOR_MAJOR_TYPE_ARRAY (4U) - -#define CBOR_MAJOR_TYPE_MAP (5U) - -#define CBOR_MAJOR_TYPE_TAGGED (6U) - -#define MIN_SIMPLE_VALUE_LONG_ARGUMENT (32U) - -#define MAX_SIMPLE_VALUE_ADDITIONAL_INFO (23U) - -bool -cbor_nondet_parse( - bool check_map_key_bound, - size_t map_key_bound, - uint8_t **pinput, - size_t *plen, - cbor_raw *dest -); - -size_t cbor_nondet_size(cbor_raw x, size_t bound); - -size_t cbor_nondet_serialize(cbor_raw x, uint8_t *output, size_t len); - -uint8_t cbor_nondet_major_type(cbor_raw x); - -bool cbor_nondet_read_simple_value(cbor_raw x, uint8_t *dest); - -bool cbor_nondet_read_uint64(cbor_raw x, uint64_t *dest); - -bool cbor_nondet_read_int64(cbor_raw x, int64_t *dest); - -bool cbor_nondet_get_string(cbor_raw x, uint8_t **dest, uint64_t *dlen); - -bool cbor_nondet_get_byte_string(cbor_raw x, uint8_t **dest, uint64_t *dlen); - -bool cbor_nondet_get_text_string(cbor_raw x, uint8_t **dest, uint64_t *dlen); - -bool cbor_nondet_get_tagged(cbor_raw x, cbor_raw *dest, uint64_t *dtag); - -bool cbor_nondet_get_array_length(cbor_raw x, uint64_t *dest); - -bool cbor_nondet_array_iterator_start(cbor_raw x, cbor_array_iterator *dest); - -bool cbor_nondet_array_iterator_is_empty(cbor_array_iterator x); - -uint64_t cbor_nondet_array_iterator_length(cbor_array_iterator x); - -bool cbor_nondet_array_iterator_next(cbor_array_iterator *x, cbor_raw *dest); - -cbor_array_iterator cbor_nondet_array_iterator_truncate(cbor_array_iterator x, uint64_t len); - -bool cbor_nondet_get_array_item(cbor_raw x, uint64_t i, cbor_raw *dest); - -bool cbor_nondet_get_map_length(cbor_raw x, uint64_t *dest); - -bool cbor_nondet_map_iterator_start(cbor_raw x, cbor_map_iterator *dest); - -bool cbor_nondet_map_iterator_is_empty(cbor_map_iterator x); - -cbor_raw cbor_nondet_map_entry_key(cbor_map_entry x); - -cbor_raw cbor_nondet_map_entry_value(cbor_map_entry x); - -bool -cbor_nondet_map_iterator_next(cbor_map_iterator *x, cbor_raw *dest_key, cbor_raw *dest_value); - -bool cbor_nondet_equal(cbor_raw x1, cbor_raw x2); - -bool cbor_nondet_map_get(cbor_raw x, cbor_raw k, cbor_raw *dest); - -bool cbor_nondet_mk_simple_value(uint8_t v, cbor_raw *dest); - -cbor_raw cbor_nondet_mk_uint64(uint64_t v); - -cbor_raw cbor_nondet_mk_neg_int64(uint64_t v); - -cbor_raw cbor_nondet_mk_int64(int64_t v); - -bool cbor_nondet_mk_byte_string(uint8_t *a, uint64_t len, cbor_raw *dest); - -bool cbor_nondet_mk_text_string(uint8_t *a, uint64_t len, cbor_raw *dest); - -bool cbor_nondet_mk_tagged(uint64_t tag, cbor_raw *r, cbor_raw *dest); - -bool cbor_nondet_mk_array(cbor_raw *a, uint64_t len, cbor_raw *dest); - -cbor_map_entry cbor_nondet_mk_map_entry(cbor_raw xk, cbor_raw xv); - -bool cbor_nondet_mk_map(cbor_map_entry *a, uint64_t len, cbor_raw *dest); - -typedef struct cbor_nondet_map_get_multiple_entry_t_s -{ - cbor_raw key; - cbor_raw value; - bool found; -} -cbor_nondet_map_get_multiple_entry_t; - -bool -cbor_nondet_map_get_multiple( - cbor_raw map, - cbor_nondet_map_get_multiple_entry_t *dest, - size_t len -); - -#if defined(__cplusplus) -} -#endif - -#define CBORNondet_H_DEFINED -#endif /* CBORNondet_H */ diff --git a/3rdparty/internal/evercbor/CBORNondetType.h b/3rdparty/internal/evercbor/CBORNondetType.h deleted file mode 100644 index b2706c3ca06a..000000000000 --- a/3rdparty/internal/evercbor/CBORNondetType.h +++ /dev/null @@ -1,172 +0,0 @@ - - -#ifndef CBORNondetType_H -#define CBORNondetType_H - -#if defined(__cplusplus) -extern "C" { -#endif - -#include "krmllib.h" - -typedef struct CBOR_Spec_Raw_Base_raw_uint64_s -{ - uint8_t size; - uint64_t value; -} -CBOR_Spec_Raw_Base_raw_uint64; - -typedef struct CBOR_Pulse_Raw_Slice_byte_slice_s -{ - uint8_t *elt; - size_t len; -} -CBOR_Pulse_Raw_Slice_byte_slice; - -typedef struct CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator_s -{ - CBOR_Pulse_Raw_Slice_byte_slice s; - uint64_t len; -} -CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator; - -typedef struct cbor_serialized_s -{ - CBOR_Spec_Raw_Base_raw_uint64 cbor_serialized_header; - CBOR_Pulse_Raw_Slice_byte_slice cbor_serialized_payload; -} -cbor_serialized; - -typedef struct cbor_int_s -{ - uint8_t cbor_int_type; - uint8_t cbor_int_size; - uint64_t cbor_int_value; -} -cbor_int; - -typedef struct cbor_string_s -{ - uint8_t cbor_string_type; - uint8_t cbor_string_size; - CBOR_Pulse_Raw_Slice_byte_slice cbor_string_ptr; -} -cbor_string; - -typedef struct cbor_raw_s cbor_raw; - -typedef struct cbor_tagged_s -{ - CBOR_Spec_Raw_Base_raw_uint64 cbor_tagged_tag; - cbor_raw *cbor_tagged_ptr; -} -cbor_tagged; - -typedef struct Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw_s -{ - cbor_raw *elt; - size_t len; -} -Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw; - -typedef struct cbor_array_s -{ - uint8_t cbor_array_length_size; - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw cbor_array_ptr; -} -cbor_array; - -typedef struct cbor_map_entry_s cbor_map_entry; - -typedef struct Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry_s -{ - cbor_map_entry *elt; - size_t len; -} -Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry; - -typedef struct cbor_map_s -{ - uint8_t cbor_map_length_size; - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry cbor_map_ptr; -} -cbor_map; - -#define CBOR_Case_Int 0 -#define CBOR_Case_Simple 1 -#define CBOR_Case_String 2 -#define CBOR_Case_Tagged 3 -#define CBOR_Case_Array 4 -#define CBOR_Case_Map 5 -#define CBOR_Case_Serialized_Tagged 6 -#define CBOR_Case_Serialized_Array 7 -#define CBOR_Case_Serialized_Map 8 - -typedef uint8_t cbor_raw_tags; - -typedef struct cbor_raw_s -{ - cbor_raw_tags tag; - union { - cbor_int case_CBOR_Case_Int; - uint8_t case_CBOR_Case_Simple; - cbor_string case_CBOR_Case_String; - cbor_tagged case_CBOR_Case_Tagged; - cbor_array case_CBOR_Case_Array; - cbor_map case_CBOR_Case_Map; - cbor_serialized case_CBOR_Case_Serialized_Tagged; - cbor_serialized case_CBOR_Case_Serialized_Array; - cbor_serialized case_CBOR_Case_Serialized_Map; - } - ; -} -cbor_raw; - -typedef struct cbor_map_entry_s -{ - cbor_raw cbor_map_entry_key; - cbor_raw cbor_map_entry_value; -} -cbor_map_entry; - -#define CBOR_Raw_Iterator_Slice 0 -#define CBOR_Raw_Iterator_Serialized 1 - -typedef uint8_t cbor_array_iterator_tags; - -typedef struct cbor_array_iterator_s -{ - cbor_array_iterator_tags tag; - union { - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_raw case_CBOR_Raw_Iterator_Slice; - CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator case_CBOR_Raw_Iterator_Serialized; - } - ; -} -cbor_array_iterator; - -typedef struct cbor_map_iterator_s -{ - cbor_array_iterator_tags tag; - union { - Pulse_Lib_Slice_slice__CBOR_Pulse_Raw_Type_cbor_map_entry case_CBOR_Raw_Iterator_Slice; - CBOR_Pulse_Raw_Iterator_Base_cbor_raw_serialized_iterator case_CBOR_Raw_Iterator_Serialized; - } - ; -} -cbor_map_iterator; - -typedef cbor_raw cbor_nondet_t; - -typedef cbor_array_iterator cbor_nondet_array_iterator_t; - -typedef cbor_map_iterator cbor_nondet_map_iterator_t; - -typedef cbor_map_entry cbor_nondet_map_entry_t; - -#if defined(__cplusplus) -} -#endif - -#define CBORNondetType_H_DEFINED -#endif /* CBORNondetType_H */ diff --git a/3rdparty/internal/evercbor/internal/CBORNondet.h b/3rdparty/internal/evercbor/internal/CBORNondet.h deleted file mode 100644 index 0c232f9c1e60..000000000000 --- a/3rdparty/internal/evercbor/internal/CBORNondet.h +++ /dev/null @@ -1,64 +0,0 @@ - - -#ifndef internal_CBORNondet_H -#define internal_CBORNondet_H - -#if defined(__cplusplus) -extern "C" { -#endif - -#include "krmllib.h" - -#include "CBORNondetType.h" -#include "../CBORNondet.h" - -#define FStar_Pervasives_Native_None 0 -#define FStar_Pervasives_Native_Some 1 - -typedef uint8_t FStar_Pervasives_Native_option__bool_tags; - -typedef struct FStar_Pervasives_Native_option__bool_s -{ - FStar_Pervasives_Native_option__bool_tags tag; - bool v; -} -FStar_Pervasives_Native_option__bool; - -typedef struct FStar_Pervasives_Native_option__size_t_s -{ - FStar_Pervasives_Native_option__bool_tags tag; - size_t v; -} -FStar_Pervasives_Native_option__size_t; - -size_t -CBOR_Pulse_Raw_Format_Serialize_ser_( - cbor_raw x_, - CBOR_Pulse_Raw_Slice_byte_slice out, - size_t offset -); - -bool CBOR_Pulse_Raw_Format_Serialize_siz_(cbor_raw x_, size_t *out); - -bool -CBOR_Pulse_Raw_EverParse_Nondet_Gen_impl_check_map_depth_aux( - size_t bound, - CBOR_Pulse_Raw_Slice_byte_slice *pl, - size_t n1 -); - -FStar_Pervasives_Native_option__bool -CBOR_Pulse_Raw_EverParse_Nondet_Basic_impl_check_equiv_map_hd_basic( - FStar_Pervasives_Native_option__size_t map_bound, - CBOR_Pulse_Raw_Slice_byte_slice l1, - CBOR_Pulse_Raw_Slice_byte_slice l2 -); - -bool CBOR_Pulse_Raw_Nondet_Compare_cbor_nondet_equiv(cbor_raw x1, cbor_raw x2); - -#if defined(__cplusplus) -} -#endif - -#define internal_CBORNondet_H_DEFINED -#endif /* internal_CBORNondet_H */ diff --git a/3rdparty/internal/evercbor/krmllib.h b/3rdparty/internal/evercbor/krmllib.h deleted file mode 100644 index eca4035f305a..000000000000 --- a/3rdparty/internal/evercbor/krmllib.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef __KRMLLIB_H -#define __KRMLLIB_H - -#include -#include -#include -#include -#include - -#ifndef KRML_HOST_PRINTF -# include -# define KRML_HOST_PRINTF printf -#endif - -#if ( \ - (defined __STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ - (!(defined KRML_HOST_EPRINTF))) -# define KRML_HOST_EPRINTF(...) fprintf(stderr, __VA_ARGS__) -#elif !(defined KRML_HOST_EPRINTF) && defined(_MSC_VER) -# define KRML_HOST_EPRINTF(...) fprintf(stderr, __VA_ARGS__) -#endif - -#ifndef KRML_HOST_EXIT -# define KRML_HOST_EXIT exit -#endif - -#ifndef KRML_HOST_MALLOC -# define KRML_HOST_MALLOC malloc -#endif - -#ifndef KRML_HOST_CALLOC -# define KRML_HOST_CALLOC calloc -#endif - -#ifndef KRML_HOST_FREE -# define KRML_HOST_FREE free -#endif - -#ifndef KRML_HOST_IGNORE -# define KRML_HOST_IGNORE(x) (void)(x) -#endif - -/* In FStar.Buffer.fst, the size of arrays is uint32_t, but it's a number of - * *elements*. Do an ugly, run-time check (some of which KaRaMeL can eliminate). - */ -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)) -# define _KRML_CHECK_SIZE_PRAGMA \ - _Pragma("GCC diagnostic ignored \"-Wtype-limits\"") -#else -# define _KRML_CHECK_SIZE_PRAGMA -#endif - -#define KRML_CHECK_SIZE(size_elt, sz) \ - do { \ - _KRML_CHECK_SIZE_PRAGMA \ - if (((size_t)(sz)) > ((size_t)(SIZE_MAX / (size_elt)))) { \ - KRML_HOST_PRINTF( \ - "Maximum allocatable size exceeded, aborting before overflow at " \ - "%s:%d\n", \ - __FILE__, __LINE__); \ - KRML_HOST_EXIT(253); \ - } \ - } while (0) - -/* In expression position, use the comma-operator and a malloc to return an - * expression of the right size. KaRaMeL passes t as the parameter to the macro. - */ -#define KRML_EABORT(t, msg) \ - (KRML_HOST_PRINTF("KaRaMeL abort at %s:%d\n%s\n", __FILE__, __LINE__, msg), \ - KRML_HOST_EXIT(255), *((t *)KRML_HOST_MALLOC(sizeof(t)))) - -#ifndef KRML_MAYBE_UNUSED_VAR -# define KRML_MAYBE_UNUSED_VAR(x) KRML_HOST_IGNORE(x) -#endif - -#endif /* __KRMLLIB_H */ diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f8e70de3586..ee8b5f7217b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [7.0.15] + +[7.0.15]: https://github.com/microsoft/CCF/releases/tag/ccf-7.0.15 + +### Changed + +- CBOR parsing now rejects composite (array or map) and tagged values used as map keys anywhere in the decoded document, including nested maps in optional COSE headers (#8297). + +### Removed + +- Removed the exported `evercbor` CMake target and installed `libevercbor.a` library. Applications using CCF's public APIs that explicitly depend on this target or link this library directly must remove that dependency. No further build changes are necessary: the replacement CBOR implementation is linked transitively by CCF (#8297). + ## [7.0.14] [7.0.14]: https://github.com/microsoft/CCF/releases/tag/ccf-7.0.14 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d824d68810c..3168337ac6a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,9 +164,14 @@ include_directories(${CCF_DIR}/src) set(CCF_3RD_PARTY_EXPORTED_DIR "${CCF_DIR}/3rdparty/exported") set(CCF_3RD_PARTY_INTERNAL_DIR "${CCF_DIR}/3rdparty/internal") +set( + TAV_INCLUDE_DIR + "${CCF_3RD_PARTY_INTERNAL_DIR}/tee-attestation-verification/ffi/include" +) include_directories(SYSTEM ${CCF_3RD_PARTY_EXPORTED_DIR}) include_directories(SYSTEM ${CCF_3RD_PARTY_INTERNAL_DIR}) +include_directories(SYSTEM ${TAV_INCLUDE_DIR}) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/tools.cmake) @@ -223,7 +228,6 @@ include(${CCF_DIR}/cmake/ccf_rs.cmake) include(${CCF_DIR}/cmake/threading.cmake) include(${CCF_DIR}/cmake/crypto.cmake) include(${CCF_DIR}/cmake/quickjs.cmake) -include(${CCF_DIR}/cmake/evercbor.cmake) # Launcher library list( @@ -757,10 +761,9 @@ if(BUILD_TESTS) if(FUZZING) add_fuzz_test( cbor_fuzz_test - ${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/cbor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/test/cbor_fuzz.cpp ) - target_link_libraries(cbor_fuzz_test PRIVATE evercbor) + target_link_libraries(cbor_fuzz_test PRIVATE ccfcrypto) endif() add_unit_test( @@ -842,7 +845,6 @@ if(BUILD_TESTS) ENVIRONMENT "TEST_ENDORSEMENTS_PATH=${CMAKE_CURRENT_SOURCE_DIR}/tests/uvm_endorsements" ) - target_link_libraries(endorsements_test PRIVATE evercbor) add_unit_test( historical_queries_test diff --git a/cgmanifest.json b/cgmanifest.json index 14462cac030c..e6019ee79296 100644 --- a/cgmanifest.json +++ b/cgmanifest.json @@ -110,16 +110,6 @@ } } }, - { - "component": { - "type": "git", - "git": { - "repositoryUrl": "https://github.com/project-everest/everparse", - "commitHash": "950bc93838ac2faae51126d8acd0637cf8c8a569", - "tag": "v2026.07.02" - } - } - }, { "component": { "type": "git", diff --git a/cmake/crypto.cmake b/cmake/crypto.cmake index 0efcee0742dd..da483a15ee08 100644 --- a/cmake/crypto.cmake +++ b/cmake/crypto.cmake @@ -27,7 +27,6 @@ set( ${CCF_DIR}/src/crypto/openssl/verifier.cpp ${CCF_DIR}/src/crypto/openssl/cose_verifier.cpp ${CCF_DIR}/src/crypto/sharing.cpp - ${CCF_DIR}/src/crypto/cbor.cpp ) find_library(CRYPTO_LIBRARY crypto) @@ -43,7 +42,7 @@ add_san(ccfcrypto) add_hardening(ccfcrypto) add_tidy(ccfcrypto) -target_link_libraries(ccfcrypto PUBLIC crypto ssl evercbor ccf_threading) +target_link_libraries(ccfcrypto PUBLIC crypto ssl ccf_threading) target_link_libraries( ccfcrypto PUBLIC diff --git a/cmake/evercbor.cmake b/cmake/evercbor.cmake deleted file mode 100644 index a34e9e538dd4..000000000000 --- a/cmake/evercbor.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the Apache 2.0 License. - -# Build EverCBOR -set(EVERCBOR_DIR "${CCF_3RD_PARTY_INTERNAL_DIR}/evercbor") -set(EVERCBOR_SRCS "${EVERCBOR_DIR}/CBORNondet.c") - -add_library(evercbor STATIC ${EVERCBOR_SRCS}) - -target_include_directories( - evercbor - PUBLIC $ -) - -target_compile_options(evercbor PRIVATE -Wno-everything) -set_property(TARGET evercbor PROPERTY POSITION_INDEPENDENT_CODE ON) -add_san(evercbor) -add_hardening(evercbor) - -install(TARGETS evercbor EXPORT ccf DESTINATION lib) diff --git a/python/pyproject.toml b/python/pyproject.toml index 7529d0383b9b..50017d2f73df 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ccf" -version = "7.0.14" +version = "7.0.15" authors = [ { name="CCF Team", email="CCF-Sec@microsoft.com" }, ] diff --git a/src/cose/cose_rs/Cargo.lock b/src/cose/cose_rs/Cargo.lock index 2c296c56827d..b9bb3136bd27 100644 --- a/src/cose/cose_rs/Cargo.lock +++ b/src/cose/cose_rs/Cargo.lock @@ -26,9 +26,8 @@ dependencies = [ name = "cose-openssl" version = "0.1.0" dependencies = [ - "cborrs", - "cborrs-nondet", "openssl-sys", + "tee-attestation-verification-cbor", ] [[package]] @@ -74,6 +73,14 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "tee-attestation-verification-cbor" +version = "1.0.8" +dependencies = [ + "cborrs", + "cborrs-nondet", +] + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/src/cose/cose_rs/src/lib.rs b/src/cose/cose_rs/src/lib.rs index a1d73b596236..7c725f4f4315 100644 --- a/src/cose/cose_rs/src/lib.rs +++ b/src/cose/cose_rs/src/lib.rs @@ -49,56 +49,50 @@ unsafe fn str_from_raw(ptr: *const u8, len: usize) -> &'static str { std::str::from_utf8(bytes).unwrap_or("") } -fn build_ledger_phdr(kid: &[u8], iat: i64, issuer: &str, subject: &str, txid: &str) -> CborValue { +fn build_ledger_phdr<'a>( + kid: &'a [u8], + iat: i64, + issuer: &'a str, + subject: &'a str, + txid: &'a str, +) -> CborValue<'a> { let cwt = CborValue::Map(vec![ (CborValue::Int(IAT), CborValue::Int(iat)), - ( - CborValue::Int(ISS), - CborValue::TextString(issuer.to_string()), - ), - ( - CborValue::Int(SUB), - CborValue::TextString(subject.to_string()), - ), + (CborValue::Int(ISS), CborValue::text(issuer)), + (CborValue::Int(SUB), CborValue::text(subject)), ]); - let ccf = CborValue::Map(vec![( - CborValue::TextString(TX_ID.to_string()), - CborValue::TextString(txid.to_string()), - )]); + let ccf = CborValue::Map(vec![(CborValue::text(TX_ID), CborValue::text(txid))]); CborValue::Map(vec![ - (CborValue::Int(KID), CborValue::ByteString(kid.to_vec())), + (CborValue::Int(KID), CborValue::bytes(kid)), (CborValue::Int(VDS), CborValue::Int(CCF_LEDGER_SHA256)), (CborValue::Int(CWT_CLAIMS), cwt), - (CborValue::TextString(CCF_V1.to_string()), ccf), + (CborValue::text(CCF_V1), ccf), ]) } -fn build_endorsement_phdr( +fn build_endorsement_phdr<'a>( iat: i64, - epoch_begin: &str, - epoch_end: &str, - previous_merkle_root: &[u8], -) -> CborValue { + epoch_begin: &'a str, + epoch_end: &'a str, + previous_merkle_root: &'a [u8], +) -> CborValue<'a> { let cwt = CborValue::Map(vec![(CborValue::Int(IAT), CborValue::Int(iat))]); let mut ccf_entries = vec![( - CborValue::TextString(TX_RANGE_BEGIN.to_string()), - CborValue::TextString(epoch_begin.to_string()), + CborValue::text(TX_RANGE_BEGIN), + CborValue::text(epoch_begin), )]; if !epoch_end.is_empty() { - ccf_entries.push(( - CborValue::TextString(TX_RANGE_END.to_string()), - CborValue::TextString(epoch_end.to_string()), - )); + ccf_entries.push((CborValue::text(TX_RANGE_END), CborValue::text(epoch_end))); } if !previous_merkle_root.is_empty() { ccf_entries.push(( - CborValue::TextString(EPOCH_LAST_MERKLE_ROOT.to_string()), - CborValue::ByteString(previous_merkle_root.to_vec()), + CborValue::text(EPOCH_LAST_MERKLE_ROOT), + CborValue::bytes(previous_merkle_root), )); } @@ -106,7 +100,7 @@ fn build_endorsement_phdr( CborValue::Map(vec![ (CborValue::Int(CWT_CLAIMS), cwt), - (CborValue::TextString(CCF_V1.to_string()), ccf), + (CborValue::text(CCF_V1), ccf), ]) } diff --git a/src/cose/test/cose_ffi_test.cpp b/src/cose/test/cose_ffi_test.cpp index b6b2401a2006..38c2f3daab70 100644 --- a/src/cose/test/cose_ffi_test.cpp +++ b/src/cose/test/cose_ffi_test.cpp @@ -4,12 +4,15 @@ #include "ccf/crypto/verifier.h" #include "cose/cose_rs_ffi.h" -#include "crypto/cbor.h" +#include "crypto/cbor_helpers.h" +#include "crypto/cbor_tags.h" #include "crypto/cose.h" #include "crypto/openssl/ec_key_pair.h" +#include "crypto/test/cbor_printer.h" #include #include +#include #include namespace @@ -37,29 +40,29 @@ namespace CoseSign1Components decompose(const std::vector& envelope) { - using namespace ccf::cbor; - auto cose = parse(envelope); - const auto& env = cose->tag_at(ccf::cbor::tag::COSE_SIGN_1); - auto phdr = env->array_at(0)->as_bytes(); + using namespace tav::cbor; + auto cose = nondet_parse(envelope); + const auto& env = cose.tag_at(ccf::cbor::tag::COSE_SIGN_1); + auto phdr = env.array_at(0).as_bytes(); std::optional> payload; try { - payload = env->array_at(2)->as_bytes(); + payload = env.array_at(2).as_bytes(); } - catch (const CBORDecodeError&) + catch (const DecodeError&) { - if (env->array_at(2)->as_simple() != ccf::cbor::SimpleValue::Null) + if (env.array_at(2).as_simple() != tav::cbor::SimpleValue::Null) { throw; } } - auto sig = env->array_at(3)->as_bytes(); + auto sig = env.array_at(3).as_bytes(); - auto phdr_parsed = parse({phdr.data(), phdr.size()}); - auto alg = phdr_parsed->map_at(make_signed(ccf::cose::header::iana::ALG)) - ->as_signed(); + auto phdr_parsed = nondet_parse({phdr.data(), phdr.size()}); + auto alg = + phdr_parsed.map_at(make_signed(ccf::cose::header::iana::ALG)).as_signed(); return {phdr, payload, sig, alg}; } diff --git a/src/crypto/cbor.cpp b/src/crypto/cbor.cpp deleted file mode 100644 index 3fc853a6968d..000000000000 --- a/src/crypto/cbor.cpp +++ /dev/null @@ -1,792 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the Apache 2.0 License. - -#include "crypto/cbor.h" - -#include "ccf/ds/hex.h" - -#include -#include -#include -#include - -#define FMT_HEADER_ONLY -#include - -extern "C" -{ -#include "evercbor/CBORNondet.h" -} - -using namespace ccf::cbor; - -namespace -{ - /* Handy storage of 'cbor_raw's when recursively nesting objects. EverCBOR - * collections work as pointers from one cbor_raw to another, with arrays - * relying on space continuity, and that has to stay intact until calling - * cbor_nondet_serialize. Therefore, the following choices have been made: - * - * - individual items stored in lists rather than collections to avoid - * move-on-resize - * - CBOR collections are made vectors for continuity, and only referenced - * after filled up. - */ - class CborRawArena - { - public: - CborRawArena() = default; - ~CborRawArena() = default; - - void push(cbor_raw&& single) - { - singles.push_back(single); - } - - [[nodiscard]] cbor_raw* single() const - { - return const_cast(&singles.back()); - } - - void push(std::vector&& array) - { - arrays.push_back(array); - } - - [[nodiscard]] cbor_raw* array() const - { - return const_cast(&arrays.back().front()); - } - - void push(std::vector&& map) - { - maps.push_back(map); - } - - [[nodiscard]] cbor_map_entry* map() const - { - return const_cast(&maps.back().front()); - } - - // No copy - CborRawArena(const CborRawArena&) = delete; - CborRawArena& operator=(const CborRawArena&) = delete; - - // No move - CborRawArena(CborRawArena&&) = delete; - CborRawArena& operator=(CborRawArena&&) = delete; - - private: - std::list singles; - std::list> arrays; - std::list> maps; - }; - Value consume(cbor_nondet_t cbor, size_t depth, size_t max_depth); - - void print_indent(std::ostringstream& os, size_t indent) - { - for (size_t i = 0; i < indent; ++i) - { - os << " "; - } - } - - Value consume_signed(cbor_nondet_t cbor) - { - Signed value{0}; - if (!cbor_nondet_read_int64(cbor, &value)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to decode signed value"); - } - return std::make_shared(value); - } - - Value consume_byte_string(cbor_nondet_t cbor) - { - uint8_t* data = nullptr; - uint64_t length = 0; - if (!cbor_nondet_get_byte_string(cbor, &data, &length)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to decode byte string"); - } - Bytes value{data, static_cast(length)}; - return std::make_shared(value); - } - - Value consume_text_string(cbor_nondet_t cbor) - { - uint8_t* data = nullptr; - uint64_t length = 0; - if (!cbor_nondet_get_text_string(cbor, &data, &length)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to decode text string"); - } - String value{ - reinterpret_cast(data), static_cast(length)}; - return std::make_shared(value); - } - - Value consume_array(cbor_nondet_t cbor, size_t depth, size_t max_depth) - { - cbor_nondet_array_iterator_t iter; - if (!cbor_nondet_array_iterator_start(cbor, &iter)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to start array iterator"); - } - - Array array; - while (!cbor_nondet_array_iterator_is_empty(iter)) - { - cbor_nondet_t item; - if (!cbor_nondet_array_iterator_next(&iter, &item)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to get next array item"); - } - array.items.push_back(consume(item, depth + 1, max_depth)); - } - return std::make_shared(std::move(array)); - } - - Value consume_map(cbor_nondet_t cbor, size_t depth, size_t max_depth) - { - cbor_map_iterator iter; - if (!cbor_nondet_map_iterator_start(cbor, &iter)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to start map iterator"); - } - - Map map; - while (!cbor_nondet_map_iterator_is_empty(iter)) - { - cbor_raw key_raw; - cbor_raw value_raw; - if (!cbor_nondet_map_iterator_next(&iter, &key_raw, &value_raw)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to get next map entry"); - } - map.items.emplace_back( - consume(key_raw, depth + 1, max_depth), - consume(value_raw, depth + 1, max_depth)); - } - return std::make_shared(std::move(map)); - } - - Value consume_tagged(cbor_nondet_t cbor, size_t depth, size_t max_depth) - { - uint64_t tag = 0; - cbor_nondet_t payload; - if (!cbor_nondet_get_tagged(cbor, &payload, &tag)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to decode tagged value"); - } - - Tagged tagged; - tagged.tag = tag; - tagged.item = consume(payload, depth + 1, max_depth); - return std::make_shared(std::move(tagged)); - } - - Value consume_simple(cbor_nondet_t cbor) - { - // Return the raw simple value (single byte) and leave detailed - // interpretation to the caller. EverCBOR does not yet support more granular - // parsing, or floating point numbers with extra payload. - Simple value{0}; - if (!cbor_nondet_read_simple_value(cbor, &value)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to decode simple value"); - } - return std::make_shared(value); - } - - Value consume(cbor_nondet_t cbor, size_t depth, size_t max_depth) - { - if (depth > max_depth) - { - throw CBORDecodeError( - Error::DECODE_FAILED, - fmt::format("Maximum CBOR nesting depth ({}) exceeded", max_depth)); - } - - const auto mt = cbor_nondet_major_type(cbor); - switch (mt) - { - case CBOR_MAJOR_TYPE_UINT64: - case CBOR_MAJOR_TYPE_NEG_INT64: - return consume_signed(cbor); - case CBOR_MAJOR_TYPE_BYTE_STRING: - return consume_byte_string(cbor); - case CBOR_MAJOR_TYPE_TEXT_STRING: - return consume_text_string(cbor); - case CBOR_MAJOR_TYPE_ARRAY: - return consume_array(cbor, depth, max_depth); - case CBOR_MAJOR_TYPE_MAP: - return consume_map(cbor, depth, max_depth); - case CBOR_MAJOR_TYPE_TAGGED: - return consume_tagged(cbor, depth, max_depth); - case CBOR_MAJOR_TYPE_SIMPLE_VALUE: - return consume_simple(cbor); - default: - throw CBORDecodeError(Error::DECODE_FAILED, "Unknown CBOR major type"); - } - } - - std::string format_simple(const Simple& v) - { - const auto casted = static_cast(v); - switch (casted) - { - case SimpleValue::False: - return "Simple: False"; - case SimpleValue::True: - return "Simple: True"; - case SimpleValue::Null: - return "Simple: Null"; - case SimpleValue::Undefined: - return "Simple: Undefined"; - default: - return "Simple: " + std::to_string(casted); - } - } - - cbor_raw to_raw_cbor( - const Value& value, CborRawArena& arena, size_t depth, size_t max_depth); - - cbor_raw to_raw_signed(const Signed& v) - { - return cbor_nondet_mk_int64(v); - } - - // EverCBOR rejects null data pointers, which empty spans and string_views - // may hold. Never dereferenced, because the length is zero. - uint8_t empty_string_placeholder{0}; - - cbor_raw to_raw_string(const String& v) - { - cbor_raw result; - auto* data = v.empty() ? - &empty_string_placeholder : - reinterpret_cast(const_cast(v.data())); - if (!cbor_nondet_mk_text_string(data, v.size(), &result)) - { - throw CBOREncodeError( - Error::ENCODE_FAILED, fmt::format("Encoding text string {} failed", v)); - } - return result; - } - - cbor_raw to_raw_bytes(const Bytes& v) - { - cbor_raw result; - auto* data = - v.empty() ? &empty_string_placeholder : const_cast(v.data()); - if (!cbor_nondet_mk_byte_string(data, v.size(), &result)) - { - throw CBOREncodeError( - Error::ENCODE_FAILED, - fmt::format("Encoding bytes string {} failed", ccf::ds::to_hex(v))); - } - return result; - } - - cbor_raw to_raw_simple(const Simple& v) - { - cbor_raw result; - if (!cbor_nondet_mk_simple_value(v, &result)) - { - throw CBOREncodeError( - Error::ENCODE_FAILED, - fmt::format("Encoding simple value {} failed", format_simple(v))); - } - return result; - } - - cbor_raw to_raw_tagged( - const Tagged& v, CborRawArena& arena, size_t depth, size_t max_depth) - { - cbor_raw result; - arena.push(to_raw_cbor(v.item, arena, depth + 1, max_depth)); - if (!cbor_nondet_mk_tagged(v.tag, arena.single(), &result)) - { - throw CBOREncodeError( - Error::ENCODE_FAILED, fmt::format("Encoding tag {} failed", v.tag)); - } - - return result; - } - - cbor_raw to_raw_array( - const Array& v, CborRawArena& arena, size_t depth, size_t max_depth) - { - cbor_raw result; - std::vector items; - items.reserve(v.items.size()); - for (const auto& item : v.items) - { - items.push_back(to_raw_cbor(item, arena, depth + 1, max_depth)); - } - - size_t arr_size = items.size(); - - // A workaround to encode an empty array by passing a fake ptr with size=0. - if (items.empty()) - { - items.push_back(cbor_raw{}); - } - - arena.push(std::move(items)); - if (!cbor_nondet_mk_array(arena.array(), arr_size, &result)) - { - throw CBOREncodeError( - Error::ENCODE_FAILED, - fmt::format("Encoding array of size {} failed", arr_size)); - } - - return result; - } - - cbor_raw to_raw_map( - const Map& v, CborRawArena& arena, size_t depth, size_t max_depth) - { - cbor_raw result; - - std::vector entries; - entries.reserve(v.items.size()); - for (const auto& [key, value] : v.items) - { - auto cbor_key = to_raw_cbor(key, arena, depth + 1, max_depth); - auto cbor_value = to_raw_cbor(value, arena, depth + 1, max_depth); - entries.push_back(cbor_nondet_mk_map_entry(cbor_key, cbor_value)); - } - - size_t map_size = entries.size(); - - // A workaround to encode an empty map by passing a fake ptr with size=0. - if (entries.empty()) - { - entries.push_back(cbor_map_entry{}); - } - - arena.push(std::move(entries)); - if (!cbor_nondet_mk_map(arena.map(), map_size, &result)) - { - throw CBOREncodeError( - Error::ENCODE_FAILED, - fmt::format("Encoding map of size {} failed", map_size)); - } - - return result; - } - - cbor_raw to_raw_cbor( - const Value& value, CborRawArena& arena, size_t depth, size_t max_depth) - { - if (depth > max_depth) - { - throw CBOREncodeError( - Error::ENCODE_FAILED, - fmt::format("Maximum CBOR nesting depth ({}) exceeded", max_depth)); - } - - return std::visit( - [&](const auto& v) { - using T = std::decay_t; - if constexpr (std::is_same_v) - { - return to_raw_signed(v); - } - if constexpr (std::is_same_v) - { - return to_raw_string(v); - } - if constexpr (std::is_same_v) - { - return to_raw_bytes(v); - } - if constexpr (std::is_same_v) - { - return to_raw_simple(v); - } - if constexpr (std::is_same_v) - { - return to_raw_tagged(v, arena, depth, max_depth); - } - if constexpr (std::is_same_v) - { - return to_raw_array(v, arena, depth, max_depth); - } - if constexpr (std::is_same_v) - { - return to_raw_map(v, arena, depth, max_depth); - } - }, - value->value); - } - - void print_value_impl( - std::ostringstream& os, const Value& value, size_t indent) - { - if (!value) - { - print_indent(os, indent); - os << "" << std::endl; - return; - } - - std::visit( - [&os, indent](const auto& v) { - using T = std::decay_t; - if constexpr (std::is_same_v) - { - print_indent(os, indent); - os << "Signed: " << v << std::endl; - } - else if constexpr (std::is_same_v) - { - print_indent(os, indent); - os << "Bytes[" << v.size() << "]:"; - if (!v.empty()) - { - os << " "; - } - os << ccf::ds::to_hex(v) << std::endl; - } - else if constexpr (std::is_same_v) - { - print_indent(os, indent); - os << "String: \"" << v << "\"" << std::endl; - } - else if constexpr (std::is_same_v) - { - print_indent(os, indent); - os << "Array[" << v.items.size() << "]:" << std::endl; - for (const auto& item : v.items) - { - print_value_impl(os, item, indent + 1); - } - } - else if constexpr (std::is_same_v) - { - print_indent(os, indent); - os << "Map[" << v.items.size() << "]:" << std::endl; - for (const auto& [key, val] : v.items) - { - print_indent(os, indent + 1); - os << "Key:" << std::endl; - print_value_impl(os, key, indent + 2); - print_indent(os, indent + 1); - os << "Value:" << std::endl; - print_value_impl(os, val, indent + 2); - } - } - else if constexpr (std::is_same_v) - { - print_indent(os, indent); - os << "Tagged[" << v.tag << "]:" << std::endl; - print_value_impl(os, v.item, indent + 1); - } - else if constexpr (std::is_same_v) - { - print_indent(os, indent); - os << format_simple(v) << std::endl; - } - }, - value->value); - } -} // namespace - -namespace ccf::cbor -{ - CBOREncodeError::CBOREncodeError(Error err, const std::string& what) : - std::runtime_error(what), - error(err) - {} - - Error CBOREncodeError::error_code() const - { - return error; - } - - CBORDecodeError::CBORDecodeError(Error err, const std::string& what) : - std::runtime_error(what), - error(err) - {} - - Error CBORDecodeError::error_code() const - { - return error; - } - - Value make_signed(int64_t value) - { - return std::make_shared(value); - } - - Value make_simple(SimpleValue value) - { - return std::make_shared(value); - } - - Value make_string(std::string_view data) - { - return std::make_shared(data); - } - - Value make_bytes(std::span data) - { - return std::make_shared(data); - } - - Value make_tagged(uint64_t tag, Value&& value) - { - return std::make_shared( - Tagged{.tag = tag, .item = std::move(value)}); - } - - Value make_array(std::vector&& data) - { - return std::make_shared(Array{.items = std::move(data)}); - } - - Value make_map(std::vector&& data) - { - return std::make_shared(Map{.items = std::move(data)}); - } - - Value parse(std::span raw, size_t max_depth) - { - cbor_nondet_t cbor; - const bool check_map_key_bound = false; - const size_t map_key_bound = 0; - auto* cbor_parse_input = const_cast(raw.data()); - size_t cbor_parse_size = raw.size(); - if (!cbor_nondet_parse( - check_map_key_bound, - map_key_bound, - &cbor_parse_input, - &cbor_parse_size, - &cbor)) - { - throw CBORDecodeError( - Error::DECODE_FAILED, "Failed to parse top-level cbor"); - } - - if (cbor_parse_size > 0) - { - throw CBORDecodeError( - Error::DECODE_FAILED, - fmt::format("Trailing {} byte(s) after CBOR item", cbor_parse_size)); - } - - return consume(cbor, 0, max_depth); - } - - std::vector serialize(const Value& value, size_t max_depth) - { - CborRawArena arena{}; - auto raw = to_raw_cbor(value, arena, 0, max_depth); - const auto expected_size = - cbor_nondet_size(raw, std::numeric_limits::max()); - - std::vector result(expected_size); - - const auto bytes_written = - cbor_nondet_serialize(raw, result.data(), expected_size); - if (bytes_written != expected_size) - { - throw CBOREncodeError( - Error::ENCODE_FAILED, - fmt::format( - "Encoded CBOR of size {} when expected {}", - bytes_written, - expected_size)); - } - - return result; - } - - std::string to_string(const Value& value) - { - std::ostringstream os; - constexpr size_t initial_indent{0}; - print_value_impl(os, value, initial_indent); - auto as_string = os.str(); - if (!as_string.empty() && as_string.back() == '\n') - { - as_string.pop_back(); - } - return as_string; - } - - bool simple_to_boolean(const Simple& value) - { - switch (value) - { - case SimpleValue::False: - return false; - case SimpleValue::True: - return true; - default: - throw CBORDecodeError( - Error::TYPE_MISMATCH, "Simple value cannot be matched to boolean"); - } - } - - SimpleValue boolean_to_simple(bool value) - { - return value ? SimpleValue::True : SimpleValue::False; - } - - const Value& ValueImpl::array_at(size_t index) const - { - if (!std::holds_alternative(value)) - { - throw CBORDecodeError(Error::TYPE_MISMATCH, "Not an array"); - } - - const auto& arr = std::get(value); - if (index >= arr.items.size()) - { - throw CBORDecodeError(Error::OUT_OF_BOUND, "Array index out of bounds"); - } - - return arr.items[index]; - } - - const Value& ValueImpl::map_at(const Value& key) const - { - if (!std::holds_alternative(value)) - { - throw CBORDecodeError(Error::TYPE_MISMATCH, "Not a map"); - } - - // Fail fast: Array, Map, Tagged are not supported as map keys in this - // version, and probably shouldn't be in the future. - std::visit( - [](const auto& k) { - using T = std::decay_t; - if constexpr ( - std::is_same_v || std::is_same_v || - std::is_same_v) - { - throw CBORDecodeError( - Error::TYPE_MISMATCH, - "Array, Map, and Tagged values cannot be used as map keys"); - } - }, - key->value); - - const auto& map = std::get(value); - for (const auto& [k, v] : map.items) - { - const bool match = std::visit( - [](const auto& a, const auto& b) -> bool { - using TA = std::decay_t; - using TB = std::decay_t; - - if constexpr (!std::is_same_v) - { - return false; - } - else if constexpr (std::is_same_v) - { - return a == b; - } - else if constexpr ( - std::is_same_v || std::is_same_v) - { - return std::equal(a.begin(), a.end(), b.begin(), b.end()); - } - else - { - return false; - } - }, - key->value, - k->value); - - if (match) - { - return v; - } - } - - throw CBORDecodeError(Error::KEY_NOT_FOUND, "Key not found in map"); - } - - size_t ValueImpl::size() const - { - if (std::holds_alternative(value)) - { - const auto& arr = std::get(value); - return arr.items.size(); - } - if (std::holds_alternative(value)) - { - const auto& map = std::get(value); - return map.items.size(); - } - throw CBORDecodeError(Error::TYPE_MISMATCH, "Not a collection"); - } - - const Value& ValueImpl::tag_at(uint64_t tag) const - { - if (!std::holds_alternative(value)) - { - throw CBORDecodeError(Error::TYPE_MISMATCH, "Not a tagged value"); - } - - const auto& tagged = std::get(value); - if (tagged.tag != tag) - { - throw CBORDecodeError(Error::KEY_NOT_FOUND, "Tag does not match"); - } - - return tagged.item; - } - - Signed ValueImpl::as_signed() const - { - if (!std::holds_alternative(value)) - { - throw CBORDecodeError(Error::TYPE_MISMATCH, "Not a signed value"); - } - return std::get(value); - } - - Bytes ValueImpl::as_bytes() const - { - if (!std::holds_alternative(value)) - { - throw CBORDecodeError(Error::TYPE_MISMATCH, "Not a bytes value"); - } - return std::get(value); - } - - String ValueImpl::as_string() const - { - if (!std::holds_alternative(value)) - { - throw CBORDecodeError(Error::TYPE_MISMATCH, "Not a string value"); - } - return std::get(value); - } - - Simple ValueImpl::as_simple() const - { - if (!std::holds_alternative(value)) - { - throw CBORDecodeError(Error::TYPE_MISMATCH, "Not a simple value"); - } - return std::get(value); - } -} // namespace ccf::cbor \ No newline at end of file diff --git a/src/crypto/cbor.h b/src/crypto/cbor.h deleted file mode 100644 index 15c7a271ad07..000000000000 --- a/src/crypto/cbor.h +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the Apache 2.0 License. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#define FMT_HEADER_ONLY -#include - -namespace ccf::cbor -{ - namespace tag - { - // https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.2 - static constexpr int64_t EPOCH_DATE_TIME = 1; - - // https://www.rfc-editor.org/rfc/rfc8152.html#section-2 - static constexpr int64_t COSE_SIGN_1 = 18; - } - - struct ValueImpl; - using Value = std::shared_ptr; - - using Signed = int64_t; - using Bytes = std::span; - using String = std::string_view; - using Simple = uint8_t; - - // https://www.iana.org/assignments/cbor-simple-values/cbor-simple-values.xhtml. - // - // To be filled further on demand, currently only those to be (likely) used. - enum SimpleValue : uint8_t - { - False = 20, - True = 21, - Null = 22, - Undefined = 23, - }; - - struct Array - { - std::vector items; - }; - - using MapItem = std::pair; - struct Map - { - std::vector items; - }; - - struct Tagged - { - uint64_t tag{0}; - Value item{nullptr}; - }; - - using Type = std::variant; - - enum class Error : uint8_t - { - UNDEFINED = 0, - DECODE_FAILED = 1, - KEY_NOT_FOUND = 2, - OUT_OF_BOUND = 3, - TYPE_MISMATCH = 4, - ENCODE_FAILED = 5, - }; - - class CBOREncodeError : public std::runtime_error - { - public: - explicit CBOREncodeError(Error err, const std::string& what); - [[nodiscard]] Error error_code() const; - - private: - Error error{Error::UNDEFINED}; - }; - - class CBORDecodeError : public std::runtime_error - { - public: - explicit CBORDecodeError(Error err, const std::string& what); - [[nodiscard]] Error error_code() const; - - private: - Error error{Error::UNDEFINED}; - }; - - struct ValueImpl - { - ValueImpl(Type value_) : value(std::move(value_)) {} - Type value; - - [[nodiscard]] const Value& array_at(size_t index) const; - [[nodiscard]] const Value& map_at(const Value& key) const; - [[nodiscard]] const Value& tag_at(uint64_t tag) const; - [[nodiscard]] Signed as_signed() const; - [[nodiscard]] Bytes as_bytes() const; - [[nodiscard]] String as_string() const; - [[nodiscard]] Simple as_simple() const; - [[nodiscard]] size_t size() const; - }; - - Value make_signed(int64_t value); - Value make_simple(SimpleValue value); - Value make_string(std::string_view data); - Value make_bytes(std::span data); - Value make_tagged(uint64_t tag, Value&& value); - Value make_array(std::vector&& data); - Value make_map(std::vector&& data); - - Value parse(std::span raw, size_t max_depth = 16); - std::vector serialize(const Value& value, size_t max_depth = 16); - - std::string to_string(const Value& value); - bool simple_to_boolean(const Simple& value); - SimpleValue boolean_to_simple(bool value); - - decltype(auto) rethrow_with_msg(auto&& f, std::string_view msg = {}) - { - try - { - return f(); - } - catch (const CBORDecodeError& err) - { - if (!msg.empty()) - { - throw CBORDecodeError( - err.error_code(), fmt::format("{}: {}", msg, err.what())); - } - throw; - } - } -} // namespace ccf::cbor \ No newline at end of file diff --git a/src/crypto/cbor_helpers.h b/src/crypto/cbor_helpers.h new file mode 100644 index 000000000000..34f8033772d6 --- /dev/null +++ b/src/crypto/cbor_helpers.h @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the Apache 2.0 License. + +#pragma once + +#include +#include +#include +#include +#include + +namespace ccf::cbor +{ + /// Copy an array, substituting one element. + /// + /// Values are immutable, so an edit rebuilds the container around the + /// elements it keeps. + inline tav::cbor::Value with_element( + const tav::cbor::Value& array, size_t index, tav::cbor::Value replacement) + { + std::vector items; + items.reserve(array.size()); + for (size_t i = 0; i < array.size(); ++i) + { + items.push_back( + i == index ? std::exchange(replacement, {}) : array.array_at(i)); + } + return tav::cbor::make_array(std::move(items)); + } + + /// Copy a map, substituting the value stored under an integer key. + inline tav::cbor::Value with_entry( + const tav::cbor::Value& map, int64_t key, tav::cbor::Value replacement) + { + std::vector entries; + entries.reserve(map.size()); + for (size_t i = 0; i < map.size(); ++i) + { + tav::cbor::Value existing = map.map_key_at(i); + const bool matches = existing.kind() == tav::cbor::Kind::SIGNED && + existing.as_signed() == key; + entries.emplace_back( + std::move(existing), + matches ? std::exchange(replacement, {}) : map.map_value_at(i)); + } + return tav::cbor::make_map(std::move(entries)); + } +} diff --git a/src/crypto/cbor_tags.h b/src/crypto/cbor_tags.h new file mode 100644 index 000000000000..a1ea735ccfd0 --- /dev/null +++ b/src/crypto/cbor_tags.h @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the Apache 2.0 License. + +#pragma once + +#include + +namespace ccf::cbor::tag +{ + // https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.2 + static constexpr int64_t EPOCH_DATE_TIME = 1; + + // https://www.rfc-editor.org/rfc/rfc8152.html#section-2 + static constexpr int64_t COSE_SIGN_1 = 18; +} diff --git a/src/crypto/cose.cpp b/src/crypto/cose.cpp index fd9879dc9b93..fccb816b9c6e 100644 --- a/src/crypto/cose.cpp +++ b/src/crypto/cose.cpp @@ -3,10 +3,11 @@ #include "ccf/crypto/cose.h" -#include "crypto/cbor.h" +#include "crypto/cbor_tags.h" #include "crypto/cose.h" #include +#include #include namespace ccf::cose::edit @@ -14,29 +15,29 @@ namespace ccf::cose::edit std::vector set_unprotected_header( const std::span& cose_input, const desc::Type& descriptor) { - using namespace ccf::cbor; + using namespace tav::cbor; - auto cose_cbor = rethrow_with_msg( - [&]() { return parse(cose_input); }, "Failed to parse COSE_Sign1"); + const Value cose_cbor = rethrow_with_msg( + [&]() { return nondet_parse(cose_input); }, "Failed to parse COSE_Sign1"); - const auto& cose_envelope = rethrow_with_msg( - [&]() -> auto& { return cose_cbor->tag_at(ccf::cbor::tag::COSE_SIGN_1); }, + const Value cose_envelope = rethrow_with_msg( + [&]() { return cose_cbor.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "Failed to parse COSE_Sign1 tag"); - const auto& phdr = rethrow_with_msg( - [&]() -> auto& { return cose_envelope->array_at(0); }, + const Value phdr = rethrow_with_msg( + [&]() { return cose_envelope.array_at(0); }, "Failed to parse COSE_Sign1 protected header"); - const auto& payload = rethrow_with_msg( - [&]() -> auto& { return cose_envelope->array_at(2); }, + const Value payload = rethrow_with_msg( + [&]() { return cose_envelope.array_at(2); }, "Failed to parse COSE_Sign1 payload"); - const auto& signature = rethrow_with_msg( - [&]() -> auto& { return cose_envelope->array_at(3); }, + const Value signature = rethrow_with_msg( + [&]() { return cose_envelope.array_at(3); }, "Failed to parse COSE_Sign1 signature"); std::vector edited; - edited.push_back(phdr); + edited.push_back(shallow_copy(phdr)); if (std::holds_alternative(descriptor)) { @@ -49,16 +50,18 @@ namespace ccf::cose::edit if (std::holds_alternative(pos)) { - std::vector items{make_bytes(value)}; + std::vector items; + items.push_back(make_bytes(value)); uhdr.emplace_back(make_signed(key), make_array(std::move(items))); } else if (std::holds_alternative(pos)) { auto subkey = std::get(pos).key; - std::vector items{make_bytes(value)}; - std::vector submap{ - {make_signed(subkey), make_array(std::move(items))}}; + std::vector items; + items.push_back(make_bytes(value)); + std::vector submap; + submap.emplace_back(make_signed(subkey), make_array(std::move(items))); uhdr.emplace_back(make_signed(key), make_map(std::move(submap))); } @@ -74,11 +77,11 @@ namespace ccf::cose::edit throw std::logic_error("Invalid COSE_Sign1 edit descriptor"); } - edited.push_back(payload); - edited.push_back(signature); + edited.push_back(shallow_copy(payload)); + edited.push_back(shallow_copy(signature)); - auto edited_envelope = + const Value edited_envelope = make_tagged(ccf::cbor::tag::COSE_SIGN_1, make_array(std::move(edited))); - return serialize(edited_envelope); + return edited_envelope.nondet_serialize(); } } \ No newline at end of file diff --git a/src/crypto/cose_utils.h b/src/crypto/cose_utils.h index 741b2e27ea2a..9fdd4dec4b31 100644 --- a/src/crypto/cose_utils.h +++ b/src/crypto/cose_utils.h @@ -3,30 +3,31 @@ #pragma once -#include "crypto/cbor.h" +#include "crypto/cbor_tags.h" + +#include namespace ccf::cose::utils { inline std::vector> parse_x5chain( - const ccf::cbor::Value& x5chain_value) + const tav::cbor::Value& x5chain_value) { std::vector> chain; // x5chain can be either an array of byte strings or a single byte string try { - for (size_t i = 0; i < x5chain_value->size(); ++i) + for (size_t i = 0; i < x5chain_value.size(); ++i) { const auto x5chain_ctx = "x5chain[" + std::to_string(i) + "]"; - const auto& bytes = ccf::cbor::rethrow_with_msg( - [&]() { return x5chain_value->array_at(i)->as_bytes(); }, - x5chain_ctx); + const auto& bytes = tav::cbor::rethrow_with_msg( + [&]() { return x5chain_value.array_at(i).as_bytes(); }, x5chain_ctx); chain.emplace_back(bytes.begin(), bytes.end()); } } - catch (const ccf::cbor::CBORDecodeError&) + catch (const tav::cbor::DecodeError&) { - auto bytes = ccf::cbor::rethrow_with_msg( - [&]() { return x5chain_value->as_bytes(); }, "x5chain"); + auto bytes = tav::cbor::rethrow_with_msg( + [&]() { return x5chain_value.as_bytes(); }, "x5chain"); chain.emplace_back(bytes.begin(), bytes.end()); } return chain; diff --git a/src/crypto/openssl/cose_verifier.cpp b/src/crypto/openssl/cose_verifier.cpp index e42d1b75caf9..5c73fc3c7446 100644 --- a/src/crypto/openssl/cose_verifier.cpp +++ b/src/crypto/openssl/cose_verifier.cpp @@ -4,10 +4,12 @@ #include "crypto/openssl/cose_verifier.h" #include "cose/cose_rs_ffi.h" +#include "crypto/cbor_helpers.h" #include "ds/internal_logger.h" -#include +#include #include +#include namespace { @@ -19,30 +21,30 @@ namespace CoseSign1Components decompose_cose_sign1(std::span envelope) { - using namespace ccf::cbor; + using namespace tav::cbor; - auto cose_cbor = - rethrow_with_msg([&]() { return parse(envelope); }, "Parse COSE CBOR"); + auto cose_cbor = rethrow_with_msg( + [&]() { return nondet_parse(envelope); }, "Parse COSE CBOR"); - const auto& cose_envelope = rethrow_with_msg( - [&]() -> auto& { return cose_cbor->tag_at(ccf::cbor::tag::COSE_SIGN_1); }, + const auto cose_envelope = rethrow_with_msg( + [&]() { return cose_cbor.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "Parse COSE tag"); auto phdr = rethrow_with_msg( - [&]() { return cose_envelope->array_at(0)->as_bytes(); }, + [&]() { return cose_envelope.array_at(0).as_bytes(); }, "Parse protected header"); std::optional> payload; { - const auto& payload_item = cose_envelope->array_at(2); + const auto& payload_item = cose_envelope.array_at(2); try { - payload = payload_item->as_bytes(); + payload = payload_item.as_bytes(); } - catch (const CBORDecodeError&) + catch (const DecodeError&) { // as_bytes() fails when payload is CBOR null (detached) - if (payload_item->as_simple() != ccf::cbor::SimpleValue::Null) + if (payload_item.as_simple() != tav::cbor::SimpleValue::Null) { throw; } @@ -50,7 +52,7 @@ namespace } auto sig = rethrow_with_msg( - [&]() { return cose_envelope->array_at(3)->as_bytes(); }, + [&]() { return cose_envelope.array_at(3).as_bytes(); }, "Parse signature"); return {phdr, payload, sig}; @@ -58,9 +60,10 @@ namespace int64_t extract_alg(std::span phdr_bytes) { - using namespace ccf::cbor; - auto phdr = parse(phdr_bytes); - return phdr->map_at(make_signed(ccf::cose::header::iana::ALG))->as_signed(); + using namespace tav::cbor; + const Value phdr = nondet_parse(phdr_bytes); + const Value alg_key = make_signed(ccf::cose::header::iana::ALG); + return phdr.map_at(alg_key).as_signed(); } CoseKey cose_key_from_pem(const ccf::crypto::Pem& pem) @@ -302,41 +305,42 @@ namespace ccf::crypto COSEEndorsementValidity extract_cose_endorsement_validity( std::span cose_msg) { - using namespace ccf::cbor; + using namespace tav::cbor; - auto cose_cbor = - rethrow_with_msg([&]() { return parse(cose_msg); }, "Parse COSE CBOR"); + auto cose_cbor = rethrow_with_msg( + [&]() { return nondet_parse(cose_msg); }, "Parse COSE CBOR"); - const auto& cose_envelope = rethrow_with_msg( - [&]() -> auto& { return cose_cbor->tag_at(ccf::cbor::tag::COSE_SIGN_1); }, + const auto cose_envelope = rethrow_with_msg( + [&]() { return cose_cbor.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "Parse COSE tag"); - const auto& phdr_raw = rethrow_with_msg( - [&]() -> auto& { return cose_envelope->array_at(0); }, + const auto phdr_raw = rethrow_with_msg( + [&]() { return cose_envelope.array_at(0); }, "Parse raw protected header"); auto phdr = rethrow_with_msg( - [&]() { return parse(phdr_raw->as_bytes()); }, "Decode protected header"); + [&]() { return nondet_parse(phdr_raw.as_bytes()); }, + "Decode protected header"); - const auto& ccf_claims = rethrow_with_msg( - [&]() -> auto& { - return phdr->map_at(make_string(ccf::cose::header::custom::CCF_V1)); + const auto ccf_claims = rethrow_with_msg( + [&]() { + return phdr.map_at(make_string(ccf::cose::header::custom::CCF_V1)); }, "Retrieve CCF claims"); auto from = rethrow_with_msg( [&]() { return ccf_claims - ->map_at(make_string(ccf::cose::header::custom::TX_RANGE_BEGIN)) - ->as_string(); + .map_at(make_string(ccf::cose::header::custom::TX_RANGE_BEGIN)) + .as_string(); }, "Retrieve epoch range begin"); auto to = rethrow_with_msg( [&]() { return ccf_claims - ->map_at(make_string(ccf::cose::header::custom::TX_RANGE_END)) - ->as_string(); + .map_at(make_string(ccf::cose::header::custom::TX_RANGE_END)) + .as_string(); }, "Retrieve epoch range end"); diff --git a/src/crypto/test/cbor.cpp b/src/crypto/test/cbor.cpp index 94c6f8c55e60..794d37cf0aa6 100644 --- a/src/crypto/test/cbor.cpp +++ b/src/crypto/test/cbor.cpp @@ -1,16 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the Apache 2.0 License. #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#include "crypto/cbor.h" - #include "ccf/ds/hex.h" +#include "crypto/cbor_helpers.h" +#include "crypto/cbor_tags.h" +#include "crypto/test/cbor_printer.h" #include #include #include +#include +#include #include -using namespace ccf::cbor; +using namespace tav::cbor; TEST_CASE("CBOR: signed integers") { @@ -36,17 +39,17 @@ TEST_CASE("CBOR: signed integers") SUBCASE(name) { auto cbor_bytes = ccf::ds::from_hex(hex); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->as_signed() == expected_value); + REQUIRE(value.as_signed() == expected_value); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE(decoded->as_signed() == expected_value); + REQUIRE(decoded.as_signed() == expected_value); - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } } @@ -56,7 +59,7 @@ TEST_CASE("CBOR: signed integer overflow") { // 9223372036854775807 + 1 = 9223372036854775808 auto cbor_bytes = ccf::ds::from_hex("1b8000000000000000"); - REQUIRE_THROWS_AS(parse(cbor_bytes), CBORDecodeError); + REQUIRE_THROWS_AS(nondet_parse(cbor_bytes), DecodeError); } TEST_CASE("CBOR: strings") @@ -76,17 +79,17 @@ TEST_CASE("CBOR: strings") SUBCASE(name) { auto cbor_bytes = ccf::ds::from_hex(hex); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->as_string() == expected_value); + REQUIRE(value.as_string() == expected_value); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE(decoded->as_string() == expected_value); + REQUIRE(decoded.as_string() == expected_value); - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } } @@ -112,27 +115,27 @@ TEST_CASE("CBOR: bytes") SUBCASE(name) { auto cbor_bytes = ccf::ds::from_hex(hex); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - auto bytes = value->as_bytes(); + auto bytes = value.as_bytes(); REQUIRE(std::equal( expected_value.begin(), expected_value.end(), bytes.begin(), bytes.end())); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - bytes = decoded->as_bytes(); + bytes = decoded.as_bytes(); REQUIRE(std::equal( expected_value.begin(), expected_value.end(), bytes.begin(), bytes.end())); - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } } @@ -156,17 +159,17 @@ TEST_CASE("CBOR: simple values") SUBCASE(name) { auto cbor_bytes = ccf::ds::from_hex(hex); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->as_simple() == expected_value); + REQUIRE(value.as_simple() == expected_value); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE(decoded->as_simple() == expected_value); + REQUIRE(decoded.as_simple() == expected_value); - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } } @@ -175,59 +178,59 @@ TEST_CASE("CBOR: simple values") TEST_CASE("CBOR: tagged value Tag(9001) with signed -42") { auto cbor_bytes = ccf::ds::from_hex("d923293829"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(9001); - REQUIRE(item->as_signed() == -42); + const auto& item = value.tag_at(9001); + REQUIRE(item.as_signed() == -42); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE_EQ(decoded->tag_at(9001)->as_signed(), -42); + REQUIRE_EQ(decoded.tag_at(9001).as_signed(), -42); const std::string expected_repr = R"(Tagged[9001]: Signed: -42)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged value Tag(9002) with string") { auto cbor_bytes = ccf::ds::from_hex("d9232a6d74616767656420737472696e67"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(9002); - REQUIRE(item->as_string() == "tagged string"); + const auto& item = value.tag_at(9002); + REQUIRE(item.as_string() == "tagged string"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE_EQ(decoded->tag_at(9002)->as_string(), "tagged string"); + REQUIRE_EQ(decoded.tag_at(9002).as_string(), "tagged string"); const std::string expected_repr = R"(Tagged[9002]: String: "tagged string")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged value Tag(9003) with bytes") { auto cbor_bytes = ccf::ds::from_hex("d9232b42cafe"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(9003); - auto bytes = item->as_bytes(); + const auto& item = value.tag_at(9003); + auto bytes = item.as_bytes(); REQUIRE(bytes.size() == 2); REQUIRE(bytes[0] == 0xca); REQUIRE(bytes[1] == 0xfe); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - auto round_trip_bytes = decoded->tag_at(9003)->as_bytes(); + auto round_trip_bytes = decoded.tag_at(9003).as_bytes(); REQUIRE(std::equal( round_trip_bytes.begin(), round_trip_bytes.end(), @@ -236,88 +239,88 @@ TEST_CASE("CBOR: tagged value Tag(9003) with bytes") const std::string expected_repr = R"(Tagged[9003]: Bytes[2]: cafe)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged value Tag(9004) with boolean") { auto cbor_bytes = ccf::ds::from_hex("d9232cf5"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(9004); - REQUIRE(item->as_simple() == SimpleValue::True); + const auto& item = value.tag_at(9004); + REQUIRE(item.as_simple() == SimpleValue::True); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE_EQ(decoded->tag_at(9004)->as_simple(), SimpleValue::True); + REQUIRE_EQ(decoded.tag_at(9004).as_simple(), SimpleValue::True); const std::string expected_repr = R"(Tagged[9004]: Simple: True)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: nested tags Tag(9010, Tag(9020))") { auto cbor_bytes = ccf::ds::from_hex("d92332d9233c666e6573746564"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& outer_item = value->tag_at(9010); - const auto& inner_item = outer_item->tag_at(9020); - REQUIRE(inner_item->as_string() == "nested"); + const auto& outer_item = value.tag_at(9010); + const auto& inner_item = outer_item.tag_at(9020); + REQUIRE(inner_item.as_string() == "nested"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE_EQ(decoded->tag_at(9010)->tag_at(9020)->as_string(), "nested"); + REQUIRE_EQ(decoded.tag_at(9010).tag_at(9020).as_string(), "nested"); const std::string expected_repr = R"(Tagged[9010]: Tagged[9020]: String: "nested")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: empty array") { auto cbor_bytes = ccf::ds::from_hex("80"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 0); + REQUIRE(value.size() == 0); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = "Array[0]:"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array [1, 2, 3, 4, 5]") { auto cbor_bytes = ccf::ds::from_hex("850102030405"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 5); + const auto& arr = value; + REQUIRE(arr.size() == 5); for (size_t i = 0; i < 5; i++) { - REQUIRE(arr.items[i]->as_signed() == i + 1); + REQUIRE(arr.array_at(i).as_signed() == i + 1); } - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); for (size_t i = 0; i < 5; i++) { - REQUIRE_EQ(decoded->array_at(i)->as_signed(), i + 1); + REQUIRE_EQ(decoded.array_at(i).as_signed(), i + 1); } const std::string expected_repr = R"(Array[5]: @@ -326,144 +329,144 @@ TEST_CASE("CBOR: array [1, 2, 3, 4, 5]") Signed: 3 Signed: 4 Signed: 5)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array [-1, -2, -3]") { auto cbor_bytes = ccf::ds::from_hex("83202122"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 3); + const auto& arr = value; + REQUIRE(arr.size() == 3); - REQUIRE(arr.items[0]->as_signed() == -1); - REQUIRE(arr.items[1]->as_signed() == -2); - REQUIRE(arr.items[2]->as_signed() == -3); + REQUIRE(arr.array_at(0).as_signed() == -1); + REQUIRE(arr.array_at(1).as_signed() == -2); + REQUIRE(arr.array_at(2).as_signed() == -3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE_EQ(decoded->array_at(0)->as_signed(), -1); - REQUIRE_EQ(decoded->array_at(1)->as_signed(), -2); - REQUIRE_EQ(decoded->array_at(2)->as_signed(), -3); + REQUIRE_EQ(decoded.array_at(0).as_signed(), -1); + REQUIRE_EQ(decoded.array_at(1).as_signed(), -2); + REQUIRE_EQ(decoded.array_at(2).as_signed(), -3); const std::string expected_repr = R"(Array[3]: Signed: -1 Signed: -2 Signed: -3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array ['a', 'b', 'c']") { auto cbor_bytes = ccf::ds::from_hex("83616161626163"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 3); + const auto& arr = value; + REQUIRE(arr.size() == 3); - REQUIRE(arr.items[0]->as_string() == "a"); - REQUIRE(arr.items[1]->as_string() == "b"); - REQUIRE(arr.items[2]->as_string() == "c"); + REQUIRE(arr.array_at(0).as_string() == "a"); + REQUIRE(arr.array_at(1).as_string() == "b"); + REQUIRE(arr.array_at(2).as_string() == "c"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE_EQ(decoded->array_at(0)->as_string(), "a"); - REQUIRE_EQ(decoded->array_at(1)->as_string(), "b"); - REQUIRE_EQ(decoded->array_at(2)->as_string(), "c"); + REQUIRE_EQ(decoded.array_at(0).as_string(), "a"); + REQUIRE_EQ(decoded.array_at(1).as_string(), "b"); + REQUIRE_EQ(decoded.array_at(2).as_string(), "c"); const std::string expected_repr = R"(Array[3]: String: "a" String: "b" String: "c")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array [b'x', b'y', b'z']") { auto cbor_bytes = ccf::ds::from_hex("8341784179417a"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 3); + const auto& arr = value; + REQUIRE(arr.size() == 3); - auto bytes0 = arr.items[0]->as_bytes(); + auto bytes0 = arr.array_at(0).as_bytes(); REQUIRE(bytes0.size() == 1); REQUIRE(bytes0[0] == 'x'); - auto bytes1 = arr.items[1]->as_bytes(); + auto bytes1 = arr.array_at(1).as_bytes(); REQUIRE(bytes1.size() == 1); REQUIRE(bytes1[0] == 'y'); - auto bytes2 = arr.items[2]->as_bytes(); + auto bytes2 = arr.array_at(2).as_bytes(); REQUIRE(bytes2.size() == 1); REQUIRE(bytes2[0] == 'z'); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[3]: Bytes[1]: 78 Bytes[1]: 79 Bytes[1]: 7a)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array [True, False, None]") { auto cbor_bytes = ccf::ds::from_hex("83f5f4f6"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 3); + const auto& arr = value; + REQUIRE(arr.size() == 3); - REQUIRE(arr.items[0]->as_simple() == SimpleValue::True); - REQUIRE(arr.items[1]->as_simple() == SimpleValue::False); - REQUIRE(arr.items[2]->as_simple() == SimpleValue::Null); + REQUIRE(arr.array_at(0).as_simple() == SimpleValue::True); + REQUIRE(arr.array_at(1).as_simple() == SimpleValue::False); + REQUIRE(arr.array_at(2).as_simple() == SimpleValue::Null); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[3]: Simple: True Simple: False Simple: Null)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array [1, 'two', b'3', True, None]") { auto cbor_bytes = ccf::ds::from_hex("85016374776f4133f5f6"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 5); + const auto& arr = value; + REQUIRE(arr.size() == 5); - REQUIRE(arr.items[0]->as_signed() == 1); + REQUIRE(arr.array_at(0).as_signed() == 1); - REQUIRE(arr.items[1]->as_string() == "two"); + REQUIRE(arr.array_at(1).as_string() == "two"); - auto bytes = arr.items[2]->as_bytes(); + auto bytes = arr.array_at(2).as_bytes(); REQUIRE(bytes.size() == 1); REQUIRE(bytes[0] == '3'); - REQUIRE(arr.items[3]->as_simple() == SimpleValue::True); + REQUIRE(arr.array_at(3).as_simple() == SimpleValue::True); - REQUIRE(arr.items[4]->as_simple() == SimpleValue::Null); + REQUIRE(arr.array_at(4).as_simple() == SimpleValue::Null); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[5]: @@ -472,30 +475,30 @@ TEST_CASE("CBOR: array [1, 'two', b'3', True, None]") Bytes[1]: 33 Simple: True Simple: Null)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array [0, -1, 42, -100, 65535]") { auto cbor_bytes = ccf::ds::from_hex("850020182a386319ffff"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 5); + const auto& arr = value; + REQUIRE(arr.size() == 5); - REQUIRE(arr.items[0]->as_signed() == 0); + REQUIRE(arr.array_at(0).as_signed() == 0); - REQUIRE(arr.items[1]->as_signed() == -1); + REQUIRE(arr.array_at(1).as_signed() == -1); - REQUIRE(arr.items[2]->as_signed() == 42); + REQUIRE(arr.array_at(2).as_signed() == 42); - REQUIRE(arr.items[3]->as_signed() == -100); + REQUIRE(arr.array_at(3).as_signed() == -100); - REQUIRE(arr.items[4]->as_signed() == 65535); + REQUIRE(arr.array_at(4).as_signed() == 65535); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[5]: @@ -504,29 +507,29 @@ TEST_CASE("CBOR: array [0, -1, 42, -100, 65535]") Signed: 42 Signed: -100 Signed: 65535)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: nested array [[1, 2], [3, 4], [5, 6]]") { auto cbor_bytes = ccf::ds::from_hex("83820102820304820506"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 3); + const auto& arr = value; + REQUIRE(arr.size() == 3); for (size_t i = 0; i < 3; i++) { - const auto& inner = std::get(arr.items[i]->value); - REQUIRE(inner.items.size() == 2); + const auto inner = arr.array_at(i); + REQUIRE(inner.size() == 2); - REQUIRE(inner.items[0]->as_signed() == i * 2 + 1); - REQUIRE(inner.items[1]->as_signed() == i * 2 + 2); + REQUIRE(inner.array_at(0).as_signed() == i * 2 + 1); + REQUIRE(inner.array_at(1).as_signed() == i * 2 + 2); } - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[3]: @@ -539,35 +542,35 @@ TEST_CASE("CBOR: nested array [[1, 2], [3, 4], [5, 6]]") Array[2]: Signed: 5 Signed: 6)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: deeply nested array [1, [2, 3], 4, [5, [6, 7]]]") { auto cbor_bytes = ccf::ds::from_hex("8401820203048205820607"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& arr = std::get(value->value); - REQUIRE(arr.items.size() == 4); + const auto& arr = value; + REQUIRE(arr.size() == 4); - REQUIRE(arr.items[0]->as_signed() == 1); + REQUIRE(arr.array_at(0).as_signed() == 1); - const auto& arr1 = std::get(arr.items[1]->value); - REQUIRE(arr1.items.size() == 2); - REQUIRE(arr1.items[0]->as_signed() == 2); - REQUIRE(arr1.items[1]->as_signed() == 3); + const auto arr1 = arr.array_at(1); + REQUIRE(arr1.size() == 2); + REQUIRE(arr1.array_at(0).as_signed() == 2); + REQUIRE(arr1.array_at(1).as_signed() == 3); - REQUIRE(arr.items[2]->as_signed() == 4); + REQUIRE(arr.array_at(2).as_signed() == 4); - const auto& arr3 = std::get(arr.items[3]->value); - REQUIRE(arr3.items.size() == 2); - REQUIRE(arr3.items[0]->as_signed() == 5); + const auto arr3 = arr.array_at(3); + REQUIRE(arr3.size() == 2); + REQUIRE(arr3.array_at(0).as_signed() == 5); - const auto& arr3_1 = std::get(arr3.items[1]->value); - REQUIRE(arr3_1.items.size() == 2); - REQUIRE(arr3_1.items[0]->as_signed() == 6); - REQUIRE(arr3_1.items[1]->as_signed() == 7); + const auto arr3_1 = arr3.array_at(1); + REQUIRE(arr3_1.size() == 2); + REQUIRE(arr3_1.array_at(0).as_signed() == 6); + REQUIRE(arr3_1.array_at(1).as_signed() == 7); const std::string expected_repr = R"(Array[4]: Signed: 1 @@ -580,24 +583,24 @@ TEST_CASE("CBOR: deeply nested array [1, [2, 3], 4, [5, [6, 7]]]") Array[2]: Signed: 6 Signed: 7)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged array Tag(9100) with [1, 2, 3]") { auto cbor_bytes = ccf::ds::from_hex("d9238c83010203"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(9100); - const auto& arr = std::get(item->value); - REQUIRE(arr.items.size() == 3); - REQUIRE(arr.items[0]->as_signed() == 1); - REQUIRE(arr.items[1]->as_signed() == 2); - REQUIRE(arr.items[2]->as_signed() == 3); + const auto& item = value.tag_at(9100); + const auto& arr = item; + REQUIRE(arr.size() == 3); + REQUIRE(arr.array_at(0).as_signed() == 1); + REQUIRE(arr.array_at(1).as_signed() == 2); + REQUIRE(arr.array_at(2).as_signed() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Tagged[9100]: @@ -605,68 +608,68 @@ TEST_CASE("CBOR: tagged array Tag(9100) with [1, 2, 3]") Signed: 1 Signed: 2 Signed: 3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged empty array Tag(9300) with []") { auto cbor_bytes = ccf::ds::from_hex("d9245480"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(9300); - const auto& arr = std::get(item->value); - REQUIRE(arr.items.size() == 0); + const auto& item = value.tag_at(9300); + const auto& arr = item; + REQUIRE(arr.size() == 0); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - const auto& array = decoded->tag_at(9300); - REQUIRE_THROWS_AS((void)array->array_at(0), CBORDecodeError); + const auto& array = decoded.tag_at(9300); + REQUIRE_THROWS_AS((void)array.array_at(0), DecodeError); const std::string expected_repr = R"(Tagged[9300]: Array[0]:)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: empty map") { auto cbor_bytes = ccf::ds::from_hex("a0"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 0); + REQUIRE(value.size() == 0); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = "Map[0]:"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {1: 'one', 2: 'two', 3: 'three'}") { auto cbor_bytes = ccf::ds::from_hex("a301636f6e65026374776f03657468726565"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - REQUIRE(value->map_at(make_signed(1))->as_string() == "one"); - REQUIRE(value->map_at(make_signed(2))->as_string() == "two"); - REQUIRE(value->map_at(make_signed(3))->as_string() == "three"); + REQUIRE(value.map_at(make_signed(1)).as_string() == "one"); + REQUIRE(value.map_at(make_signed(2)).as_string() == "two"); + REQUIRE(value.map_at(make_signed(3)).as_string() == "three"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); for (size_t i = 0; i < 3; i++) { REQUIRE_EQ( - decoded->map_at(make_signed(i + 1))->as_string(), - value->map_at(make_signed(i + 1))->as_string()); + decoded.map_at(make_signed(i + 1)).as_string(), + value.map_at(make_signed(i + 1)).as_string()); } const std::string expected_repr = R"(Map[3]: @@ -682,23 +685,23 @@ TEST_CASE("CBOR: map {1: 'one', 2: 'two', 3: 'three'}") Signed: 3 Value: String: "three")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {0: 100, 1: 200, 2: 300}") { auto cbor_bytes = ccf::ds::from_hex("a30018640118c80219012c"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - REQUIRE(value->map_at(make_signed(0))->as_signed() == 100); - REQUIRE(value->map_at(make_signed(1))->as_signed() == 200); - REQUIRE(value->map_at(make_signed(2))->as_signed() == 300); + REQUIRE(value.map_at(make_signed(0)).as_signed() == 100); + REQUIRE(value.map_at(make_signed(1)).as_signed() == 200); + REQUIRE(value.map_at(make_signed(2)).as_signed() == 300); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[3]: @@ -714,27 +717,27 @@ TEST_CASE("CBOR: map {0: 100, 1: 200, 2: 300}") Signed: 2 Value: Signed: 300)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {'a': 1, 'b': 2, 'c': 3}") { auto cbor_bytes = ccf::ds::from_hex("a3616101616202616303"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& map = std::get(value->value); - REQUIRE(map.items.size() == 3); + const auto& map = value; + REQUIRE(map.size() == 3); - REQUIRE(map.items[0].first->as_string() == "a"); - REQUIRE(map.items[0].second->as_signed() == 1); - REQUIRE(map.items[1].first->as_string() == "b"); - REQUIRE(map.items[1].second->as_signed() == 2); - REQUIRE(map.items[2].first->as_string() == "c"); - REQUIRE(map.items[2].second->as_signed() == 3); + REQUIRE(map.map_key_at(0).as_string() == "a"); + REQUIRE(map.map_value_at(0).as_signed() == 1); + REQUIRE(map.map_key_at(1).as_string() == "b"); + REQUIRE(map.map_value_at(1).as_signed() == 2); + REQUIRE(map.map_key_at(2).as_string() == "c"); + REQUIRE(map.map_value_at(2).as_signed() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[3]: @@ -750,25 +753,25 @@ TEST_CASE("CBOR: map {'a': 1, 'b': 2, 'c': 3}") String: "c" Value: Signed: 3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {'x': 'y', 'foo': 'bar'}") { auto cbor_bytes = ccf::ds::from_hex("a26178617963666f6f63626172"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& map = std::get(value->value); - REQUIRE(map.items.size() == 2); + const auto& map = value; + REQUIRE(map.size() == 2); - REQUIRE(map.items[0].first->as_string() == "x"); - REQUIRE(map.items[0].second->as_string() == "y"); - REQUIRE(map.items[1].first->as_string() == "foo"); - REQUIRE(map.items[1].second->as_string() == "bar"); + REQUIRE(map.map_key_at(0).as_string() == "x"); + REQUIRE(map.map_value_at(0).as_string() == "y"); + REQUIRE(map.map_key_at(1).as_string() == "foo"); + REQUIRE(map.map_value_at(1).as_string() == "bar"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[2]: @@ -780,7 +783,7 @@ TEST_CASE("CBOR: map {'x': 'y', 'foo': 'bar'}") String: "foo" Value: String: "bar")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -788,21 +791,21 @@ TEST_CASE("CBOR: map {'enabled': True, 'disabled': False, 'unknown': None}") { auto cbor_bytes = ccf::ds::from_hex( "a367656e61626c6564f56864697361626c6564f467756e6b6e6f776ef6"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& map = std::get(value->value); - REQUIRE(map.items.size() == 3); + const auto& map = value; + REQUIRE(map.size() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); - REQUIRE(map.items[0].first->as_string() == "enabled"); - REQUIRE(map.items[0].second->as_simple() == SimpleValue::True); - REQUIRE(map.items[1].first->as_string() == "disabled"); - REQUIRE(map.items[1].second->as_simple() == SimpleValue::False); - REQUIRE(map.items[2].first->as_string() == "unknown"); - REQUIRE(map.items[2].second->as_simple() == SimpleValue::Null); + REQUIRE(map.map_key_at(0).as_string() == "enabled"); + REQUIRE(map.map_value_at(0).as_simple() == SimpleValue::True); + REQUIRE(map.map_key_at(1).as_string() == "disabled"); + REQUIRE(map.map_value_at(1).as_simple() == SimpleValue::False); + REQUIRE(map.map_key_at(2).as_string() == "unknown"); + REQUIRE(map.map_value_at(2).as_simple() == SimpleValue::Null); const std::string expected_repr = R"(Map[3]: Key: @@ -817,7 +820,7 @@ TEST_CASE("CBOR: map {'enabled': True, 'disabled': False, 'unknown': None}") String: "unknown" Value: Simple: Null)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -825,15 +828,15 @@ TEST_CASE("CBOR: map {-1: 'minus one', -10: 'minus ten'}") { auto cbor_bytes = ccf::ds::from_hex("a220696d696e7573206f6e6529696d696e75732074656e"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 2); + REQUIRE(value.size() == 2); - REQUIRE(value->map_at(make_signed(-1))->as_string() == "minus one"); - REQUIRE(value->map_at(make_signed(-10))->as_string() == "minus ten"); + REQUIRE(value.map_at(make_signed(-1)).as_string() == "minus one"); + REQUIRE(value.map_at(make_signed(-10)).as_string() == "minus ten"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[2]: @@ -845,27 +848,27 @@ TEST_CASE("CBOR: map {-1: 'minus one', -10: 'minus ten'}") Signed: -10 Value: String: "minus ten")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array with map [1, {'a': 2}, 3]") { auto cbor_bytes = ccf::ds::from_hex("8301a161610203"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - REQUIRE(value->array_at(0)->as_signed() == 1); + REQUIRE(value.array_at(0).as_signed() == 1); - const auto& map = value->array_at(1); - REQUIRE(map->size() == 1); - REQUIRE(map->map_at(make_string("a"))->as_signed() == 2); + const auto& map = value.array_at(1); + REQUIRE(map.size() == 1); + REQUIRE(map.map_at(make_string("a")).as_signed() == 2); - REQUIRE(value->array_at(2)->as_signed() == 3); + REQUIRE(value.array_at(2).as_signed() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[3]: @@ -876,28 +879,28 @@ TEST_CASE("CBOR: array with map [1, {'a': 2}, 3]") Value: Signed: 2 Signed: 3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array of maps [{'x': 1}, {'y': 2}, {'z': 3}]") { auto cbor_bytes = ccf::ds::from_hex("83a1617801a1617902a1617a03"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - REQUIRE(value->array_at(0)->size() == 1); - REQUIRE(value->array_at(0)->map_at(make_string("x"))->as_signed() == 1); + REQUIRE(value.array_at(0).size() == 1); + REQUIRE(value.array_at(0).map_at(make_string("x")).as_signed() == 1); - REQUIRE(value->array_at(1)->size() == 1); - REQUIRE(value->array_at(1)->map_at(make_string("y"))->as_signed() == 2); + REQUIRE(value.array_at(1).size() == 1); + REQUIRE(value.array_at(1).map_at(make_string("y")).as_signed() == 2); - REQUIRE(value->array_at(2)->size() == 1); - REQUIRE(value->array_at(2)->map_at(make_string("z"))->as_signed() == 3); + REQUIRE(value.array_at(2).size() == 1); + REQUIRE(value.array_at(2).map_at(make_string("z")).as_signed() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[3]: @@ -916,25 +919,25 @@ TEST_CASE("CBOR: array of maps [{'x': 1}, {'y': 2}, {'z': 3}]") String: "z" Value: Signed: 3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map with array {'items': [1, 2, 3]}") { auto cbor_bytes = ccf::ds::from_hex("a1656974656d7383010203"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 1); + REQUIRE(value.size() == 1); - const auto& arr = value->map_at(make_string("items")); - REQUIRE(arr->size() == 3); - REQUIRE(arr->array_at(0)->as_signed() == 1); - REQUIRE(arr->array_at(1)->as_signed() == 2); - REQUIRE(arr->array_at(2)->as_signed() == 3); + const auto& arr = value.map_at(make_string("items")); + REQUIRE(arr.size() == 3); + REQUIRE(arr.array_at(0).as_signed() == 1); + REQUIRE(arr.array_at(1).as_signed() == 2); + REQUIRE(arr.array_at(2).as_signed() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[1]: @@ -945,34 +948,34 @@ TEST_CASE("CBOR: map with array {'items': [1, 2, 3]}") Signed: 1 Signed: 2 Signed: 3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map with multiple arrays") { auto cbor_bytes = ccf::ds::from_hex("a3616182010261628203046163820506"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - const auto& arr_a = value->map_at(make_string("a")); - REQUIRE(arr_a->size() == 2); - REQUIRE(arr_a->array_at(0)->as_signed() == 1); - REQUIRE(arr_a->array_at(1)->as_signed() == 2); + const auto& arr_a = value.map_at(make_string("a")); + REQUIRE(arr_a.size() == 2); + REQUIRE(arr_a.array_at(0).as_signed() == 1); + REQUIRE(arr_a.array_at(1).as_signed() == 2); - const auto& arr_b = value->map_at(make_string("b")); - REQUIRE(arr_b->size() == 2); - REQUIRE(arr_b->array_at(0)->as_signed() == 3); - REQUIRE(arr_b->array_at(1)->as_signed() == 4); + const auto& arr_b = value.map_at(make_string("b")); + REQUIRE(arr_b.size() == 2); + REQUIRE(arr_b.array_at(0).as_signed() == 3); + REQUIRE(arr_b.array_at(1).as_signed() == 4); - const auto& arr_c = value->map_at(make_string("c")); - REQUIRE(arr_c->size() == 2); - REQUIRE(arr_c->array_at(0)->as_signed() == 5); - REQUIRE(arr_c->array_at(1)->as_signed() == 6); + const auto& arr_c = value.map_at(make_string("c")); + REQUIRE(arr_c.size() == 2); + REQUIRE(arr_c.array_at(0).as_signed() == 5); + REQUIRE(arr_c.array_at(1).as_signed() == 6); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[3]: @@ -994,22 +997,22 @@ TEST_CASE("CBOR: map with multiple arrays") Array[2]: Signed: 5 Signed: 6)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged map Tag(10000) with {'a': 1, 'b': 2}") { auto cbor_bytes = ccf::ds::from_hex("d92710a2616101616202"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(10000); - REQUIRE(item->size() == 2); - REQUIRE(item->map_at(make_string("a"))->as_signed() == 1); - REQUIRE(item->map_at(make_string("b"))->as_signed() == 2); + const auto& item = value.tag_at(10000); + REQUIRE(item.size() == 2); + REQUIRE(item.map_at(make_string("a")).as_signed() == 1); + REQUIRE(item.map_at(make_string("b")).as_signed() == 2); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Tagged[10000]: @@ -1022,7 +1025,7 @@ TEST_CASE("CBOR: tagged map Tag(10000) with {'a': 1, 'b': 2}") String: "b" Value: Signed: 2)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -1031,22 +1034,22 @@ TEST_CASE( { auto cbor_bytes = ccf::ds::from_hex( "83f5a365636f756e74182a656c6162656c656974656d7366616374697665f5f6"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - REQUIRE(value->array_at(0)->as_simple() == SimpleValue::True); + REQUIRE(value.array_at(0).as_simple() == SimpleValue::True); - const auto& map = value->array_at(1); - REQUIRE(map->size() == 3); - REQUIRE(map->map_at(make_string("count"))->as_signed() == 42); - REQUIRE(map->map_at(make_string("label"))->as_string() == "items"); - REQUIRE(map->map_at(make_string("active"))->as_simple() == SimpleValue::True); + const auto& map = value.array_at(1); + REQUIRE(map.size() == 3); + REQUIRE(map.map_at(make_string("count")).as_signed() == 42); + REQUIRE(map.map_at(make_string("label")).as_string() == "items"); + REQUIRE(map.map_at(make_string("active")).as_simple() == SimpleValue::True); - REQUIRE(value->array_at(2)->as_simple() == SimpleValue::Null); + REQUIRE(value.array_at(2).as_simple() == SimpleValue::Null); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[3]: @@ -1065,7 +1068,7 @@ TEST_CASE( Value: Simple: True Simple: Null)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -1073,21 +1076,21 @@ TEST_CASE("CBOR: array ['header', {'id': 123, 'name': 'test'}, 'footer']") { auto cbor_bytes = ccf::ds::from_hex( "8366686561646572a2626964187b646e616d65647465737466666f6f746572"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - REQUIRE(value->array_at(0)->as_string() == "header"); + REQUIRE(value.array_at(0).as_string() == "header"); - const auto& map = value->array_at(1); - REQUIRE(map->size() == 2); - REQUIRE(map->map_at(make_string("id"))->as_signed() == 123); - REQUIRE(map->map_at(make_string("name"))->as_string() == "test"); + const auto& map = value.array_at(1); + REQUIRE(map.size() == 2); + REQUIRE(map.map_at(make_string("id")).as_signed() == 123); + REQUIRE(map.map_at(make_string("name")).as_string() == "test"); - REQUIRE(value->array_at(2)->as_string() == "footer"); + REQUIRE(value.array_at(2).as_string() == "footer"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[3]: @@ -1102,7 +1105,7 @@ TEST_CASE("CBOR: array ['header', {'id': 123, 'name': 'test'}, 'footer']") Value: String: "test" String: "footer")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -1110,24 +1113,24 @@ TEST_CASE("CBOR: array [1, 2, {'nested': {'key': 'value'}}, 3]") { auto cbor_bytes = ccf::ds::from_hex("840102a1666e6573746564a1636b65796576616c756503"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 4); + REQUIRE(value.size() == 4); - REQUIRE(value->array_at(0)->as_signed() == 1); - REQUIRE(value->array_at(1)->as_signed() == 2); + REQUIRE(value.array_at(0).as_signed() == 1); + REQUIRE(value.array_at(1).as_signed() == 2); - const auto& map = value->array_at(2); - REQUIRE(map->size() == 1); + const auto& map = value.array_at(2); + REQUIRE(map.size() == 1); - const auto& nested_map = map->map_at(make_string("nested")); - REQUIRE(nested_map->size() == 1); - REQUIRE(nested_map->map_at(make_string("key"))->as_string() == "value"); + const auto& nested_map = map.map_at(make_string("nested")); + REQUIRE(nested_map.size() == 1); + REQUIRE(nested_map.map_at(make_string("key")).as_string() == "value"); - REQUIRE(value->array_at(3)->as_signed() == 3); + REQUIRE(value.array_at(3).as_signed() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[4]: @@ -1143,26 +1146,26 @@ TEST_CASE("CBOR: array [1, 2, {'nested': {'key': 'value'}}, 3]") Value: String: "value" Signed: 3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: array [1, Tag(9600, 'tagged'), 3]") { auto cbor_bytes = ccf::ds::from_hex("8301d925806674616767656403"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - REQUIRE(value->array_at(0)->as_signed() == 1); + REQUIRE(value.array_at(0).as_signed() == 1); - const auto& item = value->array_at(1)->tag_at(9600); - REQUIRE(item->as_string() == "tagged"); + const auto& item = value.array_at(1).tag_at(9600); + REQUIRE(item.as_string() == "tagged"); - REQUIRE(value->array_at(2)->as_signed() == 3); + REQUIRE(value.array_at(2).as_signed() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Array[3]: @@ -1170,48 +1173,47 @@ TEST_CASE("CBOR: array [1, Tag(9600, 'tagged'), 3]") Tagged[9600]: String: "tagged" Signed: 3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: large bytes array (16 bytes)") { auto cbor_bytes = ccf::ds::from_hex("50000102030405060708090a0b0c0d0e0f"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - auto bytes = value->as_bytes(); + auto bytes = value.as_bytes(); REQUIRE(bytes.size() == 16); for (size_t i = 0; i < 16; i++) { REQUIRE(bytes[i] == static_cast(i)); } - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = "Bytes[16]: 000102030405060708090a0b0c0d0e0f"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map with mixed key types") { auto cbor_bytes = ccf::ds::from_hex("a301636e756d6373747202456279746573f5"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - REQUIRE(value->map_at(make_signed(1))->as_string() == "num"); - REQUIRE(value->map_at(make_string("str"))->as_signed() == 2); + REQUIRE(value.map_at(make_signed(1)).as_string() == "num"); + REQUIRE(value.map_at(make_string("str")).as_signed() == 2); const auto bytes_key = ccf::ds::from_hex("6279746573"); - REQUIRE( - value->map_at(make_bytes(bytes_key))->as_simple() == SimpleValue::True); + REQUIRE(value.map_at(make_bytes(bytes_key)).as_simple() == SimpleValue::True); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[3]: @@ -1227,28 +1229,28 @@ TEST_CASE("CBOR: map with mixed key types") Bytes[5]: 6279746573 Value: Simple: True)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {'a': 1, 'b': 'two', 'c': b'3', 'd': False}") { auto cbor_bytes = ccf::ds::from_hex("a461610161626374776f616341336164f4"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 4); + REQUIRE(value.size() == 4); - REQUIRE(value->map_at(make_string("a"))->as_signed() == 1); - REQUIRE(value->map_at(make_string("b"))->as_string() == "two"); + REQUIRE(value.map_at(make_string("a")).as_signed() == 1); + REQUIRE(value.map_at(make_string("b")).as_string() == "two"); - const auto byte_value = value->map_at(make_string("c"))->as_bytes(); + const auto byte_value = value.map_at(make_string("c")).as_bytes(); REQUIRE(byte_value.size() == 1); REQUIRE(byte_value[0] == 0x33); - REQUIRE(value->map_at(make_string("d"))->as_simple() == SimpleValue::False); + REQUIRE(value.map_at(make_string("d")).as_simple() == SimpleValue::False); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[4]: @@ -1268,7 +1270,7 @@ TEST_CASE("CBOR: map {'a': 1, 'b': 'two', 'c': b'3', 'd': False}") String: "d" Value: Simple: False)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -1276,18 +1278,18 @@ TEST_CASE("CBOR: map {'key1': b'value1', 'key2': b'value2'}") { auto cbor_bytes = ccf::ds::from_hex("a2646b6579314676616c756531646b6579324676616c756532"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 2); + REQUIRE(value.size() == 2); - const auto value1 = value->map_at(make_string("key1"))->as_bytes(); + const auto value1 = value.map_at(make_string("key1")).as_bytes(); REQUIRE(value1.size() == 6); - const auto value2 = value->map_at(make_string("key2"))->as_bytes(); + const auto value2 = value.map_at(make_string("key2")).as_bytes(); REQUIRE(value2.size() == 6); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[2]: @@ -1299,34 +1301,34 @@ TEST_CASE("CBOR: map {'key1': b'value1', 'key2': b'value2'}") String: "key2" Value: Bytes[6]: 76616c756532)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {1: [10, 20], 2: ['a', 'b'], 3: [b'x', b'y']}") { auto cbor_bytes = ccf::ds::from_hex("a301820a14028261616162038241784179"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - const auto& arr0 = value->map_at(make_signed(1)); - REQUIRE(arr0->size() == 2); - REQUIRE(arr0->array_at(0)->as_signed() == 10); - REQUIRE(arr0->array_at(1)->as_signed() == 20); + const auto& arr0 = value.map_at(make_signed(1)); + REQUIRE(arr0.size() == 2); + REQUIRE(arr0.array_at(0).as_signed() == 10); + REQUIRE(arr0.array_at(1).as_signed() == 20); - const auto& arr1 = value->map_at(make_signed(2)); - REQUIRE(arr1->size() == 2); - REQUIRE(arr1->array_at(0)->as_string() == "a"); - REQUIRE(arr1->array_at(1)->as_string() == "b"); + const auto& arr1 = value.map_at(make_signed(2)); + REQUIRE(arr1.size() == 2); + REQUIRE(arr1.array_at(0).as_string() == "a"); + REQUIRE(arr1.array_at(1).as_string() == "b"); - const auto& arr2 = value->map_at(make_signed(3)); - REQUIRE(arr2->size() == 2); - REQUIRE(arr2->array_at(0)->as_bytes()[0] == 'x'); - REQUIRE(arr2->array_at(1)->as_bytes()[0] == 'y'); + const auto& arr2 = value.map_at(make_signed(3)); + REQUIRE(arr2.size() == 2); + REQUIRE(arr2.array_at(0).as_bytes()[0] == 'x'); + REQUIRE(arr2.array_at(1).as_bytes()[0] == 'y'); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[3]: @@ -1348,25 +1350,25 @@ TEST_CASE("CBOR: map {1: [10, 20], 2: ['a', 'b'], 3: [b'x', b'y']}") Array[2]: Bytes[1]: 78 Bytes[1]: 79)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {1: b'data1', 2: b'data2'}") { auto cbor_bytes = ccf::ds::from_hex("a20145646174613102456461746132"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 2); + REQUIRE(value.size() == 2); - const auto data1 = value->map_at(make_signed(1))->as_bytes(); + const auto data1 = value.map_at(make_signed(1)).as_bytes(); REQUIRE(data1.size() == 5); - const auto data2 = value->map_at(make_signed(2))->as_bytes(); + const auto data2 = value.map_at(make_signed(2)).as_bytes(); REQUIRE(data2.size() == 5); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[2]: @@ -1378,31 +1380,31 @@ TEST_CASE("CBOR: map {1: b'data1', 2: b'data2'}") Signed: 2 Value: Bytes[5]: 6461746132)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {'nested': [1, [2, 3], 4]}") { auto cbor_bytes = ccf::ds::from_hex("a1666e6573746564830182020304"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 1); + REQUIRE(value.size() == 1); - const auto& arr = value->map_at(make_string("nested")); - REQUIRE(arr->size() == 3); + const auto& arr = value.map_at(make_string("nested")); + REQUIRE(arr.size() == 3); - REQUIRE(arr->array_at(0)->as_signed() == 1); + REQUIRE(arr.array_at(0).as_signed() == 1); - const auto& nested = arr->array_at(1); - REQUIRE(nested->size() == 2); - REQUIRE(nested->array_at(0)->as_signed() == 2); - REQUIRE(nested->array_at(1)->as_signed() == 3); + const auto& nested = arr.array_at(1); + REQUIRE(nested.size() == 2); + REQUIRE(nested.array_at(0).as_signed() == 2); + REQUIRE(nested.array_at(1).as_signed() == 3); - REQUIRE(arr->array_at(2)->as_signed() == 4); + REQUIRE(arr.array_at(2).as_signed() == 4); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[1]: @@ -1415,23 +1417,23 @@ TEST_CASE("CBOR: map {'nested': [1, [2, 3], 4]}") Signed: 2 Signed: 3 Signed: 4)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: map {'tagged': Tag(9500, 'value')}") { auto cbor_bytes = ccf::ds::from_hex("a166746167676564d9251c6576616c7565"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 1); + REQUIRE(value.size() == 1); - const auto& tagged_value = value->map_at(make_string("tagged")); - const auto& item = tagged_value->tag_at(9500); - REQUIRE(item->as_string() == "value"); + const auto& tagged_value = value.map_at(make_string("tagged")); + const auto& item = tagged_value.tag_at(9500); + REQUIRE(item.as_string() == "value"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[1]: @@ -1440,7 +1442,7 @@ TEST_CASE("CBOR: map {'tagged': Tag(9500, 'value')}") Value: Tagged[9500]: String: "value")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -1450,28 +1452,28 @@ TEST_CASE( { auto cbor_bytes = ccf::ds::from_hex( "a3676e756d626572738301020367737472696e6773826161616265666c61677382f5f4"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - const auto& nums = value->map_at(make_string("numbers")); - REQUIRE(nums->size() == 3); - REQUIRE(nums->array_at(0)->as_signed() == 1); - REQUIRE(nums->array_at(1)->as_signed() == 2); - REQUIRE(nums->array_at(2)->as_signed() == 3); + const auto& nums = value.map_at(make_string("numbers")); + REQUIRE(nums.size() == 3); + REQUIRE(nums.array_at(0).as_signed() == 1); + REQUIRE(nums.array_at(1).as_signed() == 2); + REQUIRE(nums.array_at(2).as_signed() == 3); - const auto& strs = value->map_at(make_string("strings")); - REQUIRE(strs->size() == 2); - REQUIRE(strs->array_at(0)->as_string() == "a"); - REQUIRE(strs->array_at(1)->as_string() == "b"); + const auto& strs = value.map_at(make_string("strings")); + REQUIRE(strs.size() == 2); + REQUIRE(strs.array_at(0).as_string() == "a"); + REQUIRE(strs.array_at(1).as_string() == "b"); - const auto& flags = value->map_at(make_string("flags")); - REQUIRE(flags->size() == 2); - REQUIRE(flags->array_at(0)->as_simple() == SimpleValue::True); - REQUIRE(flags->array_at(1)->as_simple() == SimpleValue::False); + const auto& flags = value.map_at(make_string("flags")); + REQUIRE(flags.size() == 2); + REQUIRE(flags.array_at(0).as_simple() == SimpleValue::True); + REQUIRE(flags.array_at(1).as_simple() == SimpleValue::False); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[3]: @@ -1494,7 +1496,7 @@ TEST_CASE( Array[2]: Simple: True Simple: False)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -1502,25 +1504,25 @@ TEST_CASE("CBOR: map {'empty': [], 'single': [42], 'multiple': [1, 2, 3]}") { auto cbor_bytes = ccf::ds::from_hex( "a365656d707479806673696e676c6581182a686d756c7469706c6583010203"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE(value->size() == 3); + REQUIRE(value.size() == 3); - const auto& empty = value->map_at(make_string("empty")); - REQUIRE(empty->size() == 0); + const auto& empty = value.map_at(make_string("empty")); + REQUIRE(empty.size() == 0); - const auto& single = value->map_at(make_string("single")); - REQUIRE(single->size() == 1); - REQUIRE(single->array_at(0)->as_signed() == 42); + const auto& single = value.map_at(make_string("single")); + REQUIRE(single.size() == 1); + REQUIRE(single.array_at(0).as_signed() == 42); - const auto& multiple = value->map_at(make_string("multiple")); - REQUIRE(multiple->size() == 3); - REQUIRE(multiple->array_at(0)->as_signed() == 1); - REQUIRE(multiple->array_at(1)->as_signed() == 2); - REQUIRE(multiple->array_at(2)->as_signed() == 3); + const auto& multiple = value.map_at(make_string("multiple")); + REQUIRE(multiple.size() == 3); + REQUIRE(multiple.array_at(0).as_signed() == 1); + REQUIRE(multiple.array_at(1).as_signed() == 2); + REQUIRE(multiple.array_at(2).as_signed() == 3); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Map[3]: @@ -1540,7 +1542,7 @@ TEST_CASE("CBOR: map {'empty': [], 'single': [42], 'multiple': [1, 2, 3]}") Signed: 1 Signed: 2 Signed: 3)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } @@ -1550,38 +1552,38 @@ TEST_CASE("CBOR: large string (100 'A's)") "786441414141414141414141414141414141414141414141414141414141414141414141" "41414141414141414141414141414141414141414141414141414141414141414141414141" "4141414141414141414141414141414141414141414141414141414141"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - auto str = value->as_string(); + auto str = value.as_string(); REQUIRE(str.size() == 100); for (size_t i = 0; i < 100; i++) { REQUIRE(str[i] == 'A'); } - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(String: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged array Tag(9200, ['a', 'b', 'c'])") { auto cbor_bytes = ccf::ds::from_hex("d923f083616161626163"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(9200); - REQUIRE(item->size() == 3); - REQUIRE(item->array_at(0)->as_string() == "a"); - REQUIRE(item->array_at(1)->as_string() == "b"); - REQUIRE(item->array_at(2)->as_string() == "c"); + const auto& item = value.tag_at(9200); + REQUIRE(item.size() == 3); + REQUIRE(item.array_at(0).as_string() == "a"); + REQUIRE(item.array_at(1).as_string() == "b"); + REQUIRE(item.array_at(2).as_string() == "c"); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Tagged[9200]: @@ -1589,23 +1591,23 @@ TEST_CASE("CBOR: tagged array Tag(9200, ['a', 'b', 'c'])") String: "a" String: "b" String: "c")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged array Tag(9400, [1, 'two', b'3'])") { auto cbor_bytes = ccf::ds::from_hex("d924b883016374776f4133"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(9400); - REQUIRE(item->size() == 3); - REQUIRE(item->array_at(0)->as_signed() == 1); - REQUIRE(item->array_at(1)->as_string() == "two"); - REQUIRE(item->array_at(2)->as_bytes()[0] == 0x33); + const auto& item = value.tag_at(9400); + REQUIRE(item.size() == 3); + REQUIRE(item.array_at(0).as_signed() == 1); + REQUIRE(item.array_at(1).as_string() == "two"); + REQUIRE(item.array_at(2).as_bytes()[0] == 0x33); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Tagged[9400]: @@ -1613,21 +1615,21 @@ TEST_CASE("CBOR: tagged array Tag(9400, [1, 'two', b'3'])") Signed: 1 String: "two" Bytes[1]: 33)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: tagged array Tag(20000, [{'x': 1}, {'y': 2}])") { auto cbor_bytes = ccf::ds::from_hex("d94e2082a1617801a1617902"); - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - const auto& item = value->tag_at(20000); - const auto& arr = std::get(item->value); - REQUIRE(arr.items.size() == 2); + const auto& item = value.tag_at(20000); + const auto& arr = item; + REQUIRE(arr.size() == 2); - auto encoded = serialize(value); - auto decoded = parse(encoded); + auto encoded = value.nondet_serialize(); + auto decoded = nondet_parse(encoded); REQUIRE_EQ(cbor_bytes, encoded); const std::string expected_repr = R"(Tagged[20000]: @@ -1642,77 +1644,80 @@ TEST_CASE("CBOR: tagged array Tag(20000, [{'x': 1}, {'y': 2}])") String: "y" Value: Signed: 2)"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: helper function make_signed") { auto value = make_signed(42); - REQUIRE(value != nullptr); - REQUIRE(value->as_signed() == 42); + REQUIRE_FALSE(value.empty()); + REQUIRE(value.as_signed() == 42); const std::string expected_repr = "Signed: 42"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: helper function make_signed") { auto value = make_signed(-42); - REQUIRE(value != nullptr); - REQUIRE(value->as_signed() == -42); + REQUIRE_FALSE(value.empty()); + REQUIRE(value.as_signed() == -42); const std::string expected_repr = "Signed: -42"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: helper function make_string") { auto value = make_string("hello"); - REQUIRE(value != nullptr); - REQUIRE(value->as_string() == "hello"); + REQUIRE_FALSE(value.empty()); + REQUIRE(value.as_string() == "hello"); const std::string expected_repr = R"(String: "hello")"; - const std::string result = to_string(value); + const std::string result = ccf::cbor::test::to_string(value); REQUIRE(result == expected_repr); } TEST_CASE("CBOR: encode empty bytes and string with null data pointer") { // Zero-length spans and string_views may hold a null data pointer. - const Bytes null_bytes{static_cast(nullptr), 0}; - REQUIRE_EQ(serialize(make_bytes(null_bytes)), ccf::ds::from_hex("40")); + const std::span null_bytes{ + static_cast(nullptr), 0}; + REQUIRE_EQ( + make_bytes(null_bytes).nondet_serialize(), ccf::ds::from_hex("40")); - const String null_string{}; + const std::string_view null_string{}; REQUIRE(null_string.data() == nullptr); - REQUIRE_EQ(serialize(make_string(null_string)), ccf::ds::from_hex("60")); + REQUIRE_EQ( + make_string(null_string).nondet_serialize(), ccf::ds::from_hex("60")); // The common case: an empty vector, whose data() may be null. const std::vector empty_vec; - REQUIRE_EQ(serialize(make_bytes(empty_vec)), ccf::ds::from_hex("40")); + REQUIRE_EQ(make_bytes(empty_vec).nondet_serialize(), ccf::ds::from_hex("40")); } TEST_CASE("CBOR: error - invalid data") { auto cbor_bytes = ccf::ds::from_hex("18"); - REQUIRE_THROWS_AS(parse(cbor_bytes), CBORDecodeError); + REQUIRE_THROWS_AS(nondet_parse(cbor_bytes), DecodeError); } TEST_CASE("CBOR: error - array out of bounds") { auto cbor_bytes = ccf::ds::from_hex("83010203"); - auto value = parse(cbor_bytes); - REQUIRE_THROWS_AS((void)value->array_at(10), CBORDecodeError); + auto value = nondet_parse(cbor_bytes); + REQUIRE_THROWS_AS((void)value.array_at(10), DecodeError); } TEST_CASE("CBOR: error - unexpected tag") { auto cbor_bytes = ccf::ds::from_hex("d9232b42cafe"); // Tag 9003 - auto value = parse(cbor_bytes); + auto value = nondet_parse(cbor_bytes); - REQUIRE_THROWS_AS((void)value->tag_at(9004), CBORDecodeError); + REQUIRE_THROWS_AS((void)value.tag_at(9004), DecodeError); } TEST_CASE("CBOR: throw with context") @@ -1720,76 +1725,85 @@ TEST_CASE("CBOR: throw with context") auto v = make_signed(105); const std::string context = "Custom enough context"; - const std::string err = "Not a string value"; + // Accessors report the operation that failed. + const std::string err = "as_string"; const std::string expected_err = context + ": " + err; REQUIRE_THROWS_WITH_AS( - rethrow_with_msg([&]() { std::ignore = v->as_string(); }, context), + rethrow_with_msg([&]() { std::ignore = v.as_string(); }, context), expected_err.c_str(), - CBORDecodeError); + DecodeError); } TEST_CASE("CBOR: trailing bytes rejected") { // Valid CBOR integer 42 = 0x182a auto valid = ccf::ds::from_hex("182a"); - REQUIRE_NOTHROW(parse(valid)); + REQUIRE_NOTHROW(nondet_parse(valid)); // Append trailing byte - should be rejected auto with_trailing = ccf::ds::from_hex("182a00"); - REQUIRE_THROWS_AS(parse(with_trailing), CBORDecodeError); + REQUIRE_THROWS_AS(nondet_parse(with_trailing), DecodeError); // Valid CBOR byte string h'0102' = 0x420102 auto valid_bstr = ccf::ds::from_hex("420102"); - REQUIRE_NOTHROW(parse(valid_bstr)); + REQUIRE_NOTHROW(nondet_parse(valid_bstr)); // Append trailing bytes auto bstr_trailing = ccf::ds::from_hex("420102ff"); - REQUIRE_THROWS_AS(parse(bstr_trailing), CBORDecodeError); + REQUIRE_THROWS_AS(nondet_parse(bstr_trailing), DecodeError); // Valid CBOR array [1, 2] = 0x820102 auto valid_array = ccf::ds::from_hex("820102"); - REQUIRE_NOTHROW(parse(valid_array)); + REQUIRE_NOTHROW(nondet_parse(valid_array)); // Append trailing byte auto array_trailing = ccf::ds::from_hex("82010203"); - REQUIRE_THROWS_AS(parse(array_trailing), CBORDecodeError); + REQUIRE_THROWS_AS(nondet_parse(array_trailing), DecodeError); } TEST_CASE("CBOR: parse max depth") { // depth 1: [42] -- should pass at max_depth=2 auto depth1 = ccf::ds::from_hex("81182a"); - REQUIRE_NOTHROW(parse(depth1, 2)); + REQUIRE_NOTHROW(nondet_parse(depth1, 2)); // depth 2: [[42]] -- should pass at max_depth=2 auto depth2 = ccf::ds::from_hex("8181182a"); - REQUIRE_NOTHROW(parse(depth2, 2)); + REQUIRE_NOTHROW(nondet_parse(depth2, 2)); // depth 3: [[[42]]] -- should fail at max_depth=2 auto depth3 = ccf::ds::from_hex("818181182a"); - REQUIRE_THROWS_AS(parse(depth3, 2), CBORDecodeError); + REQUIRE_THROWS_AS(nondet_parse(depth3, 2), DecodeError); // map depth 3: {1: {1: {1: 42}}} -- should fail at max_depth=2 auto map_depth3 = ccf::ds::from_hex("a101a101a101182a"); - REQUIRE_THROWS_AS(parse(map_depth3, 2), CBORDecodeError); + REQUIRE_THROWS_AS(nondet_parse(map_depth3, 2), DecodeError); // map depth 2: {1: {1: 42}} -- should pass at max_depth=2 auto map_depth2 = ccf::ds::from_hex("a101a101182a"); - REQUIRE_NOTHROW(parse(map_depth2, 2)); + REQUIRE_NOTHROW(nondet_parse(map_depth2, 2)); } TEST_CASE("CBOR: serialize max depth") { // depth 1: [42] -- should pass at max_depth=1,2 - auto shallow = make_array({make_signed(42)}); - REQUIRE_NOTHROW(serialize(shallow, 1)); - REQUIRE_NOTHROW(serialize(shallow, 2)); + std::vector shallow_items; + shallow_items.push_back(make_signed(42)); + auto shallow = make_array(std::move(shallow_items)); + REQUIRE_NOTHROW(std::ignore = shallow.nondet_serialize(1)); + REQUIRE_NOTHROW(std::ignore = shallow.nondet_serialize(2)); // Build 3 levels: [[[42]]] - auto deep = make_array({make_array({make_array({make_signed(42)})})}); - REQUIRE_THROWS_AS(serialize(deep, 2), CBOREncodeError); + auto deep = make_signed(42); + for (int i = 0; i < 3; ++i) + { + std::vector level; + level.push_back(std::move(deep)); + deep = make_array(std::move(level)); + } + REQUIRE_THROWS_AS(std::ignore = deep.nondet_serialize(2), EncodeError); // Same deep tree passes at higher limit - REQUIRE_NOTHROW(serialize(deep, 3)); - REQUIRE_NOTHROW(serialize(deep, 4)); + REQUIRE_NOTHROW(std::ignore = deep.nondet_serialize(3)); + REQUIRE_NOTHROW(std::ignore = deep.nondet_serialize(4)); } diff --git a/src/crypto/test/cbor_fuzz.cpp b/src/crypto/test/cbor_fuzz.cpp index 9b6c3221b840..87b9b1e7e953 100644 --- a/src/crypto/test/cbor_fuzz.cpp +++ b/src/crypto/test/cbor_fuzz.cpp @@ -1,30 +1,32 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the Apache 2.0 License. -#include "crypto/cbor.h" +#include "crypto/cbor_tags.h" +#include "crypto/test/cbor_printer.h" #include #include #include +#include extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - ccf::cbor::Value value; + tav::cbor::Value value; try { - value = ccf::cbor::parse({data, size}); + value = tav::cbor::nondet_parse({data, size}); } - catch (const ccf::cbor::CBORDecodeError&) + catch (const tav::cbor::DecodeError&) { return 0; } // If parse succeeded, exercise serialization round-trip and string // rendering. Any failure here is a real bug - let the fuzzer surface it. - std::ignore = ccf::cbor::to_string(value); - auto serialized = ccf::cbor::serialize(value); - auto reparsed = ccf::cbor::parse(serialized); - auto reserialized = ccf::cbor::serialize(reparsed); + std::ignore = ccf::cbor::test::to_string(value); + auto serialized = value.nondet_serialize(); + auto reparsed = tav::cbor::nondet_parse(serialized); + auto reserialized = reparsed.nondet_serialize(); if (serialized != reserialized) { diff --git a/src/crypto/test/cbor_printer.h b/src/crypto/test/cbor_printer.h new file mode 100644 index 000000000000..7edf88263dbe --- /dev/null +++ b/src/crypto/test/cbor_printer.h @@ -0,0 +1,133 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the Apache 2.0 License. + +#pragma once + +#include "ccf/ds/hex.h" + +#include +#include +#include +#include + +namespace ccf::cbor::test +{ + inline void print_indent(std::ostringstream& os, size_t indent) + { + for (size_t i = 0; i < indent; ++i) + { + os << " "; + } + } + + inline std::string format_simple(uint8_t v) + { + const auto casted = static_cast(v); + switch (casted) + { + case tav::cbor::SimpleValue::False: + return "Simple: False"; + case tav::cbor::SimpleValue::True: + return "Simple: True"; + case tav::cbor::SimpleValue::Null: + return "Simple: Null"; + case tav::cbor::SimpleValue::Undefined: + return "Simple: Undefined"; + default: + return "Simple: " + std::to_string(casted); + } + } + + inline void print_value_impl( + std::ostringstream& os, const tav::cbor::Value& value, size_t indent) + { + using tav::cbor::Kind; + + switch (value.kind()) + { + case Kind::SIGNED: + print_indent(os, indent); + os << "Signed: " << value.as_signed() << std::endl; + break; + + case Kind::BYTES: + { + const auto bytes = value.as_bytes(); + print_indent(os, indent); + os << "Bytes[" << bytes.size() << "]:"; + if (!bytes.empty()) + { + os << " "; + } + os << ccf::ds::to_hex(bytes) << std::endl; + break; + } + + case Kind::STRING: + print_indent(os, indent); + os << "String: \"" << value.as_string() << "\"" << std::endl; + break; + + case Kind::ARRAY: + { + const auto count = value.size(); + print_indent(os, indent); + os << "Array[" << count << "]:" << std::endl; + for (size_t i = 0; i < count; ++i) + { + print_value_impl(os, value.array_at(i), indent + 1); + } + break; + } + + case Kind::MAP: + { + const auto count = value.size(); + print_indent(os, indent); + os << "Map[" << count << "]:" << std::endl; + for (size_t i = 0; i < count; ++i) + { + print_indent(os, indent + 1); + os << "Key:" << std::endl; + print_value_impl(os, value.map_key_at(i), indent + 2); + print_indent(os, indent + 1); + os << "Value:" << std::endl; + print_value_impl(os, value.map_value_at(i), indent + 2); + } + break; + } + + case Kind::TAGGED: + { + const auto tag = value.as_tag(); + print_indent(os, indent); + os << "Tagged[" << tag << "]:" << std::endl; + print_value_impl(os, value.tag_at(tag), indent + 1); + break; + } + + case Kind::SIMPLE: + print_indent(os, indent); + os << format_simple(value.as_simple()) << std::endl; + break; + + case Kind::INVALID: + default: + print_indent(os, indent); + os << "" << std::endl; + break; + } + } + + inline std::string to_string(const tav::cbor::Value& value) + { + std::ostringstream os; + print_value_impl(os, value, 0); + auto as_string = os.str(); + if (!as_string.empty() && as_string.back() == '\n') + { + as_string.pop_back(); + } + return as_string; + } +} diff --git a/src/crypto/test/cose.cpp b/src/crypto/test/cose.cpp index 8b9aeb976889..d023b754edb1 100644 --- a/src/crypto/test/cose.cpp +++ b/src/crypto/test/cose.cpp @@ -7,7 +7,9 @@ #include "ccf/crypto/verifier.h" #include "ccf/ds/hex.h" #include "cose/cose_rs_ffi.h" +#include "crypto/cbor_helpers.h" #include "crypto/openssl/cose_verifier.h" +#include "crypto/test/cbor_printer.h" #include "node/cose_common.h" #include @@ -15,6 +17,7 @@ #include #include #include +#include #include // Hardcoded test vectors signed with pycose / Python cryptography (P-384). @@ -164,7 +167,7 @@ TEST_CASE("Check unprotected header") { for (auto& [envelope, payload, detached] : test_envelopes()) { - using namespace ccf::cbor; + using namespace tav::cbor; for (const auto& key : keys) { @@ -173,14 +176,15 @@ TEST_CASE("Check unprotected header") ccf::cose::edit::desc::Value desc{position, key, value}; auto edited = ccf::cose::edit::set_unprotected_header(envelope, desc); - auto parsed = parse(edited); + auto parsed = nondet_parse(edited); const auto& uhdr = - parsed->tag_at(ccf::cbor::tag::COSE_SIGN_1)->array_at(1); + parsed.tag_at(ccf::cbor::tag::COSE_SIGN_1).array_at(1); std::vector ref; if (std::holds_alternative(position)) { - std::vector items{make_bytes(value)}; + std::vector items; + items.push_back(make_bytes(value)); ref.emplace_back(make_signed(key), make_array(std::move(items))); } @@ -188,15 +192,19 @@ TEST_CASE("Check unprotected header") { auto subkey = std::get(position).key; - std::vector items{make_bytes(value)}; - std::vector inner_map{ - {make_signed(subkey), make_array(std::move(items))}}; + std::vector items; + items.push_back(make_bytes(value)); + std::vector inner_map; + inner_map.emplace_back( + make_signed(subkey), make_array(std::move(items))); ref.emplace_back(make_signed(key), make_map(std::move(inner_map))); } auto ref_map = make_map(std::move(ref)); - REQUIRE_EQ(to_string(ref_map), to_string(uhdr)); + REQUIRE_EQ( + ccf::cbor::test::to_string(ref_map), + ccf::cbor::test::to_string(uhdr)); } } @@ -204,13 +212,13 @@ TEST_CASE("Check unprotected header") auto edited = ccf::cose::edit::set_unprotected_header( envelope, ccf::cose::edit::desc::Empty{}); - auto parsed = parse(edited); - const auto& uhdr = - parsed->tag_at(ccf::cbor::tag::COSE_SIGN_1)->array_at(1); + auto parsed = nondet_parse(edited); + const auto& uhdr = parsed.tag_at(ccf::cbor::tag::COSE_SIGN_1).array_at(1); auto ref_map = make_map({}); - REQUIRE_EQ(to_string(ref_map), to_string(uhdr)); + REQUIRE_EQ( + ccf::cbor::test::to_string(ref_map), ccf::cbor::test::to_string(uhdr)); } } } @@ -240,45 +248,66 @@ TEST_CASE("Decode CCF COSE receipt") Sibling, }; const auto with_proof_hash_size = [&](ProofHashField field, size_t size) { - using namespace ccf::cbor; + using namespace tav::cbor; - auto receipt = parse(receipt_bytes); - const auto& envelope = receipt->tag_at(ccf::cbor::tag::COSE_SIGN_1); - const auto& unprotected = envelope->array_at(1); + auto receipt = nondet_parse(receipt_bytes); + const auto& envelope = receipt.tag_at(ccf::cbor::tag::COSE_SIGN_1); + const auto& unprotected = envelope.array_at(1); const auto& vdp = - unprotected->map_at(make_signed(ccf::cose::header::iana::VDP)); + unprotected.map_at(make_signed(ccf::cose::header::iana::VDP)); const auto& proofs = - vdp->map_at(make_signed(ccf::cose::header::iana::INCLUSION_PROOFS)); - auto proof = parse(proofs->array_at(0)->as_bytes()); + vdp.map_at(make_signed(ccf::cose::header::iana::INCLUSION_PROOFS)); + auto proof = nondet_parse(proofs.array_at(0).as_bytes()); std::vector replacement(size, 0x42); std::array empty_replacement{}; const std::span replacement_span = replacement.empty() ? std::span(empty_replacement.data(), 0) : std::span(replacement); + Value edited_proof; if (field == ProofHashField::Sibling) { - const auto& path = proof->map_at( + const auto path = proof.map_at( make_signed(ccf::MerkleProofLabel::MERKLE_PROOF_PATH_LABEL)); - const auto& link = path->array_at(0); - std::get(link->value).items.at(1) = make_bytes(replacement_span); + const auto link = path.array_at(0); + auto edited_link = + ccf::cbor::with_element(link, 1, make_bytes(replacement_span)); + auto edited_path = + ccf::cbor::with_element(path, 0, std::move(edited_link)); + edited_proof = ccf::cbor::with_entry( + proof, + ccf::MerkleProofLabel::MERKLE_PROOF_PATH_LABEL, + std::move(edited_path)); } else { - const auto& leaf = proof->map_at( + const auto leaf = proof.map_at( make_signed(ccf::MerkleProofLabel::MERKLE_PROOF_LEAF_LABEL)); const auto index = field == ProofHashField::WriteSetDigest ? 0 : 2; - std::get(leaf->value).items.at(index) = - make_bytes(replacement_span); + auto edited_leaf = + ccf::cbor::with_element(leaf, index, make_bytes(replacement_span)); + edited_proof = ccf::cbor::with_entry( + proof, + ccf::MerkleProofLabel::MERKLE_PROOF_LEAF_LABEL, + std::move(edited_leaf)); } - auto serialised_proof = serialize(proof); - std::get(proofs->value).items.at(0) = make_bytes(serialised_proof); - return serialize(receipt); + const auto serialised_proof = edited_proof.nondet_serialize(); + auto edited_proofs = + ccf::cbor::with_element(proofs, 0, make_bytes(serialised_proof)); + auto edited_vdp = ccf::cbor::with_entry( + vdp, ccf::cose::header::iana::INCLUSION_PROOFS, std::move(edited_proofs)); + auto edited_unprotected = ccf::cbor::with_entry( + unprotected, ccf::cose::header::iana::VDP, std::move(edited_vdp)); + auto edited_envelope = + ccf::cbor::with_element(envelope, 1, std::move(edited_unprotected)); + const Value edited_receipt = + make_tagged(ccf::cbor::tag::COSE_SIGN_1, std::move(edited_envelope)); + return edited_receipt.nondet_serialize(); }; const auto decode_proofs = [](const std::vector& receipt_bytes) { - auto receipt = ccf::cbor::parse(receipt_bytes); - const auto& envelope = receipt->tag_at(ccf::cbor::tag::COSE_SIGN_1); + auto receipt = tav::cbor::nondet_parse(receipt_bytes); + const auto& envelope = receipt.tag_at(ccf::cbor::tag::COSE_SIGN_1); return ccf::cose::decode_merkle_proofs(envelope); }; const auto with_decoded_proof_hash_size = diff --git a/src/crypto/test/cose_bench.cpp b/src/crypto/test/cose_bench.cpp index a099949767ce..8b724a9ea7f1 100644 --- a/src/crypto/test/cose_bench.cpp +++ b/src/crypto/test/cose_bench.cpp @@ -2,10 +2,13 @@ // Licensed under the Apache 2.0 License. #include "cose/cose_rs_ffi.h" -#include "crypto/cbor.h" +#include "crypto/cbor_helpers.h" +#include "crypto/cbor_tags.h" #include "crypto/cose.h" #include "crypto/openssl/ec_key_pair.h" +#include + #define PICOBENCH_UNIQUE_SYM_SUFFIX __COUNTER__ #define PICOBENCH_IMPLEMENT_WITH_MAIN #include @@ -65,30 +68,30 @@ struct CoseSign1Components static CoseSign1Components decompose(const std::vector& envelope) { - using namespace ccf::cbor; - auto cose = parse(envelope); - const auto& env = cose->tag_at(ccf::cbor::tag::COSE_SIGN_1); - auto phdr = env->array_at(0)->as_bytes(); + using namespace tav::cbor; + auto cose = nondet_parse(envelope); + const auto& env = cose.tag_at(ccf::cbor::tag::COSE_SIGN_1); + auto phdr = env.array_at(0).as_bytes(); std::optional> payload; try { - payload = env->array_at(2)->as_bytes(); + payload = env.array_at(2).as_bytes(); } - catch (const CBORDecodeError&) + catch (const DecodeError&) { - if (env->array_at(2)->as_simple() != ccf::cbor::SimpleValue::Null) + if (env.array_at(2).as_simple() != tav::cbor::SimpleValue::Null) { throw; } } - auto sig = env->array_at(3)->as_bytes(); + auto sig = env.array_at(3).as_bytes(); - auto phdr_parsed = parse({phdr.data(), phdr.size()}); + auto phdr_parsed = nondet_parse({phdr.data(), phdr.size()}); auto alg = - phdr_parsed->map_at(ccf::cbor::make_signed(ccf::cose::header::iana::ALG)) - ->as_signed(); + phdr_parsed.map_at(tav::cbor::make_signed(ccf::cose::header::iana::ALG)) + .as_signed(); return {phdr, payload, sig, alg}; } diff --git a/src/crypto/test/crypto.cpp b/src/crypto/test/crypto.cpp index 4677e09a89e3..f01a7cda3920 100644 --- a/src/crypto/test/crypto.cpp +++ b/src/crypto/test/crypto.cpp @@ -14,7 +14,7 @@ #include "ccf/crypto/symmetric_key.h" #include "ccf/crypto/verifier.h" #include "ccf/ds/x509_time_fmt.h" -#include "crypto/cbor.h" +#include "crypto/cbor_tags.h" #include "crypto/certs.h" #include "crypto/cose.h" #include "crypto/csr.h" @@ -31,6 +31,7 @@ #include #include #include +#include using namespace std; using namespace ccf::crypto; diff --git a/src/endpoints/authentication/cose_auth.cpp b/src/endpoints/authentication/cose_auth.cpp index 7d46649c2ee7..1c84c5f7cee8 100644 --- a/src/endpoints/authentication/cose_auth.cpp +++ b/src/endpoints/authentication/cose_auth.cpp @@ -9,9 +9,12 @@ #include "ccf/rpc_context.h" #include "ccf/service/tables/members.h" #include "ccf/service/tables/users.h" -#include "crypto/cbor.h" +#include "crypto/cbor_helpers.h" +#include "crypto/cbor_tags.h" #include "node/cose_common.h" +#include + namespace { std::string buf_to_string(std::span buf) @@ -42,46 +45,44 @@ namespace ccf extract_governance_protected_header_and_signature( const std::vector& cose_sign1) { - using namespace ccf::cbor; + using namespace tav::cbor; auto cose_cbor = rethrow_with_msg( - [&]() { return parse(cose_sign1); }, "Parse COSE CBOR"); + [&]() { return nondet_parse(cose_sign1); }, "Parse COSE CBOR"); - const auto& cose_envelope = rethrow_with_msg( - [&]() -> auto& { - return cose_cbor->tag_at(ccf::cbor::tag::COSE_SIGN_1); - }, + const auto cose_envelope = rethrow_with_msg( + [&]() { return cose_cbor.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "Parse COSE tag"); - const auto& phdr_raw = rethrow_with_msg( - [&]() -> auto& { return cose_envelope->array_at(0); }, + const auto phdr_raw = rethrow_with_msg( + [&]() { return cose_envelope.array_at(0); }, "Parse raw protected header"); auto phdr = rethrow_with_msg( - [&]() { return parse(phdr_raw->as_bytes()); }, + [&]() { return nondet_parse(phdr_raw.as_bytes()); }, "Decode protected header"); ccf::GovernanceProtectedHeader parsed; parsed.alg = rethrow_with_msg( [&]() { - return phdr->map_at(make_signed(header::iana::ALG))->as_signed(); + return phdr.map_at(make_signed(header::iana::ALG)).as_signed(); }, "Parse alg in protected header"); parsed.kid = buf_to_string(rethrow_with_msg( [&]() { - return phdr->map_at(make_signed(header::iana::KID))->as_bytes(); + return phdr.map_at(make_signed(header::iana::KID)).as_bytes(); }, "Parse kid in protected header")); parsed.gov_msg_created_at = rethrow_with_msg( [&]() { const int64_t value = - phdr->map_at(make_string(HEADER_PARAM_MSG_CREATED_AT))->as_signed(); + phdr.map_at(make_string(HEADER_PARAM_MSG_CREATED_AT)).as_signed(); if (value < 0) { - throw CBORDecodeError(Error::TYPE_MISMATCH, "Must be non-negative"); + throw DecodeError(Error::TYPE_MISMATCH, "Must be non-negative"); } return value; }, @@ -90,10 +91,10 @@ namespace ccf try { parsed.gov_msg_type = rethrow_with_msg([&]() { - return phdr->map_at(make_string(HEADER_PARAM_MSG_TYPE))->as_string(); + return phdr.map_at(make_string(HEADER_PARAM_MSG_TYPE)).as_string(); }); } - catch (const CBORDecodeError& err) + catch (const DecodeError& err) { if (err.error_code() != Error::KEY_NOT_FOUND) { @@ -104,11 +105,11 @@ namespace ccf try { parsed.gov_msg_proposal_id = rethrow_with_msg([&]() { - return phdr->map_at(make_string(HEADER_PARAM_MSG_PROPOSAL_ID)) - ->as_string(); + return phdr.map_at(make_string(HEADER_PARAM_MSG_PROPOSAL_ID)) + .as_string(); }); } - catch (const CBORDecodeError& err) + catch (const DecodeError& err) { if (err.error_code() != Error::KEY_NOT_FOUND) { @@ -117,15 +118,15 @@ namespace ccf } auto signature = rethrow_with_msg( - [&]() { return cose_envelope->array_at(3)->as_bytes(); }, + [&]() { return cose_envelope.array_at(3).as_bytes(); }, "Parse COSE signature"); auto payload = rethrow_with_msg( - [&]() { return cose_envelope->array_at(2)->as_bytes(); }, + [&]() { return cose_envelope.array_at(2).as_bytes(); }, "Parse COSE payload"); DecomposedCoseSign1 decomposed{ - phdr_raw->as_bytes(), payload, signature, parsed.alg}; + phdr_raw.as_bytes(), payload, signature, parsed.alg}; return {parsed, decomposed}; } @@ -135,36 +136,34 @@ namespace ccf const std::string& msg_type_name, const std::string& created_at_name) { - using namespace ccf::cbor; + using namespace tav::cbor; auto cose_cbor = rethrow_with_msg( - [&]() { return parse(cose_sign1); }, "Parse COSE CBOR"); + [&]() { return nondet_parse(cose_sign1); }, "Parse COSE CBOR"); - const auto& cose_envelope = rethrow_with_msg( - [&]() -> auto& { - return cose_cbor->tag_at(ccf::cbor::tag::COSE_SIGN_1); - }, + const auto cose_envelope = rethrow_with_msg( + [&]() { return cose_cbor.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "Parse COSE tag"); - const auto& phdr_raw = rethrow_with_msg( - [&]() -> auto& { return cose_envelope->array_at(0); }, + const auto phdr_raw = rethrow_with_msg( + [&]() { return cose_envelope.array_at(0); }, "Parse raw protected header"); auto phdr = rethrow_with_msg( - [&]() { return parse(phdr_raw->as_bytes()); }, + [&]() { return nondet_parse(phdr_raw.as_bytes()); }, "Decode protected header"); ccf::TimestampedProtectedHeader parsed; parsed.alg = rethrow_with_msg( [&]() { - return phdr->map_at(make_signed(header::iana::ALG))->as_signed(); + return phdr.map_at(make_signed(header::iana::ALG)).as_signed(); }, "Parse alg in protected header"); parsed.kid = buf_to_string(rethrow_with_msg( [&]() { - return phdr->map_at(make_signed(header::iana::KID))->as_bytes(); + return phdr.map_at(make_signed(header::iana::KID)).as_bytes(); }, "Parse kid in protected header")); @@ -173,11 +172,11 @@ namespace ccf parsed.msg_type = rethrow_with_msg( [&]() { return std::string( - phdr->map_at(make_string(msg_type_name))->as_string()); + phdr.map_at(make_string(msg_type_name)).as_string()); }, "Parse msg type in protected header"); } - catch (const CBORDecodeError& err) + catch (const DecodeError& err) { if (err.error_code() != Error::KEY_NOT_FOUND) { @@ -189,18 +188,18 @@ namespace ccf { auto val = rethrow_with_msg( [&]() { - return phdr->map_at(make_string(created_at_name))->as_signed(); + return phdr.map_at(make_string(created_at_name)).as_signed(); }, "Parse created_at in protected header"); if (val < 0) { - throw CBORDecodeError( + throw DecodeError( Error::TYPE_MISMATCH, "Header parameter created_at must be positive"); } parsed.msg_created_at = val; } - catch (const CBORDecodeError& err) + catch (const DecodeError& err) { if (err.error_code() != Error::KEY_NOT_FOUND) { @@ -209,15 +208,15 @@ namespace ccf } auto signature = rethrow_with_msg( - [&]() { return cose_envelope->array_at(3)->as_bytes(); }, + [&]() { return cose_envelope.array_at(3).as_bytes(); }, "Parse COSE signature"); auto payload = rethrow_with_msg( - [&]() { return cose_envelope->array_at(2)->as_bytes(); }, + [&]() { return cose_envelope.array_at(2).as_bytes(); }, "Parse COSE payload"); DecomposedCoseSign1 decomposed{ - phdr_raw->as_bytes(), payload, signature, parsed.alg}; + phdr_raw.as_bytes(), payload, signature, parsed.alg}; return {parsed, decomposed}; } } diff --git a/src/node/cose_common.h b/src/node/cose_common.h index d1c01abed64c..78ed6a014de9 100644 --- a/src/node/cose_common.h +++ b/src/node/cose_common.h @@ -7,15 +7,17 @@ #include "ccf/ds/hex.h" #include "ccf/ds/x509_time_fmt.h" #include "ccf/receipt.h" +#include "crypto/cbor_helpers.h" #include -#include +#include #include #include #include #include #include #include +#include #include namespace ccf::cose @@ -79,61 +81,60 @@ namespace ccf::cose CwtClaims cwt; }; - static void decode_cwt_claims(const ccf::cbor::Value& cbor, CwtClaims& claims) + static void decode_cwt_claims(const tav::cbor::Value& cbor, CwtClaims& claims) { - using namespace ccf::cbor; + using namespace tav::cbor; - const auto& cwt_claims = rethrow_with_msg( - [&]() -> auto& { - return cbor->map_at(make_signed(ccf::cose::header::iana::CWT_CLAIMS)); + const auto cwt_claims = rethrow_with_msg( + [&]() { + return cbor.map_at(make_signed(ccf::cose::header::iana::CWT_CLAIMS)); }, "Parse CWT claims map"); try { const auto& iat = - cwt_claims->map_at(make_signed(ccf::cwt::header::iana::IAT)); + cwt_claims.map_at(make_signed(ccf::cwt::header::iana::IAT)); try { - claims.iat = iat->as_signed(); + claims.iat = iat.as_signed(); } - catch (const CBORDecodeError&) + catch (const DecodeError&) { // CWT NumericDate values MUST omit CBOR tags: // https://www.rfc-editor.org/rfc/rfc8392.html#section-5 // This non-conforming fallback accepts CBOR tag 1 for UVM // endorsement compatibility. - claims.iat = iat->tag_at(ccf::cbor::tag::EPOCH_DATE_TIME)->as_signed(); + claims.iat = iat.tag_at(ccf::cbor::tag::EPOCH_DATE_TIME).as_signed(); } } - catch (const CBORDecodeError& err) + catch (const DecodeError& err) { std::ignore = err; // optional field } claims.iss = rethrow_with_msg( [&]() { - return cwt_claims->map_at(make_signed(ccf::cwt::header::iana::ISS)) - ->as_string(); + return cwt_claims.map_at(make_signed(ccf::cwt::header::iana::ISS)) + .as_string(); }, fmt::format( "Parse CWT claim iss({}) field", ccf::cwt::header::iana::ISS)); claims.sub = rethrow_with_msg( [&]() { - return cwt_claims->map_at(make_signed(ccf::cwt::header::iana::SUB)) - ->as_string(); + return cwt_claims.map_at(make_signed(ccf::cwt::header::iana::SUB)) + .as_string(); }, fmt::format( "Parse CWT claim sub({}) field", ccf::cwt::header::iana::SUB)); try { - claims.svn = - cwt_claims->map_at(make_string(ccf::cwt::header::custom::SVN)) - ->as_signed(); + claims.svn = cwt_claims.map_at(make_string(ccf::cwt::header::custom::SVN)) + .as_signed(); } - catch (const CBORDecodeError& err) + catch (const DecodeError& err) { if (err.error_code() != Error::KEY_NOT_FOUND) { @@ -182,15 +183,15 @@ namespace ccf::cose } static Sign1ProtectedHeader decode_sign1_protected_header( - const ccf::cbor::Value& phdr) + const tav::cbor::Value& phdr) { - using namespace ccf::cbor; + using namespace tav::cbor; Sign1ProtectedHeader hdr; hdr.alg = rethrow_with_msg( [&]() { - return phdr->map_at(make_signed(ccf::cose::header::iana::ALG)) - ->as_signed(); + return phdr.map_at(make_signed(ccf::cose::header::iana::ALG)) + .as_signed(); }, fmt::format( "Parse protected header alg({})", ccf::cose::header::iana::ALG)); @@ -198,17 +199,17 @@ namespace ccf::cose try { const auto& cty = - phdr->map_at(make_signed(ccf::cose::header::iana::CONTENT_TYPE)); + phdr.map_at(make_signed(ccf::cose::header::iana::CONTENT_TYPE)); try { - hdr.cty = std::string(cty->as_string()); + hdr.cty = std::string(cty.as_string()); } - catch (const CBORDecodeError&) + catch (const DecodeError&) { - hdr.cty = cty->as_signed(); + hdr.cty = cty.as_signed(); } } - catch (const CBORDecodeError& err) + catch (const DecodeError& err) { std::ignore = err; // optional field } @@ -216,7 +217,7 @@ namespace ccf::cose hdr.x5chain = rethrow_with_msg( [&]() { const auto& x5chain_val = - phdr->map_at(make_signed(ccf::cose::header::iana::X5CHAIN)); + phdr.map_at(make_signed(ccf::cose::header::iana::X5CHAIN)); return ccf::cose::utils::parse_x5chain(x5chain_val); }, fmt::format( @@ -312,35 +313,35 @@ namespace ccf::cose return {leaf_digest.h.begin(), leaf_digest.h.end()}; } - static void decode_ccf_claims(const ccf::cbor::Value& cbor, CcfClaims& claims) + static void decode_ccf_claims(const tav::cbor::Value& cbor, CcfClaims& claims) { - using namespace ccf::cbor; + using namespace tav::cbor; - const auto& ccf_claims = rethrow_with_msg( - [&]() -> auto& { - return cbor->map_at(make_string(ccf::cose::header::custom::CCF_V1)); + const auto ccf_claims = rethrow_with_msg( + [&]() { + return cbor.map_at(make_string(ccf::cose::header::custom::CCF_V1)); }, "Parse CCF claims map"); claims.txid = rethrow_with_msg( [&]() { - return ccf_claims->map_at(make_string(ccf::cose::header::custom::TX_ID)) - ->as_string(); + return ccf_claims.map_at(make_string(ccf::cose::header::custom::TX_ID)) + .as_string(); }, fmt::format( "Parse CCF claims TxID ({}) field", ccf::cose::header::custom::TX_ID)); } - static CcfCoseReceiptPhdr decode_ccf_receipt_phdr(ccf::cbor::Value& cbor) + static CcfCoseReceiptPhdr decode_ccf_receipt_phdr(tav::cbor::Value& cbor) { - using namespace ccf::cbor; + using namespace tav::cbor; CcfCoseReceiptPhdr phdr{}; phdr.alg = rethrow_with_msg( [&]() { - return cbor->map_at(make_signed(ccf::cose::header::iana::ALG)) - ->as_signed(); + return cbor.map_at(make_signed(ccf::cose::header::iana::ALG)) + .as_signed(); }, fmt::format( "Parse protected header alg({})", ccf::cose::header::iana::ALG)); @@ -348,7 +349,7 @@ namespace ccf::cose rethrow_with_msg( [&]() { const auto& bytes = - cbor->map_at(make_signed(ccf::cose::header::iana::KID))->as_bytes(); + cbor.map_at(make_signed(ccf::cose::header::iana::KID)).as_bytes(); phdr.kid.assign(bytes.begin(), bytes.end()); }, fmt::format( @@ -356,8 +357,8 @@ namespace ccf::cose phdr.vds = rethrow_with_msg( [&]() { - return cbor->map_at(make_signed(ccf::cose::header::iana::VDS)) - ->as_signed(); + return cbor.map_at(make_signed(ccf::cose::header::iana::VDS)) + .as_signed(); }, fmt::format( "Parse protected header vds({})", ccf::cose::header::iana::VDS)); @@ -375,47 +376,46 @@ namespace ccf::cose } static std::vector decode_merkle_proofs( - const ccf::cbor::Value& cbor) + const tav::cbor::Value& cbor) { - using namespace ccf::cbor; + using namespace tav::cbor; - const auto& uhdr = rethrow_with_msg( - [&]() -> auto& { return cbor->array_at(1); }, - "Parse unprotected header map"); + const auto uhdr = rethrow_with_msg( + [&]() { return cbor.array_at(1); }, "Parse unprotected header map"); - const auto& vdp = rethrow_with_msg( - [&]() -> auto& { - return uhdr->map_at(make_signed(ccf::cose::header::iana::VDP)); - }, + const auto vdp = rethrow_with_msg( + [&]() { return uhdr.map_at(make_signed(ccf::cose::header::iana::VDP)); }, fmt::format("Parse vdp() map", ccf::cose::header::iana::VDP)); - const auto& proofs_array = rethrow_with_msg( - [&]() -> auto& { - return vdp->map_at( + const auto proofs_array = rethrow_with_msg( + [&]() { + return vdp.map_at( make_signed(ccf::cose::header::iana::INCLUSION_PROOFS)); }, "Parse inclusion proofs"); std::vector proofs; - rethrow_with_msg( + const auto proof_count = rethrow_with_msg( [&]() { - if (proofs_array->size() == 0) + const auto count = proofs_array.size(); + if (count == 0) { - throw CBORDecodeError(Error::DECODE_FAILED, "Empty proofs array"); + throw DecodeError(Error::DECODE_FAILED, "Empty proofs array"); } + return count; }, "Check proofs array"); - for (size_t i = 0; i < proofs_array->size(); ++i) + for (size_t i = 0; i < proof_count; ++i) { auto cbor_proof = rethrow_with_msg( - [&]() { return parse(proofs_array->array_at(i)->as_bytes()); }, + [&]() { return nondet_parse(proofs_array.array_at(i).as_bytes()); }, "Parse an encoded proof"); - const auto& leaf = rethrow_with_msg( - [&]() -> auto& { - return cbor_proof->map_at( + const auto leaf = rethrow_with_msg( + [&]() { + return cbor_proof.map_at( make_signed(ccf::MerkleProofLabel::MERKLE_PROOF_LEAF_LABEL)); }, "Parse proof: leaf"); @@ -425,7 +425,7 @@ namespace ccf::cose rethrow_with_msg( [&]() { const auto& bytes = - leaf->array_at(ccf::MerkleProofPathBranch::LEFT)->as_bytes(); + leaf.array_at(ccf::MerkleProofPathBranch::LEFT).as_bytes(); validate_sha256_bytes(bytes, "Merkle proof write set digest"); proof.leaf.write_set_digest.assign(bytes.begin(), bytes.end()); }, @@ -433,46 +433,48 @@ namespace ccf::cose proof.leaf.commit_evidence = rethrow_with_msg( [&]() { - return leaf->array_at(ccf::MerkleProofPathBranch::RIGHT)->as_string(); + return leaf.array_at(ccf::MerkleProofPathBranch::RIGHT).as_string(); }, "Parse leaf at ce"); rethrow_with_msg( [&]() { - const auto& bytes = leaf->array_at(2)->as_bytes(); + const auto& bytes = leaf.array_at(2).as_bytes(); validate_sha256_bytes(bytes, "Merkle proof claims digest"); proof.leaf.claims_digest.assign(bytes.begin(), bytes.end()); }, "Parse leaf at cd"); - const auto& cbor_path = rethrow_with_msg( - [&]() -> auto& { - return cbor_proof->map_at( + const auto cbor_path = rethrow_with_msg( + [&]() { + return cbor_proof.map_at( make_signed(ccf::MerkleProofLabel::MERKLE_PROOF_PATH_LABEL)); }, "Parse proof: path"); - rethrow_with_msg( + const auto path_length = rethrow_with_msg( [&]() { - if (cbor_path->size() == 0) + const auto length = cbor_path.size(); + if (length == 0) { - throw CBORDecodeError(Error::DECODE_FAILED, "Empty path"); + throw DecodeError(Error::DECODE_FAILED, "Empty path"); } + return length; }, "Check proof: path"); - for (size_t j = 0; j < cbor_path->size(); j++) + for (size_t j = 0; j < path_length; j++) { std::pair> path_item; - const auto& link = rethrow_with_msg( - [&]() -> auto& { return cbor_path->array_at(j); }, "Parse path link"); + const auto link = rethrow_with_msg( + [&]() { return cbor_path.array_at(j); }, "Parse path link"); path_item.first = static_cast(rethrow_with_msg( - [&]() { return simple_to_boolean(link->array_at(0)->as_simple()); }, + [&]() { return simple_to_boolean(link.array_at(0).as_simple()); }, "Parse path element at direction")); rethrow_with_msg( [&]() { - const auto& bytes = link->array_at(1)->as_bytes(); + const auto& bytes = link.array_at(1).as_bytes(); validate_sha256_bytes(bytes, "Merkle proof sibling"); path_item.second.assign(bytes.begin(), bytes.end()); }, @@ -489,21 +491,22 @@ namespace ccf::cose static CcfCoseReceipt decode_ccf_receipt( const std::vector& cose_sign1, bool recompute_root) { - using namespace ccf::cbor; + using namespace tav::cbor; - auto cose_cbor = - rethrow_with_msg([&]() { return parse(cose_sign1); }, "Parse COSE CBOR"); + auto cose_cbor = rethrow_with_msg( + [&]() { return nondet_parse(cose_sign1); }, "Parse COSE CBOR"); - const auto& cose_envelope = rethrow_with_msg( - [&]() -> auto& { return cose_cbor->tag_at(ccf::cbor::tag::COSE_SIGN_1); }, + const auto cose_envelope = rethrow_with_msg( + [&]() { return cose_cbor.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "Parse COSE tag"); - const auto& phdr_raw = rethrow_with_msg( - [&]() -> auto& { return cose_envelope->array_at(0); }, + const auto phdr_raw = rethrow_with_msg( + [&]() { return cose_envelope.array_at(0); }, "Parse raw protected header"); auto phdr = rethrow_with_msg( - [&]() { return parse(phdr_raw->as_bytes()); }, "Parse protected header"); + [&]() { return nondet_parse(phdr_raw.as_bytes()); }, + "Parse protected header"); CcfCoseReceipt receipt; diff --git a/src/node/historical_queries_adapter.cpp b/src/node/historical_queries_adapter.cpp index 994cdcfb06c5..9f9d41b29956 100644 --- a/src/node/historical_queries_adapter.cpp +++ b/src/node/historical_queries_adapter.cpp @@ -7,17 +7,18 @@ #include "ccf/historical_queries_utils.h" #include "ccf/rpc_context.h" #include "ccf/service/tables/service.h" -#include "crypto/cbor.h" #include "crypto/cose.h" #include "kv/kv_types.h" #include "node/rpc/network_identity_subsystem.h" #include "node/tx_receipt_impl.h" +#include + namespace { - ccf::cbor::Value encode_leaf_cbor(const ccf::TxReceiptImpl& receipt) + tav::cbor::Value encode_leaf_cbor(const ccf::TxReceiptImpl& receipt) { - using namespace ccf::cbor; + using namespace tav::cbor; std::vector items; // 1 WSD @@ -40,9 +41,9 @@ namespace return make_array(std::move(items)); } - ccf::cbor::Value encode_path_cbor(const ccf::HistoryTree::Path& path) + tav::cbor::Value encode_path_cbor(const ccf::HistoryTree::Path& path) { - using namespace ccf::cbor; + using namespace tav::cbor; std::vector items; for (const auto& node : path) @@ -244,7 +245,7 @@ namespace ccf return std::nullopt; } - using namespace ccf::cbor; + using namespace tav::cbor; std::vector proof; proof.emplace_back( @@ -256,7 +257,7 @@ namespace ccf encode_path_cbor(*receipt.path)); auto proof_map = make_map(std::move(proof)); - return serialize(proof_map); + return proof_map.nondet_serialize(); } std::optional describe_cose_endorsements_v1( diff --git a/src/node/quote.cpp b/src/node/quote.cpp index 38246d01f549..03ef0db0b30e 100644 --- a/src/node/quote.cpp +++ b/src/node/quote.cpp @@ -16,11 +16,14 @@ #include "ccf/service/tables/tcb_verification.h" #include "ccf/service/tables/uvm_endorsements.h" #include "ccf/service/tables/virtual_measurements.h" +#include "crypto/cbor_helpers.h" #include "crypto/cose_utils.h" #include "ds/internal_logger.h" #include "node/js_policy.h" #include "node/uvm_endorsements.h" +#include + namespace ccf { bool verify_enclave_measurement_against_uvm_endorsements( @@ -346,13 +349,13 @@ namespace ccf // Verify the COSE_Sign1 signature and that the payload matches the // expected host_data. Returns the decoded protected header on success. cose::Sign1ProtectedHeader verify_ts_signature_and_payload( - const ccf::cbor::Value& cose_array, const HostData& host_data) + const tav::cbor::Value& cose_array, const HostData& host_data) { - const auto& phdr_raw = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { return cose_array->array_at(0); }, + const auto& phdr_raw = tav::cbor::rethrow_with_msg( + [&]() { return cose_array.array_at(0); }, "COSE_Sign1 protected header"); - auto phdr_cbor = ccf::cbor::rethrow_with_msg( - [&]() { return ccf::cbor::parse(phdr_raw->as_bytes()); }, + auto phdr_cbor = tav::cbor::rethrow_with_msg( + [&]() { return tav::cbor::nondet_parse(phdr_raw.as_bytes()); }, "Parse protected header"); auto h = cose::decode_sign1_protected_header(phdr_cbor); @@ -373,15 +376,15 @@ namespace ccf auto pubk = resolve_pubkey_from_x5chain_and_issuer(h.x5chain, h.cwt.iss); auto verifier = ccf::crypto::make_cose_verifier_from_key(pubk); - auto payload = ccf::cbor::rethrow_with_msg( - [&]() { return cose_array->array_at(2)->as_bytes(); }, + auto payload = tav::cbor::rethrow_with_msg( + [&]() { return cose_array.array_at(2).as_bytes(); }, "COSE_Sign1 payload"); - auto sig_bytes = ccf::cbor::rethrow_with_msg( - [&]() { return cose_array->array_at(3)->as_bytes(); }, + auto sig_bytes = tav::cbor::rethrow_with_msg( + [&]() { return cose_array.array_at(3).as_bytes(); }, "COSE_Sign1 signature"); if (!verifier->verify_decomposed( - phdr_raw->as_bytes(), payload, sig_bytes, h.alg)) + phdr_raw.as_bytes(), payload, sig_bytes, h.alg)) { throw std::logic_error( "Transparent statement signature verification failed"); @@ -404,22 +407,22 @@ namespace ccf // Returns the collected policy inputs for each receipt. std::vector verify_ts_receipts( const std::vector& ts_raw, - const ccf::cbor::Value& cose_array, + const tav::cbor::Value& cose_array, std::shared_ptr network_identity_subsystem) { - const auto& uhdr = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { return cose_array->array_at(1); }, + const auto& uhdr = tav::cbor::rethrow_with_msg( + [&]() { return cose_array.array_at(1); }, "Parse transparent statement unprotected header"); - const auto& receipts_array = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { - return uhdr->map_at( - ccf::cbor::make_signed(ccf::cose::header::iana::VDP)); + const auto& receipts_array = tav::cbor::rethrow_with_msg( + [&]() { + return uhdr.map_at( + tav::cbor::make_signed(ccf::cose::header::iana::VDP)); }, "Parse receipts array from unprotected header"); - const auto num_receipts = receipts_array->size(); + const auto num_receipts = receipts_array.size(); if (num_receipts == 0) { throw std::logic_error("No receipts in transparent statement"); @@ -440,30 +443,28 @@ namespace ccf for (size_t i = 0; i < num_receipts; ++i) { - const auto& receipt_bytes = ccf::cbor::rethrow_with_msg( - [&]() { return receipts_array->array_at(i)->as_bytes(); }, + const auto& receipt_bytes = tav::cbor::rethrow_with_msg( + [&]() { return receipts_array.array_at(i).as_bytes(); }, fmt::format("Extract receipt {} from array", i)); std::vector receipt_raw( receipt_bytes.begin(), receipt_bytes.end()); - auto receipt_cbor = ccf::cbor::rethrow_with_msg( - [&]() { return ccf::cbor::parse(receipt_raw); }, + auto receipt_cbor = tav::cbor::rethrow_with_msg( + [&]() { return tav::cbor::nondet_parse(receipt_raw); }, fmt::format("Parse receipt {} COSE envelope", i)); - const auto& receipt_envelope = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { - return receipt_cbor->tag_at(ccf::cbor::tag::COSE_SIGN_1); - }, + const auto& receipt_envelope = tav::cbor::rethrow_with_msg( + [&]() { return receipt_cbor.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, fmt::format("Parse receipt {} COSE_Sign1 tag", i)); - auto receipt_phdr_raw = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { - return receipt_envelope->array_at(0); - }, + auto receipt_phdr_raw = tav::cbor::rethrow_with_msg( + [&]() { return receipt_envelope.array_at(0); }, fmt::format("Parse receipt {} protected header bytes", i)); - auto receipt_phdr_cbor = ccf::cbor::rethrow_with_msg( - [&]() { return ccf::cbor::parse(receipt_phdr_raw->as_bytes()); }, + auto receipt_phdr_cbor = tav::cbor::rethrow_with_msg( + [&]() { + return tav::cbor::nondet_parse(receipt_phdr_raw.as_bytes()); + }, fmt::format("Decode receipt {} protected header", i)); auto decoded_receipt_phdr = cose::decode_ccf_receipt_phdr(receipt_phdr_cbor); @@ -560,14 +561,12 @@ namespace ccf { try { - auto parsed = ccf::cbor::rethrow_with_msg( - [&]() { return ccf::cbor::parse(ts_raw); }, + auto parsed = tav::cbor::rethrow_with_msg( + [&]() { return tav::cbor::nondet_parse(ts_raw); }, "Transparent statement COSE envelope"); - const auto& cose_array = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { - return parsed->tag_at(ccf::cbor::tag::COSE_SIGN_1); - }, + const auto& cose_array = tav::cbor::rethrow_with_msg( + [&]() { return parsed.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "COSE_Sign1 tag"); auto phdr = verify_ts_signature_and_payload(cose_array, host_data); diff --git a/src/node/test/endorsements.cpp b/src/node/test/endorsements.cpp index 6c2cb6ddf0e2..8fd8856a6d96 100644 --- a/src/node/test/endorsements.cpp +++ b/src/node/test/endorsements.cpp @@ -2,11 +2,14 @@ // Licensed under the Apache 2.0 License. #include "ccf/pal/measurement.h" -#include "crypto/cbor.h" +#include "crypto/cbor_helpers.h" +#include "crypto/cbor_tags.h" #include "crypto/openssl/hash.h" #include "ds/files.h" #include "node/uvm_endorsements.h" +#include + #define DOCTEST_CONFIG_IMPLEMENT #include #include @@ -179,20 +182,30 @@ TEST_CASE("Check Test endorsement for UVM 0.2.10") REQUIRE(endorsements.feed == ccf::default_uvm_roots_of_trust[0].feed); REQUIRE(endorsements.svn == "104"); - auto parsed = ccf::cbor::parse(endorsement); - const auto& cose_sign1 = parsed->tag_at(ccf::cbor::tag::COSE_SIGN_1); - const auto& protected_header_raw = cose_sign1->array_at(0); - auto protected_header = ccf::cbor::parse(protected_header_raw->as_bytes()); - const auto& cwt_claims = protected_header->map_at( - ccf::cbor::make_signed(ccf::cose::header::iana::CWT_CLAIMS)); - const auto& iat = - cwt_claims->map_at(ccf::cbor::make_signed(ccf::cwt::header::iana::IAT)); - iat->value = ccf::cbor::Tagged{ - ccf::cbor::tag::EPOCH_DATE_TIME, ccf::cbor::make_signed(0)}; - - auto protected_header_bytes = ccf::cbor::serialize(protected_header); - protected_header_raw->value = ccf::cbor::Bytes{protected_header_bytes}; - auto invalid_iat_endorsement = ccf::cbor::serialize(parsed); + const auto parsed = tav::cbor::nondet_parse(endorsement); + const auto cose_sign1 = parsed.tag_at(ccf::cbor::tag::COSE_SIGN_1); + const auto protected_header_raw = cose_sign1.array_at(0); + const auto protected_header = + tav::cbor::nondet_parse(protected_header_raw.as_bytes()); + const auto cwt_claims = protected_header.map_at( + tav::cbor::make_signed(ccf::cose::header::iana::CWT_CLAIMS)); + + auto edited_claims = ccf::cbor::with_entry( + cwt_claims, + ccf::cwt::header::iana::IAT, + tav::cbor::make_tagged( + ccf::cbor::tag::EPOCH_DATE_TIME, tav::cbor::make_signed(0))); + const auto edited_header = ccf::cbor::with_entry( + protected_header, + ccf::cose::header::iana::CWT_CLAIMS, + std::move(edited_claims)); + + const auto protected_header_bytes = edited_header.nondet_serialize(); + auto edited_sign1 = ccf::cbor::with_element( + cose_sign1, 0, tav::cbor::make_bytes(protected_header_bytes)); + const auto edited_envelope = tav::cbor::make_tagged( + ccf::cbor::tag::COSE_SIGN_1, std::move(edited_sign1)); + auto invalid_iat_endorsement = edited_envelope.nondet_serialize(); REQUIRE_THROWS_WITH_AS( ccf::verify_uvm_endorsements_against_roots_of_trust( diff --git a/src/node/test/historical_queries.cpp b/src/node/test/historical_queries.cpp index cab8ee200136..c90dac444242 100644 --- a/src/node/test/historical_queries.cpp +++ b/src/node/test/historical_queries.cpp @@ -10,8 +10,10 @@ #include "ccf/crypto/rsa_key_pair.h" #include "ccf/ds/locking.h" #include "ccf/receipt.h" -#include "crypto/cbor.h" +#include "crypto/cbor_helpers.h" +#include "crypto/cbor_tags.h" #include "crypto/openssl/hash.h" +#include "crypto/test/cbor_printer.h" #include "ds/messaging.h" #include "ds/test/stub_writer.h" #include "kv/test/null_encryptor.h" @@ -21,6 +23,7 @@ #include #include +#include #define DOCTEST_CONFIG_IMPLEMENT #include @@ -268,32 +271,32 @@ MerkleProofData decode_merkle_proof(const std::vector& encoded) { MerkleProofData data; - auto decoded = ccf::cbor::parse(encoded); + auto decoded = tav::cbor::nondet_parse(encoded); - const auto& leaf = decoded->map_at( - ccf::cbor::make_signed(ccf::MerkleProofLabel::MERKLE_PROOF_LEAF_LABEL)); + const auto& leaf = decoded.map_at( + tav::cbor::make_signed(ccf::MerkleProofLabel::MERKLE_PROOF_LEAF_LABEL)); - REQUIRE_EQ(leaf->size(), 3); + REQUIRE_EQ(leaf.size(), 3); - const auto& wsd = leaf->array_at(0)->as_bytes(); + const auto& wsd = leaf.array_at(0).as_bytes(); data.write_set_digest.assign(wsd.begin(), wsd.end()); - data.commit_evidence = leaf->array_at(1)->as_string(); + data.commit_evidence = leaf.array_at(1).as_string(); - const auto& cd = leaf->array_at(2)->as_bytes(); + const auto& cd = leaf.array_at(2).as_bytes(); data.claims_digest.assign(cd.begin(), cd.end()); - const auto& path = decoded->map_at( - ccf::cbor::make_signed(ccf::MerkleProofLabel::MERKLE_PROOF_PATH_LABEL)); + const auto& path = decoded.map_at( + tav::cbor::make_signed(ccf::MerkleProofLabel::MERKLE_PROOF_PATH_LABEL)); - for (size_t i = 0; i < path->size(); i++) + for (size_t i = 0; i < path.size(); i++) { - const auto& node = path->array_at(i); - const auto& dir = node->array_at(0)->as_simple(); - const auto& hash = node->array_at(1)->as_bytes(); + const auto& node = path.array_at(i); + const auto& dir = node.array_at(0).as_simple(); + const auto& hash = node.array_at(1).as_bytes(); MerkleProofData::PathItem item; - item.first = ccf::cbor::simple_to_boolean(dir); + item.first = tav::cbor::simple_to_boolean(dir); item.second.assign(hash.begin(), hash.end()); data.path.push_back(item); } diff --git a/src/node/uvm_endorsements.cpp b/src/node/uvm_endorsements.cpp index 4b1e82a63a66..f0eedcd872e0 100644 --- a/src/node/uvm_endorsements.cpp +++ b/src/node/uvm_endorsements.cpp @@ -4,10 +4,13 @@ #include "node/uvm_endorsements.h" #include "ccf/ds/json.h" -#include "crypto/cbor.h" +#include "crypto/cbor_helpers.h" +#include "crypto/cbor_tags.h" #include "crypto/cose_utils.h" #include "ds/internal_logger.h" +#include + namespace ccf { size_t parse_svn(const std::string& svn_str) @@ -45,67 +48,63 @@ namespace ccf UvmEndorsementsProtectedHeader decode_protected_header( std::span raw_endorsements) { - auto parsed = ccf::cbor::rethrow_with_msg( - [&]() { return ccf::cbor::parse(raw_endorsements); }, + auto parsed = tav::cbor::rethrow_with_msg( + [&]() { return tav::cbor::nondet_parse(raw_endorsements); }, "UVM endorsements COSE envelope"); - const auto& cose_array = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { - return parsed->tag_at(ccf::cbor::tag::COSE_SIGN_1); - }, + const auto& cose_array = tav::cbor::rethrow_with_msg( + [&]() { return parsed.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "COSE_Sign1 tag"); constexpr std::string_view phdr_context{"COSE_Sign1[0]"}; - const auto& phdr_bytes = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { return cose_array->array_at(0); }, - phdr_context); - auto phdr_bytes_span = ccf::cbor::rethrow_with_msg( - [&]() { return phdr_bytes->as_bytes(); }, phdr_context); - auto parsed_phdr = ccf::cbor::rethrow_with_msg( - [&]() { return ccf::cbor::parse(phdr_bytes_span); }, + const auto& phdr_bytes = tav::cbor::rethrow_with_msg( + [&]() { return cose_array.array_at(0); }, phdr_context); + auto phdr_bytes_span = tav::cbor::rethrow_with_msg( + [&]() { return phdr_bytes.as_bytes(); }, phdr_context); + auto parsed_phdr = tav::cbor::rethrow_with_msg( + [&]() { return tav::cbor::nondet_parse(phdr_bytes_span); }, "Parse protected header in UVM endorsements"); UvmEndorsementsProtectedHeader result; - result.alg = ccf::cbor::rethrow_with_msg( + result.alg = tav::cbor::rethrow_with_msg( [&]() { - return parsed_phdr - ->map_at(ccf::cbor::make_signed(header::iana::ALG)) - ->as_signed(); + return parsed_phdr.map_at(tav::cbor::make_signed(header::iana::ALG)) + .as_signed(); }, fmt::format( "Parse alg ({}) in protected header in UVM endorsements", header::iana::ALG)); - result.content_type = ccf::cbor::rethrow_with_msg( + result.content_type = tav::cbor::rethrow_with_msg( [&]() { return std::string( parsed_phdr - ->map_at(ccf::cbor::make_signed(header::iana::CONTENT_TYPE)) - ->as_string()); + .map_at(tav::cbor::make_signed(header::iana::CONTENT_TYPE)) + .as_string()); }, fmt::format( "Parse content-type ({}) in protected header in UVM endorsements", header::iana::CONTENT_TYPE)); - result.x5_chain = ccf::cbor::rethrow_with_msg( + result.x5_chain = tav::cbor::rethrow_with_msg( [&]() { - return utils::parse_x5chain(parsed_phdr->map_at( - ccf::cbor::make_signed(header::iana::X5CHAIN))); + return utils::parse_x5chain(parsed_phdr.map_at( + tav::cbor::make_signed(header::iana::X5CHAIN))); }, fmt::format( "Parse x5chain ({}) in protected header in UVM endorsements", header::iana::X5CHAIN)); - result.iss = ccf::cbor::rethrow_with_msg( + result.iss = tav::cbor::rethrow_with_msg( [&]() { - return parsed_phdr->map_at(ccf::cbor::make_string("iss")) - ->as_string(); + return parsed_phdr.map_at(tav::cbor::make_string("iss")) + .as_string(); }, "Parse iss in protected header in UVM endorsements"); - result.feed = ccf::cbor::rethrow_with_msg( + result.feed = tav::cbor::rethrow_with_msg( [&]() { return std::string( - parsed_phdr->map_at(ccf::cbor::make_string("feed"))->as_string()); + parsed_phdr.map_at(tav::cbor::make_string("feed")).as_string()); }, "Parse feed in protected header in UVM endorsements"); @@ -116,53 +115,49 @@ namespace ccf decode_protected_header_with_cwt( std::span raw_endorsements) { - auto parsed = ccf::cbor::rethrow_with_msg( - [&]() { return ccf::cbor::parse(raw_endorsements); }, + auto parsed = tav::cbor::rethrow_with_msg( + [&]() { return tav::cbor::nondet_parse(raw_endorsements); }, "COSE envelope"); - const auto& cose_array = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { - return parsed->tag_at(ccf::cbor::tag::COSE_SIGN_1); - }, + const auto& cose_array = tav::cbor::rethrow_with_msg( + [&]() { return parsed.tag_at(ccf::cbor::tag::COSE_SIGN_1); }, "COSE_Sign1 tag"); constexpr std::string_view phdr_context{"COSE_Sign1[0]"}; - const auto& phdr_bytes = ccf::cbor::rethrow_with_msg( - [&]() -> const ccf::cbor::Value& { return cose_array->array_at(0); }, - phdr_context); - auto phdr_bytes_span = ccf::cbor::rethrow_with_msg( - [&]() { return phdr_bytes->as_bytes(); }, phdr_context); - - auto parsed_phdr = ccf::cbor::rethrow_with_msg( - [&]() { return ccf::cbor::parse(phdr_bytes_span); }, + const auto& phdr_bytes = tav::cbor::rethrow_with_msg( + [&]() { return cose_array.array_at(0); }, phdr_context); + auto phdr_bytes_span = tav::cbor::rethrow_with_msg( + [&]() { return phdr_bytes.as_bytes(); }, phdr_context); + + auto parsed_phdr = tav::cbor::rethrow_with_msg( + [&]() { return tav::cbor::nondet_parse(phdr_bytes_span); }, "Parse protected header in UVM endorsements"); UvmEndorsementsProtectedHeader result; - result.alg = ccf::cbor::rethrow_with_msg( + result.alg = tav::cbor::rethrow_with_msg( [&]() { - return parsed_phdr - ->map_at(ccf::cbor::make_signed(header::iana::ALG)) - ->as_signed(); + return parsed_phdr.map_at(tav::cbor::make_signed(header::iana::ALG)) + .as_signed(); }, fmt::format( "Parse alg ({}) in protected header in UVM endorsements", header::iana::ALG)); - result.content_type = ccf::cbor::rethrow_with_msg( + result.content_type = tav::cbor::rethrow_with_msg( [&]() { return std::string(parsed_phdr - ->map_at(ccf::cbor::make_signed( + .map_at(tav::cbor::make_signed( header::iana::PREIMAGE_CONTENT_TYPE)) - ->as_string()); + .as_string()); }, fmt::format( "Parse content-type ({}) in protected header in UVM endorsements", header::iana::PREIMAGE_CONTENT_TYPE)); - result.x5_chain = ccf::cbor::rethrow_with_msg( + result.x5_chain = tav::cbor::rethrow_with_msg( [&]() { - return utils::parse_x5chain(parsed_phdr->map_at( - ccf::cbor::make_signed(header::iana::X5CHAIN))); + return utils::parse_x5chain(parsed_phdr.map_at( + tav::cbor::make_signed(header::iana::X5CHAIN))); }, fmt::format( "Parse x5chain ({}) in protected header in UVM endorsements", @@ -175,8 +170,8 @@ namespace ccf if (!cwt_claims.svn.has_value()) { - throw ccf::cbor::CBORDecodeError( - ccf::cbor::Error::KEY_NOT_FOUND, "No CWT svn in UVM endorsements"); + throw tav::cbor::DecodeError( + tav::cbor::Error::KEY_NOT_FOUND, "No CWT svn in UVM endorsements"); } validate_cwt_iat_against_x5chain( @@ -219,7 +214,7 @@ namespace ccf } // Since ContainerPlat 0.2.10, UVM endorsements carry SVN in CWT claims, // alongside ISS and SUB(feed), so on decoding failure fallback to legacy. - catch (const ccf::cbor::CBORDecodeError&) + catch (const tav::cbor::DecodeError&) { phdr = cose::decode_protected_header(uvm_endorsements_raw); } diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index c11b3e2a122c..df0d51c3bf88 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -2,6 +2,18 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "bitflags" +version = "2.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + [[package]] name = "cborrs" version = "0.1.0" @@ -27,15 +39,21 @@ name = "ccf-rs" version = "0.1.0" dependencies = [ "cose-rs", + "tee-attestation-verification-ffi", ] +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + [[package]] name = "cose-openssl" version = "0.1.0" dependencies = [ - "cborrs", - "cborrs-nondet", "openssl-sys", + "tee-attestation-verification-cbor", ] [[package]] @@ -51,17 +69,116 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + [[package]] name = "libc" version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "openssl" +version = "0.10.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "openssl-sys" -version = "0.9.112" +version = "0.9.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d55af3b3e226502be1526dfdba67ab0e9c96fc293004e79576b2b9edb0dbdb" +checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695" dependencies = [ "cc", "libc", @@ -69,20 +186,271 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + [[package]] name = "pkg-config" version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tee-attestation-verification-caci" +version = "1.0.8" +dependencies = [ + "serde_json", + "tee-attestation-verification-cose", + "tee-attestation-verification-crypto", + "tee-attestation-verification-lib", +] + +[[package]] +name = "tee-attestation-verification-cbor" +version = "1.0.8" +dependencies = [ + "cborrs", + "cborrs-nondet", +] + +[[package]] +name = "tee-attestation-verification-cose" +version = "1.0.8" +dependencies = [ + "tee-attestation-verification-cbor", + "tee-attestation-verification-crypto", +] + +[[package]] +name = "tee-attestation-verification-crypto" +version = "1.0.8" +dependencies = [ + "foreign-types-shared", + "js-sys", + "openssl", + "openssl-sys", + "wasm-bindgen", + "wasm-bindgen-futures", +] + +[[package]] +name = "tee-attestation-verification-ffi" +version = "1.0.8" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "tee-attestation-verification-caci", + "tee-attestation-verification-cbor", + "tee-attestation-verification-cose", + "tee-attestation-verification-crypto", + "tee-attestation-verification-lib", + "wasm-bindgen", + "wasm-bindgen-futures", + "zerocopy", +] + +[[package]] +name = "tee-attestation-verification-lib" +version = "1.0.8" +dependencies = [ + "log", + "tee-attestation-verification-crypto", + "zerocopy", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "wasm-bindgen" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b7777d5cc23d0e91404e53ce2d5e8ec7acae3026b16233dba62cd3246457950" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.119", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "zerocopy" +version = "0.8.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556764e583adb45a9f8d413c2a147fa7e8d821e48e12b14fd560b607998b75eb" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ab42fc20575779bd240faa45f94a74256f755c0fa9e89f0ede20d91d0cdfc1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml index 06c5c8d89a51..8aa4c2a59c9f 100644 --- a/src/rust/Cargo.toml +++ b/src/rust/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" crate-type = ["staticlib"] [dependencies] +tav-ffi = { package = "tee-attestation-verification-ffi", path = "../../3rdparty/internal/tee-attestation-verification/ffi", default-features = false, features = ["crypto_openssl"] } cose-rs = { path = "../cose/cose_rs" } [profile.release] diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index 83a1476d5c74..297f3d0c4fae 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -1,4 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the Apache 2.0 License. +pub use tav_ffi; pub use cose_rs;