Skip to main content

vest_lib/combinators/sints/
spec.rs

1//! Specifications for fixed-width signed integers.
2use crate::combinators::bytes::spec::*;
3use crate::combinators::mapped::spec::{FnSpecMapper, LosslessMapper, LossyMapper, SpecMapper};
4use crate::combinators::uints::spec::*;
5use crate::combinators::{Fixed, Mapped};
6use crate::core::{proof::*, spec::*};
7use vstd::prelude::*;
8
9verus! {
10
11pub const U8_BYTE_LEN: usize = 1;
12
13pub const U16_BYTE_LEN: usize = 2;
14
15pub const U32_BYTE_LEN: usize = 4;
16
17pub const U64_BYTE_LEN: usize = 8;
18
19pub type I8Fmt = Mapped<Fixed<1>, FnSpecMapper<Seq<u8>, i8>>;
20
21pub type I16LeFmt = Mapped<Fixed<2>, FnSpecMapper<Seq<u8>, i16>>;
22
23pub type I16BeFmt = Mapped<Fixed<2>, FnSpecMapper<Seq<u8>, i16>>;
24
25pub type I32LeFmt = Mapped<Fixed<4>, FnSpecMapper<Seq<u8>, i32>>;
26
27pub type I32BeFmt = Mapped<Fixed<4>, FnSpecMapper<Seq<u8>, i32>>;
28
29pub type I64LeFmt = Mapped<Fixed<8>, FnSpecMapper<Seq<u8>, i64>>;
30
31pub type I64BeFmt = Mapped<Fixed<8>, FnSpecMapper<Seq<u8>, i64>>;
32
33pub open spec fn i8_fmt() -> I8Fmt {
34    Mapped { inner: Fixed::<1>, mapper: (|i: Seq<u8>| i[0] as i8, |o: i8| seq![o as u8]) }
35}
36
37pub open spec fn i16_le_fmt() -> I16LeFmt {
38    Mapped {
39        inner: Fixed::<2>,
40        mapper: (|i: Seq<u8>| i16_le_from_bytes(array_from_seq(i)), |o: i16| i16_le_to_bytes(o)@),
41    }
42}
43
44pub open spec fn i16_be_fmt() -> I16BeFmt {
45    Mapped {
46        inner: Fixed::<2>,
47        mapper: (|i: Seq<u8>| i16_be_from_bytes(array_from_seq(i)), |o: i16| i16_be_to_bytes(o)@),
48    }
49}
50
51pub open spec fn i32_le_fmt() -> I32LeFmt {
52    Mapped {
53        inner: Fixed::<4>,
54        mapper: (|i: Seq<u8>| i32_le_from_bytes(array_from_seq(i)), |o: i32| i32_le_to_bytes(o)@),
55    }
56}
57
58pub open spec fn i32_be_fmt() -> I32BeFmt {
59    Mapped {
60        inner: Fixed::<4>,
61        mapper: (|i: Seq<u8>| i32_be_from_bytes(array_from_seq(i)), |o: i32| i32_be_to_bytes(o)@),
62    }
63}
64
65pub open spec fn i64_le_fmt() -> I64LeFmt {
66    Mapped {
67        inner: Fixed::<8>,
68        mapper: (|i: Seq<u8>| i64_le_from_bytes(array_from_seq(i)), |o: i64| i64_le_to_bytes(o)@),
69    }
70}
71
72pub open spec fn i64_be_fmt() -> I64BeFmt {
73    Mapped {
74        inner: Fixed::<8>,
75        mapper: (|i: Seq<u8>| i64_be_from_bytes(array_from_seq(i)), |o: i64| i64_be_to_bytes(o)@),
76    }
77}
78
79pub broadcast proof fn lemma_i8_bytes_roundtrip(b: u8)
80    by (bit_vector)
81    ensures
82        #[trigger] ((b as i8) as u8) == b,
83{
84}
85
86pub broadcast proof fn lemma_i8_seq_roundtrip(i: Seq<u8>)
87    requires
88        i.len() == 1,
89    ensures
90        seq![(#[trigger] (i[0] as i8) as u8)] == i,
91{
92    broadcast use lemma_i8_bytes_roundtrip;
93
94}
95
96pub broadcast proof fn lemma_i8_value_roundtrip(o: i8)
97    by (bit_vector)
98    ensures
99        #[trigger] ((o as u8) as i8) == o,
100{
101}
102
103pub open spec fn i16_le_from_bytes(i: [u8; 2]) -> i16 {
104    u16_le_from_bytes(i) as i16
105}
106
107pub open spec fn i16_le_to_bytes(o: i16) -> [u8; 2] {
108    u16_le_to_bytes(o as u16)
109}
110
111pub broadcast proof fn lemma_i16_le_bytes_roundtrip(i: [u8; 2])
112    ensures
113        #[trigger] i16_le_to_bytes(i16_le_from_bytes(i)) == i,
114{
115    let x = u16_le_from_bytes(i);
116    lemma_u16_le_bytes_roundtrip(i);
117    assert(((x as i16) as u16) == x) by (bit_vector);
118}
119
120pub broadcast proof fn lemma_i16_le_value_roundtrip(o: i16)
121    ensures
122        #[trigger] i16_le_from_bytes(i16_le_to_bytes(o)) == o,
123{
124    lemma_u16_le_value_roundtrip(o as u16);
125    assert(((o as u16) as i16) == o) by (bit_vector);
126}
127
128pub open spec fn i16_be_from_bytes(i: [u8; 2]) -> i16 {
129    u16_be_from_bytes(i) as i16
130}
131
132pub open spec fn i16_be_to_bytes(o: i16) -> [u8; 2] {
133    u16_be_to_bytes(o as u16)
134}
135
136pub broadcast proof fn lemma_i16_be_bytes_roundtrip(i: [u8; 2])
137    ensures
138        #[trigger] i16_be_to_bytes(i16_be_from_bytes(i)) == i,
139{
140    let x = u16_be_from_bytes(i);
141    lemma_u16_be_bytes_roundtrip(i);
142    assert(((x as i16) as u16) == x) by (bit_vector);
143}
144
145pub broadcast proof fn lemma_i16_be_value_roundtrip(o: i16)
146    ensures
147        #[trigger] i16_be_from_bytes(i16_be_to_bytes(o)) == o,
148{
149    lemma_u16_be_value_roundtrip(o as u16);
150    assert(((o as u16) as i16) == o) by (bit_vector);
151}
152
153pub open spec fn i32_le_from_bytes(i: [u8; 4]) -> i32 {
154    u32_le_from_bytes(i) as i32
155}
156
157pub open spec fn i32_le_to_bytes(o: i32) -> [u8; 4] {
158    u32_le_to_bytes(o as u32)
159}
160
161pub broadcast proof fn lemma_i32_le_bytes_roundtrip(i: [u8; 4])
162    ensures
163        #[trigger] i32_le_to_bytes(i32_le_from_bytes(i)) == i,
164{
165    let x = u32_le_from_bytes(i);
166    lemma_u32_le_bytes_roundtrip(i);
167    assert(((x as i32) as u32) == x) by (bit_vector);
168}
169
170pub broadcast proof fn lemma_i32_le_value_roundtrip(o: i32)
171    ensures
172        #[trigger] i32_le_from_bytes(i32_le_to_bytes(o)) == o,
173{
174    lemma_u32_le_value_roundtrip(o as u32);
175    assert(((o as u32) as i32) == o) by (bit_vector);
176}
177
178pub open spec fn i32_be_from_bytes(i: [u8; 4]) -> i32 {
179    u32_be_from_bytes(i) as i32
180}
181
182pub open spec fn i32_be_to_bytes(o: i32) -> [u8; 4] {
183    u32_be_to_bytes(o as u32)
184}
185
186pub broadcast proof fn lemma_i32_be_bytes_roundtrip(i: [u8; 4])
187    ensures
188        #[trigger] i32_be_to_bytes(i32_be_from_bytes(i)) == i,
189{
190    let x = u32_be_from_bytes(i);
191    lemma_u32_be_bytes_roundtrip(i);
192    assert(((x as i32) as u32) == x) by (bit_vector);
193}
194
195pub broadcast proof fn lemma_i32_be_value_roundtrip(o: i32)
196    ensures
197        #[trigger] i32_be_from_bytes(i32_be_to_bytes(o)) == o,
198{
199    lemma_u32_be_value_roundtrip(o as u32);
200    assert(((o as u32) as i32) == o) by (bit_vector);
201}
202
203pub open spec fn i64_le_from_bytes(i: [u8; 8]) -> i64 {
204    u64_le_from_bytes(i) as i64
205}
206
207pub open spec fn i64_le_to_bytes(o: i64) -> [u8; 8] {
208    u64_le_to_bytes(o as u64)
209}
210
211pub broadcast proof fn lemma_i64_le_bytes_roundtrip(i: [u8; 8])
212    ensures
213        #[trigger] i64_le_to_bytes(i64_le_from_bytes(i)) == i,
214{
215    let x = u64_le_from_bytes(i);
216    lemma_u64_le_bytes_roundtrip(i);
217    assert(((x as i64) as u64) == x) by (bit_vector);
218}
219
220pub broadcast proof fn lemma_i64_le_value_roundtrip(o: i64)
221    ensures
222        #[trigger] i64_le_from_bytes(i64_le_to_bytes(o)) == o,
223{
224    lemma_u64_le_value_roundtrip(o as u64);
225    assert(((o as u64) as i64) == o) by (bit_vector);
226}
227
228pub open spec fn i64_be_from_bytes(i: [u8; 8]) -> i64 {
229    u64_be_from_bytes(i) as i64
230}
231
232pub open spec fn i64_be_to_bytes(o: i64) -> [u8; 8] {
233    u64_be_to_bytes(o as u64)
234}
235
236pub broadcast proof fn lemma_i64_be_bytes_roundtrip(i: [u8; 8])
237    ensures
238        #[trigger] i64_be_to_bytes(i64_be_from_bytes(i)) == i,
239{
240    let x = u64_be_from_bytes(i);
241    lemma_u64_be_bytes_roundtrip(i);
242    assert(((x as i64) as u64) == x) by (bit_vector);
243}
244
245pub broadcast proof fn lemma_i64_be_value_roundtrip(o: i64)
246    ensures
247        #[trigger] i64_be_from_bytes(i64_be_to_bytes(o)) == o,
248{
249    lemma_u64_be_value_roundtrip(o as u64);
250    assert(((o as u64) as i64) == o) by (bit_vector);
251}
252
253impl SpecParser for super::I8 {
254    type PVal = i8;
255
256    open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, i8)> {
257        i8_fmt().spec_parse(ibuf)
258    }
259}
260
261impl Consistency for super::I8 {
262    type Val = i8;
263
264    open spec fn consistent(&self, _v: Self::Val) -> bool {
265        true
266    }
267}
268
269impl SpecSerializerDps for super::I8 {
270    type SValue = i8;
271
272    open spec fn spec_serialize_dps(&self, v: i8, obuf: Seq<u8>) -> Seq<u8> {
273        i8_fmt().spec_serialize_dps(v, obuf)
274    }
275}
276
277impl SpecSerializer for super::I8 {
278    type SVal = i8;
279
280    open spec fn spec_serialize(&self, v: i8) -> Seq<u8> {
281        i8_fmt().spec_serialize(v)
282    }
283}
284
285impl SafeParser for super::I8 {
286    proof fn lemma_parse_safe(&self, ibuf: Seq<u8>) {
287        i8_fmt().lemma_parse_safe(ibuf);
288    }
289}
290
291impl SoundParser for super::I8 {
292    proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>) {
293        broadcast use lemma_i8_seq_roundtrip;
294
295        i8_fmt().lemma_parse_sound_consumption(ibuf);
296    }
297
298    proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>) {
299        broadcast use lemma_i8_seq_roundtrip;
300
301        i8_fmt().lemma_parse_sound_value(ibuf);
302    }
303}
304
305impl NonTailFmt for super::I8 {
306    proof fn lemma_serialize_dps_prepend(&self, v: i8, obuf: Seq<u8>) {
307        i8_fmt().lemma_serialize_dps_prepend(v, obuf);
308    }
309
310    proof fn lemma_serialize_dps_len(&self, v: i8, obuf: Seq<u8>) {
311        i8_fmt().lemma_serialize_dps_len(v, obuf);
312    }
313}
314
315impl GoodSerializer for super::I8 {
316    proof fn lemma_serialize_len(&self, v: i8) {
317        i8_fmt().lemma_serialize_len(v);
318    }
319}
320
321impl SpecByteLen for super::I8 {
322    type T = i8;
323
324    open spec fn byte_len(&self, _v: Self::T) -> nat {
325        U8_BYTE_LEN as nat
326    }
327}
328
329impl MinMaxByteLen for super::I8 {
330    open spec fn min(&self) -> nat {
331        U8_BYTE_LEN as nat
332    }
333
334    open spec fn max(&self) -> nat {
335        U8_BYTE_LEN as nat
336    }
337
338    proof fn lemma_min_max_byte_len(&self, v: Self::T) {
339    }
340}
341
342impl StaticByteLen for super::I8 {
343    open spec fn static_byte_len() -> nat {
344        U8_BYTE_LEN as nat
345    }
346
347    proof fn lemma_static_len_matches_byte_len(&self, v: Self::T) {
348    }
349}
350
351impl ValueByteLen for super::I8 {
352    open spec fn value_byte_len(_v: Self::T) -> nat {
353        U8_BYTE_LEN as nat
354    }
355
356    proof fn lemma_value_len_matches_byte_len(&self, v: Self::T) {
357    }
358}
359
360impl SpecParser for super::I16Le {
361    type PVal = i16;
362
363    open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, i16)> {
364        i16_le_fmt().spec_parse(ibuf)
365    }
366}
367
368impl Consistency for super::I16Le {
369    type Val = i16;
370
371    open spec fn consistent(&self, _v: Self::Val) -> bool {
372        true
373    }
374}
375
376impl SpecSerializerDps for super::I16Le {
377    type SValue = i16;
378
379    open spec fn spec_serialize_dps(&self, v: i16, obuf: Seq<u8>) -> Seq<u8> {
380        i16_le_fmt().spec_serialize_dps(v, obuf)
381    }
382}
383
384impl SpecSerializer for super::I16Le {
385    type SVal = i16;
386
387    open spec fn spec_serialize(&self, v: i16) -> Seq<u8> {
388        i16_le_fmt().spec_serialize(v)
389    }
390}
391
392impl SafeParser for super::I16Le {
393    proof fn lemma_parse_safe(&self, ibuf: Seq<u8>) {
394        i16_le_fmt().lemma_parse_safe(ibuf);
395    }
396}
397
398impl SoundParser for super::I16Le {
399    proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>) {
400        broadcast use axiom_array_from_seq;
401        broadcast use lemma_i16_le_bytes_roundtrip;
402
403        i16_le_fmt().lemma_parse_sound_consumption(ibuf);
404    }
405
406    proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>) {
407        broadcast use axiom_array_from_seq;
408        broadcast use lemma_i16_le_bytes_roundtrip;
409
410        i16_le_fmt().lemma_parse_sound_value(ibuf);
411    }
412}
413
414impl NonTailFmt for super::I16Le {
415    proof fn lemma_serialize_dps_prepend(&self, v: i16, obuf: Seq<u8>) {
416        i16_le_fmt().lemma_serialize_dps_prepend(v, obuf);
417    }
418
419    proof fn lemma_serialize_dps_len(&self, v: i16, obuf: Seq<u8>) {
420        i16_le_fmt().lemma_serialize_dps_len(v, obuf);
421    }
422}
423
424impl GoodSerializer for super::I16Le {
425    proof fn lemma_serialize_len(&self, v: i16) {
426        i16_le_fmt().lemma_serialize_len(v);
427    }
428}
429
430impl SpecByteLen for super::I16Le {
431    type T = i16;
432
433    open spec fn byte_len(&self, _v: Self::T) -> nat {
434        U16_BYTE_LEN as nat
435    }
436}
437
438impl MinMaxByteLen for super::I16Le {
439    open spec fn min(&self) -> nat {
440        U16_BYTE_LEN as nat
441    }
442
443    open spec fn max(&self) -> nat {
444        U16_BYTE_LEN as nat
445    }
446
447    proof fn lemma_min_max_byte_len(&self, v: Self::T) {
448    }
449}
450
451impl StaticByteLen for super::I16Le {
452    open spec fn static_byte_len() -> nat {
453        U16_BYTE_LEN as nat
454    }
455
456    proof fn lemma_static_len_matches_byte_len(&self, v: Self::T) {
457    }
458}
459
460impl ValueByteLen for super::I16Le {
461    open spec fn value_byte_len(_v: Self::T) -> nat {
462        U16_BYTE_LEN as nat
463    }
464
465    proof fn lemma_value_len_matches_byte_len(&self, v: Self::T) {
466    }
467}
468
469impl SpecParser for super::I16Be {
470    type PVal = i16;
471
472    open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, i16)> {
473        i16_be_fmt().spec_parse(ibuf)
474    }
475}
476
477impl Consistency for super::I16Be {
478    type Val = i16;
479
480    open spec fn consistent(&self, _v: Self::Val) -> bool {
481        true
482    }
483}
484
485impl SpecSerializerDps for super::I16Be {
486    type SValue = i16;
487
488    open spec fn spec_serialize_dps(&self, v: i16, obuf: Seq<u8>) -> Seq<u8> {
489        i16_be_fmt().spec_serialize_dps(v, obuf)
490    }
491}
492
493impl SpecSerializer for super::I16Be {
494    type SVal = i16;
495
496    open spec fn spec_serialize(&self, v: i16) -> Seq<u8> {
497        i16_be_fmt().spec_serialize(v)
498    }
499}
500
501impl SafeParser for super::I16Be {
502    proof fn lemma_parse_safe(&self, ibuf: Seq<u8>) {
503        i16_be_fmt().lemma_parse_safe(ibuf);
504    }
505}
506
507impl SoundParser for super::I16Be {
508    proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>) {
509        broadcast use axiom_array_from_seq;
510        broadcast use lemma_i16_be_bytes_roundtrip;
511
512        i16_be_fmt().lemma_parse_sound_consumption(ibuf);
513    }
514
515    proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>) {
516        broadcast use axiom_array_from_seq;
517        broadcast use lemma_i16_be_bytes_roundtrip;
518
519        i16_be_fmt().lemma_parse_sound_value(ibuf);
520    }
521}
522
523impl NonTailFmt for super::I16Be {
524    proof fn lemma_serialize_dps_prepend(&self, v: i16, obuf: Seq<u8>) {
525        i16_be_fmt().lemma_serialize_dps_prepend(v, obuf);
526    }
527
528    proof fn lemma_serialize_dps_len(&self, v: i16, obuf: Seq<u8>) {
529        i16_be_fmt().lemma_serialize_dps_len(v, obuf);
530    }
531}
532
533impl GoodSerializer for super::I16Be {
534    proof fn lemma_serialize_len(&self, v: i16) {
535        i16_be_fmt().lemma_serialize_len(v);
536    }
537}
538
539impl SpecByteLen for super::I16Be {
540    type T = i16;
541
542    open spec fn byte_len(&self, _v: Self::T) -> nat {
543        U16_BYTE_LEN as nat
544    }
545}
546
547impl MinMaxByteLen for super::I16Be {
548    open spec fn min(&self) -> nat {
549        U16_BYTE_LEN as nat
550    }
551
552    open spec fn max(&self) -> nat {
553        U16_BYTE_LEN as nat
554    }
555
556    proof fn lemma_min_max_byte_len(&self, v: Self::T) {
557    }
558}
559
560impl StaticByteLen for super::I16Be {
561    open spec fn static_byte_len() -> nat {
562        U16_BYTE_LEN as nat
563    }
564
565    proof fn lemma_static_len_matches_byte_len(&self, v: Self::T) {
566    }
567}
568
569impl ValueByteLen for super::I16Be {
570    open spec fn value_byte_len(_v: Self::T) -> nat {
571        U16_BYTE_LEN as nat
572    }
573
574    proof fn lemma_value_len_matches_byte_len(&self, v: Self::T) {
575    }
576}
577
578impl SpecParser for super::I32Le {
579    type PVal = i32;
580
581    open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, i32)> {
582        i32_le_fmt().spec_parse(ibuf)
583    }
584}
585
586impl Consistency for super::I32Le {
587    type Val = i32;
588
589    open spec fn consistent(&self, _v: Self::Val) -> bool {
590        true
591    }
592}
593
594impl SpecSerializerDps for super::I32Le {
595    type SValue = i32;
596
597    open spec fn spec_serialize_dps(&self, v: i32, obuf: Seq<u8>) -> Seq<u8> {
598        i32_le_fmt().spec_serialize_dps(v, obuf)
599    }
600}
601
602impl SpecSerializer for super::I32Le {
603    type SVal = i32;
604
605    open spec fn spec_serialize(&self, v: i32) -> Seq<u8> {
606        i32_le_fmt().spec_serialize(v)
607    }
608}
609
610impl SafeParser for super::I32Le {
611    proof fn lemma_parse_safe(&self, ibuf: Seq<u8>) {
612        i32_le_fmt().lemma_parse_safe(ibuf);
613    }
614}
615
616impl SoundParser for super::I32Le {
617    proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>) {
618        broadcast use axiom_array_from_seq;
619        broadcast use lemma_i32_le_bytes_roundtrip;
620
621        i32_le_fmt().lemma_parse_sound_consumption(ibuf);
622    }
623
624    proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>) {
625        broadcast use axiom_array_from_seq;
626        broadcast use lemma_i32_le_bytes_roundtrip;
627
628        i32_le_fmt().lemma_parse_sound_value(ibuf);
629    }
630}
631
632impl NonTailFmt for super::I32Le {
633    proof fn lemma_serialize_dps_prepend(&self, v: i32, obuf: Seq<u8>) {
634        i32_le_fmt().lemma_serialize_dps_prepend(v, obuf);
635    }
636
637    proof fn lemma_serialize_dps_len(&self, v: i32, obuf: Seq<u8>) {
638        i32_le_fmt().lemma_serialize_dps_len(v, obuf);
639    }
640}
641
642impl GoodSerializer for super::I32Le {
643    proof fn lemma_serialize_len(&self, v: i32) {
644        i32_le_fmt().lemma_serialize_len(v);
645    }
646}
647
648impl SpecByteLen for super::I32Le {
649    type T = i32;
650
651    open spec fn byte_len(&self, _v: Self::T) -> nat {
652        U32_BYTE_LEN as nat
653    }
654}
655
656impl MinMaxByteLen for super::I32Le {
657    open spec fn min(&self) -> nat {
658        U32_BYTE_LEN as nat
659    }
660
661    open spec fn max(&self) -> nat {
662        U32_BYTE_LEN as nat
663    }
664
665    proof fn lemma_min_max_byte_len(&self, v: Self::T) {
666    }
667}
668
669impl StaticByteLen for super::I32Le {
670    open spec fn static_byte_len() -> nat {
671        U32_BYTE_LEN as nat
672    }
673
674    proof fn lemma_static_len_matches_byte_len(&self, v: Self::T) {
675    }
676}
677
678impl ValueByteLen for super::I32Le {
679    open spec fn value_byte_len(_v: Self::T) -> nat {
680        U32_BYTE_LEN as nat
681    }
682
683    proof fn lemma_value_len_matches_byte_len(&self, v: Self::T) {
684    }
685}
686
687impl SpecParser for super::I32Be {
688    type PVal = i32;
689
690    open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, i32)> {
691        i32_be_fmt().spec_parse(ibuf)
692    }
693}
694
695impl Consistency for super::I32Be {
696    type Val = i32;
697
698    open spec fn consistent(&self, _v: Self::Val) -> bool {
699        true
700    }
701}
702
703impl SpecSerializerDps for super::I32Be {
704    type SValue = i32;
705
706    open spec fn spec_serialize_dps(&self, v: i32, obuf: Seq<u8>) -> Seq<u8> {
707        i32_be_fmt().spec_serialize_dps(v, obuf)
708    }
709}
710
711impl SpecSerializer for super::I32Be {
712    type SVal = i32;
713
714    open spec fn spec_serialize(&self, v: i32) -> Seq<u8> {
715        i32_be_fmt().spec_serialize(v)
716    }
717}
718
719impl SafeParser for super::I32Be {
720    proof fn lemma_parse_safe(&self, ibuf: Seq<u8>) {
721        i32_be_fmt().lemma_parse_safe(ibuf);
722    }
723}
724
725impl SoundParser for super::I32Be {
726    proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>) {
727        broadcast use axiom_array_from_seq;
728        broadcast use lemma_i32_be_bytes_roundtrip;
729
730        i32_be_fmt().lemma_parse_sound_consumption(ibuf);
731    }
732
733    proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>) {
734        broadcast use axiom_array_from_seq;
735        broadcast use lemma_i32_be_bytes_roundtrip;
736
737        i32_be_fmt().lemma_parse_sound_value(ibuf);
738    }
739}
740
741impl NonTailFmt for super::I32Be {
742    proof fn lemma_serialize_dps_prepend(&self, v: i32, obuf: Seq<u8>) {
743        i32_be_fmt().lemma_serialize_dps_prepend(v, obuf);
744    }
745
746    proof fn lemma_serialize_dps_len(&self, v: i32, obuf: Seq<u8>) {
747        i32_be_fmt().lemma_serialize_dps_len(v, obuf);
748    }
749}
750
751impl GoodSerializer for super::I32Be {
752    proof fn lemma_serialize_len(&self, v: i32) {
753        i32_be_fmt().lemma_serialize_len(v);
754    }
755}
756
757impl SpecByteLen for super::I32Be {
758    type T = i32;
759
760    open spec fn byte_len(&self, _v: Self::T) -> nat {
761        U32_BYTE_LEN as nat
762    }
763}
764
765impl MinMaxByteLen for super::I32Be {
766    open spec fn min(&self) -> nat {
767        U32_BYTE_LEN as nat
768    }
769
770    open spec fn max(&self) -> nat {
771        U32_BYTE_LEN as nat
772    }
773
774    proof fn lemma_min_max_byte_len(&self, v: Self::T) {
775    }
776}
777
778impl StaticByteLen for super::I32Be {
779    open spec fn static_byte_len() -> nat {
780        U32_BYTE_LEN as nat
781    }
782
783    proof fn lemma_static_len_matches_byte_len(&self, v: Self::T) {
784    }
785}
786
787impl ValueByteLen for super::I32Be {
788    open spec fn value_byte_len(_v: Self::T) -> nat {
789        U32_BYTE_LEN as nat
790    }
791
792    proof fn lemma_value_len_matches_byte_len(&self, v: Self::T) {
793    }
794}
795
796impl SpecParser for super::I64Le {
797    type PVal = i64;
798
799    open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, i64)> {
800        i64_le_fmt().spec_parse(ibuf)
801    }
802}
803
804impl Consistency for super::I64Le {
805    type Val = i64;
806
807    open spec fn consistent(&self, _v: Self::Val) -> bool {
808        true
809    }
810}
811
812impl SpecSerializerDps for super::I64Le {
813    type SValue = i64;
814
815    open spec fn spec_serialize_dps(&self, v: i64, obuf: Seq<u8>) -> Seq<u8> {
816        i64_le_fmt().spec_serialize_dps(v, obuf)
817    }
818}
819
820impl SpecSerializer for super::I64Le {
821    type SVal = i64;
822
823    open spec fn spec_serialize(&self, v: i64) -> Seq<u8> {
824        i64_le_fmt().spec_serialize(v)
825    }
826}
827
828impl SafeParser for super::I64Le {
829    proof fn lemma_parse_safe(&self, ibuf: Seq<u8>) {
830        i64_le_fmt().lemma_parse_safe(ibuf);
831    }
832}
833
834impl SoundParser for super::I64Le {
835    proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>) {
836        broadcast use axiom_array_from_seq;
837        broadcast use lemma_i64_le_bytes_roundtrip;
838
839        i64_le_fmt().lemma_parse_sound_consumption(ibuf);
840    }
841
842    proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>) {
843        broadcast use axiom_array_from_seq;
844        broadcast use lemma_i64_le_bytes_roundtrip;
845
846        i64_le_fmt().lemma_parse_sound_value(ibuf);
847    }
848}
849
850impl NonTailFmt for super::I64Le {
851    proof fn lemma_serialize_dps_prepend(&self, v: i64, obuf: Seq<u8>) {
852        i64_le_fmt().lemma_serialize_dps_prepend(v, obuf);
853    }
854
855    proof fn lemma_serialize_dps_len(&self, v: i64, obuf: Seq<u8>) {
856        i64_le_fmt().lemma_serialize_dps_len(v, obuf);
857    }
858}
859
860impl GoodSerializer for super::I64Le {
861    proof fn lemma_serialize_len(&self, v: i64) {
862        i64_le_fmt().lemma_serialize_len(v);
863    }
864}
865
866impl SpecByteLen for super::I64Le {
867    type T = i64;
868
869    open spec fn byte_len(&self, _v: Self::T) -> nat {
870        U64_BYTE_LEN as nat
871    }
872}
873
874impl MinMaxByteLen for super::I64Le {
875    open spec fn min(&self) -> nat {
876        U64_BYTE_LEN as nat
877    }
878
879    open spec fn max(&self) -> nat {
880        U64_BYTE_LEN as nat
881    }
882
883    proof fn lemma_min_max_byte_len(&self, v: Self::T) {
884    }
885}
886
887impl StaticByteLen for super::I64Le {
888    open spec fn static_byte_len() -> nat {
889        U64_BYTE_LEN as nat
890    }
891
892    proof fn lemma_static_len_matches_byte_len(&self, v: Self::T) {
893    }
894}
895
896impl ValueByteLen for super::I64Le {
897    open spec fn value_byte_len(_v: Self::T) -> nat {
898        U64_BYTE_LEN as nat
899    }
900
901    proof fn lemma_value_len_matches_byte_len(&self, v: Self::T) {
902    }
903}
904
905impl SpecParser for super::I64Be {
906    type PVal = i64;
907
908    open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, i64)> {
909        i64_be_fmt().spec_parse(ibuf)
910    }
911}
912
913impl Consistency for super::I64Be {
914    type Val = i64;
915
916    open spec fn consistent(&self, _v: Self::Val) -> bool {
917        true
918    }
919}
920
921impl SpecSerializerDps for super::I64Be {
922    type SValue = i64;
923
924    open spec fn spec_serialize_dps(&self, v: i64, obuf: Seq<u8>) -> Seq<u8> {
925        i64_be_fmt().spec_serialize_dps(v, obuf)
926    }
927}
928
929impl SpecSerializer for super::I64Be {
930    type SVal = i64;
931
932    open spec fn spec_serialize(&self, v: i64) -> Seq<u8> {
933        i64_be_fmt().spec_serialize(v)
934    }
935}
936
937impl SafeParser for super::I64Be {
938    proof fn lemma_parse_safe(&self, ibuf: Seq<u8>) {
939        i64_be_fmt().lemma_parse_safe(ibuf);
940    }
941}
942
943impl SoundParser for super::I64Be {
944    proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>) {
945        broadcast use axiom_array_from_seq;
946        broadcast use lemma_i64_be_bytes_roundtrip;
947
948        i64_be_fmt().lemma_parse_sound_consumption(ibuf);
949    }
950
951    proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>) {
952        broadcast use axiom_array_from_seq;
953        broadcast use lemma_i64_be_bytes_roundtrip;
954
955        i64_be_fmt().lemma_parse_sound_value(ibuf);
956    }
957}
958
959impl NonTailFmt for super::I64Be {
960    proof fn lemma_serialize_dps_prepend(&self, v: i64, obuf: Seq<u8>) {
961        i64_be_fmt().lemma_serialize_dps_prepend(v, obuf);
962    }
963
964    proof fn lemma_serialize_dps_len(&self, v: i64, obuf: Seq<u8>) {
965        i64_be_fmt().lemma_serialize_dps_len(v, obuf);
966    }
967}
968
969impl GoodSerializer for super::I64Be {
970    proof fn lemma_serialize_len(&self, v: i64) {
971        i64_be_fmt().lemma_serialize_len(v);
972    }
973}
974
975impl SpecByteLen for super::I64Be {
976    type T = i64;
977
978    open spec fn byte_len(&self, _v: Self::T) -> nat {
979        U64_BYTE_LEN as nat
980    }
981}
982
983impl MinMaxByteLen for super::I64Be {
984    open spec fn min(&self) -> nat {
985        U64_BYTE_LEN as nat
986    }
987
988    open spec fn max(&self) -> nat {
989        U64_BYTE_LEN as nat
990    }
991
992    proof fn lemma_min_max_byte_len(&self, v: Self::T) {
993    }
994}
995
996impl StaticByteLen for super::I64Be {
997    open spec fn static_byte_len() -> nat {
998        U64_BYTE_LEN as nat
999    }
1000
1001    proof fn lemma_static_len_matches_byte_len(&self, v: Self::T) {
1002    }
1003}
1004
1005impl ValueByteLen for super::I64Be {
1006    open spec fn value_byte_len(_v: Self::T) -> nat {
1007        U64_BYTE_LEN as nat
1008    }
1009
1010    proof fn lemma_value_len_matches_byte_len(&self, v: Self::T) {
1011    }
1012}
1013
1014} // verus!