interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / crates / aienos-capability-ffi / cap_ffi_test.om

137 lines · 2861 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/crates/aienos-capability-ffi/cap_ffi_test.om: Behavioral self-test for aienos-capability-ffi.
3note Compose with: si/directives/om2.om aienux/crates/aienos-capability-ffi/cap_ffi.om aienux/crates/aienos-capability-ffi/cap_ffi_test.om
4
5fn t_ref_id r view Cap32Ref to uint
6ret get r cap_id
7end
8
9fn t_ref_gen r view Cap32Ref to uint
10ret get r gen
11end
12
13fn t_ent_subj e view Cap32Ent to uint
14ret get e subject
15end
16
17fn t_fill_mnt req edit Cap32Mnt office view Cap32Ref to void
18put req issuer 1
19put req subject 42
20put req res 0x1000
21put req rights CAP32_RIGHT_READ
22put req lease 100
23put req par_id 0
24put req par_gen 0
25put req auth_id get office cap_id
26put req auth_gen get office gen
27end
28
29fn main to int
30note 1. ABI layout contract matches 32-bit cap32 ABI [8, 4, 4, 64] and version 1
31words = new uint 4 0
32ver = cap32_abi_layout words
33if ne ver CAP32_ABI_VERSION
34ret 1
35end
36if ne get words 0 8
37ret 2
38end
39if ne get words 1 4
40ret 3
41end
42if ne get words 2 4
43ret 4
44end
45if ne get words 3 64
46ret 5
47end
48
49note 2. Start authority and fetch office ref
50if ne cap32_start CAP32_OK
51ret 9
52end
53office = new uchar 8 0
54if ne cap32_office office CAP32_OK
55ret 10
56end
57
58note 3. Mint a capability and validate it
59req = new uchar 48 0
60t_fill_mnt req office
61cap = new uchar 8 0
62if ne cap32_mint req cap CAP32_OK
63ret 11
64end
65
66ent = new uchar 64 0
67if ne cap32_validate cap 42 0x1000 CAP32_RIGHT_READ ent CAP32_OK
68ret 12
69end
70if ne t_ent_subj ent 42
71ret 13
72end
73
74note 4. Wrong subject and wrong rights refused
75if ne cap32_validate cap 99 0x1000 CAP32_RIGHT_READ ent CAP32_ERR_SUBJECT
76ret 14
77end
78if ne cap32_validate cap 42 0x1000 CAP32_RIGHT_WRITE ent CAP32_ERR_RIGHTS
79ret 15
80end
81
82note 5. Cognition mint/admin unconditionally unauthorized
83if ne cap32_cognition_mint req CAP32_ERR_UNAUTH
84ret 16
85end
86if ne cap32_cognition_admin 1 office cap CAP32_ERR_UNAUTH
87ret 17
88end
89
90note 6. Clock advance expires lease
91if ne cap32_advance_clock office 100 CAP32_OK
92ret 18
93end
94if ne cap32_clock 100
95ret 19
96end
97if ne cap32_validate cap 42 0x1000 CAP32_RIGHT_READ ent CAP32_ERR_EXPIRED
98ret 20
99end
100
101note 7. Revoke, reclaim bumps generation, old ref becomes STALE_GEN
102if ne cap32_revoke office cap CAP32_OK
103ret 21
104end
105if ne cap32_reclaim office t_ref_id cap CAP32_OK
106ret 22
107end
108if ne cap32_validate cap 42 0x1000 CAP32_RIGHT_READ ent CAP32_ERR_STALE_GEN
109ret 23
110end
111
112note 8. Generation exhaustion at 0xffffffff
113nxt = new uint 1 0
114if ne cap32_gen_advance 0xffffffff nxt CAP32_ERR_EXHAUSTED
115ret 24
116end
117
118note 9. Restart advances boot generation above floor, invalidating old office ref
119if ne cap32_restart CAP32_OK
120ret 25
121end
122new_off = new uchar 8 0
123if ne cap32_office new_off CAP32_OK
124ret 26
125end
126if le t_ref_gen new_off t_ref_gen office
127ret 27
128end
129if ne cap32_bump_epoch office CAP32_ERR_STALE_GEN
130ret 28
131end
132if ne cap32_bump_epoch new_off CAP32_OK
133ret 29
134end
135
136ret 0
137end