|
| 1 | +/- Copyright 2026 The Fuchsia Authors |
| 2 | +
|
| 3 | +Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 |
| 4 | +<LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
| 5 | +license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
| 6 | +This file may not be copied, modified, or distributed except according to |
| 7 | +those terms. -/ |
| 8 | + |
| 9 | +module |
| 10 | +public import Zerocopy |
| 11 | +@[expose] public section |
| 12 | + |
| 13 | +open Aeneas Aeneas.Std |
| 14 | +namespace Zerocopy.Obligations |
| 15 | + |
| 16 | +/- These byteorder expectations retain the raw input domain. Readers must |
| 17 | +return the positional base-256 value; writers must return every numeric byte, |
| 18 | +including zeros. They deliberately use explicit digit arithmetic rather than |
| 19 | +invoking the authored specification's shared decoder or encoder. -/ |
| 20 | + |
| 21 | +def read_u16_le_spec_contract (bytes : Aeneas.Std.Array U8 2#usize) |
| 22 | + (run : Result (U16)) : Prop := |
| 23 | + run ⦃ output => output.val = bytes.val[0]!.val + 256 * (bytes.val[1]!.val) ⦄ |
| 24 | + |
| 25 | +def read_u16_le_spec : Prop := |
| 26 | + ∀ (bytes : Aeneas.Std.Array U8 2#usize), read_u16_le_spec_contract bytes |
| 27 | + (byteorder.verification.read_u16_le bytes) |
| 28 | + |
| 29 | +def write_u16_le_spec_contract (n : U16) |
| 30 | + (run : Result (Aeneas.Std.Array U8 2#usize)) : Prop := |
| 31 | + run ⦃ output => output.val.map UScalar.val = [n.val % 256, n.val / 256 % 256] ⦄ |
| 32 | + |
| 33 | +def write_u16_le_spec : Prop := |
| 34 | + ∀ (n : U16), write_u16_le_spec_contract n |
| 35 | + (byteorder.verification.write_u16_le n) |
| 36 | + |
| 37 | +def set_u16_le_spec_contract (_bytes : Aeneas.Std.Array U8 2#usize) (n : U16) |
| 38 | + (run : Result (U16)) : Prop := |
| 39 | + run ⦃ output => output = n ⦄ |
| 40 | + |
| 41 | +def set_u16_le_spec : Prop := |
| 42 | + ∀ (bytes : Aeneas.Std.Array U8 2#usize) (n : U16), set_u16_le_spec_contract bytes n |
| 43 | + (byteorder.verification.set_u16_le bytes n) |
| 44 | + |
| 45 | +def read_u16_be_spec_contract (bytes : Aeneas.Std.Array U8 2#usize) |
| 46 | + (run : Result (U16)) : Prop := |
| 47 | + run ⦃ output => output.val = bytes.val[1]!.val + 256 * (bytes.val[0]!.val) ⦄ |
| 48 | + |
| 49 | +def read_u16_be_spec : Prop := |
| 50 | + ∀ (bytes : Aeneas.Std.Array U8 2#usize), read_u16_be_spec_contract bytes |
| 51 | + (byteorder.verification.read_u16_be bytes) |
| 52 | + |
| 53 | +def write_u16_be_spec_contract (n : U16) |
| 54 | + (run : Result (Aeneas.Std.Array U8 2#usize)) : Prop := |
| 55 | + run ⦃ output => output.val.map UScalar.val = [n.val / 256 % 256, n.val % 256] ⦄ |
| 56 | + |
| 57 | +def write_u16_be_spec : Prop := |
| 58 | + ∀ (n : U16), write_u16_be_spec_contract n |
| 59 | + (byteorder.verification.write_u16_be n) |
| 60 | + |
| 61 | +def set_u16_be_spec_contract (_bytes : Aeneas.Std.Array U8 2#usize) (n : U16) |
| 62 | + (run : Result (U16)) : Prop := |
| 63 | + run ⦃ output => output = n ⦄ |
| 64 | + |
| 65 | +def set_u16_be_spec : Prop := |
| 66 | + ∀ (bytes : Aeneas.Std.Array U8 2#usize) (n : U16), set_u16_be_spec_contract bytes n |
| 67 | + (byteorder.verification.set_u16_be bytes n) |
| 68 | + |
| 69 | +def read_u32_le_spec_contract (bytes : Aeneas.Std.Array U8 4#usize) |
| 70 | + (run : Result (U32)) : Prop := |
| 71 | + run ⦃ output => output.val = bytes.val[0]!.val + 256 * (bytes.val[1]!.val + 256 * (bytes.val[2]!.val + 256 * (bytes.val[3]!.val))) ⦄ |
| 72 | + |
| 73 | +def read_u32_le_spec : Prop := |
| 74 | + ∀ (bytes : Aeneas.Std.Array U8 4#usize), read_u32_le_spec_contract bytes |
| 75 | + (byteorder.verification.read_u32_le bytes) |
| 76 | + |
| 77 | +def write_u32_le_spec_contract (n : U32) |
| 78 | + (run : Result (Aeneas.Std.Array U8 4#usize)) : Prop := |
| 79 | + run ⦃ output => output.val.map UScalar.val = [n.val % 256, n.val / 256 % 256, n.val / 65536 % 256, n.val / 16777216 % 256] ⦄ |
| 80 | + |
| 81 | +def write_u32_le_spec : Prop := |
| 82 | + ∀ (n : U32), write_u32_le_spec_contract n |
| 83 | + (byteorder.verification.write_u32_le n) |
| 84 | + |
| 85 | +def set_u32_le_spec_contract (_bytes : Aeneas.Std.Array U8 4#usize) (n : U32) |
| 86 | + (run : Result (U32)) : Prop := |
| 87 | + run ⦃ output => output = n ⦄ |
| 88 | + |
| 89 | +def set_u32_le_spec : Prop := |
| 90 | + ∀ (bytes : Aeneas.Std.Array U8 4#usize) (n : U32), set_u32_le_spec_contract bytes n |
| 91 | + (byteorder.verification.set_u32_le bytes n) |
| 92 | + |
| 93 | +def read_u32_be_spec_contract (bytes : Aeneas.Std.Array U8 4#usize) |
| 94 | + (run : Result (U32)) : Prop := |
| 95 | + run ⦃ output => output.val = bytes.val[3]!.val + 256 * (bytes.val[2]!.val + 256 * (bytes.val[1]!.val + 256 * (bytes.val[0]!.val))) ⦄ |
| 96 | + |
| 97 | +def read_u32_be_spec : Prop := |
| 98 | + ∀ (bytes : Aeneas.Std.Array U8 4#usize), read_u32_be_spec_contract bytes |
| 99 | + (byteorder.verification.read_u32_be bytes) |
| 100 | + |
| 101 | +def write_u32_be_spec_contract (n : U32) |
| 102 | + (run : Result (Aeneas.Std.Array U8 4#usize)) : Prop := |
| 103 | + run ⦃ output => output.val.map UScalar.val = [n.val / 16777216 % 256, n.val / 65536 % 256, n.val / 256 % 256, n.val % 256] ⦄ |
| 104 | + |
| 105 | +def write_u32_be_spec : Prop := |
| 106 | + ∀ (n : U32), write_u32_be_spec_contract n |
| 107 | + (byteorder.verification.write_u32_be n) |
| 108 | + |
| 109 | +def set_u32_be_spec_contract (_bytes : Aeneas.Std.Array U8 4#usize) (n : U32) |
| 110 | + (run : Result (U32)) : Prop := |
| 111 | + run ⦃ output => output = n ⦄ |
| 112 | + |
| 113 | +def set_u32_be_spec : Prop := |
| 114 | + ∀ (bytes : Aeneas.Std.Array U8 4#usize) (n : U32), set_u32_be_spec_contract bytes n |
| 115 | + (byteorder.verification.set_u32_be bytes n) |
| 116 | + |
| 117 | +end Zerocopy.Obligations |
0 commit comments