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 / protocol / aien-protocols / core / main.om

233 lines · 4209 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/aien-protocols/core/main.om: CLI entrypoint for aien-protocols core
3note Compose with:
4note si/directives/om2.om om/tls/sha2.om protocol/aien-protocols/core/types.om
5note protocol/aien-protocols/core/provenance.om protocol/aien-protocols/core/action_event.om
6note protocol/aien-protocols/core/main.om
7
8text cmd_uuid "check-uuid"
9text cmd_digest "check-digest"
10text cmd_sha "sha256"
11text cmd_lic "check-license"
12text cmd_trans "check-transition"
13
14text msg_ok "OK\n"
15text msg_invalid "INVALID\n"
16text msg_denied "DENIED\n"
17text msg_nl "\n"
18text msg_usage "Usage: aien-protocols-core <check-uuid|check-digest|sha256|check-license|check-transition> ...\n"
19
20fn parse_u64_dec s view uchar * to long
21n = len s
22if eq n ulong 0
23ret long -1
24end
25if gt n ulong 18
26ret long -1
27end
28acc = ulong 0
29i = ulong 0
30while lt i n bound 18
31b = get s i
32if or lt b uchar 48 gt b uchar 57
33ret long -1
34end
35d = sub ulong b ulong 48
36acc = add mul acc ulong 10 d
37i = add i ulong 1
38end
39ret long acc
40end
41
42fn run_check_uuid to int
43arg = new uchar 128 0
44k = argread ulong 2 arg ulong 0 ulong 128
45if le k long 0
46w = pt_write_all int 1 msg_invalid
47if w
48ret int 1
49end
50ret int 1
51end
52u = new uchar 16 0
53rc = uuid_from_str part arg 0 ulong k u
54if ne rc PT_OK
55w = pt_write_all int 1 msg_invalid
56if w
57ret int 1
58end
59ret int 1
60end
61if not uuid_is_v4 u
62w = pt_write_all int 1 msg_invalid
63if w
64ret int 1
65end
66ret int 1
67end
68w = pt_write_all int 1 msg_ok
69if not w
70ret int 1
71end
72ret int 0
73end
74
75fn run_check_digest to int
76arg = new uchar 128 0
77k = argread ulong 2 arg ulong 0 ulong 128
78if le k long 0
79w = pt_write_all int 1 msg_invalid
80if w
81ret int 1
82end
83ret int 1
84end
85d = new uchar 32 0
86rc = digest_from_hex part arg 0 ulong k d
87if ne rc PT_OK
88w = pt_write_all int 1 msg_invalid
89if w
90ret int 1
91end
92ret int 1
93end
94fmt = new uchar 71 0
95fl = digest_format_sha256 d fmt
96w1 = pt_write_all int 1 part fmt 0 fl
97w2 = pt_write_all int 1 msg_nl
98if and w1 w2
99ret int 0
100end
101ret int 1
102end
103
104fn run_sha256 to int
105arg = new uchar 4096 0
106k = argread ulong 2 arg ulong 0 ulong 4096
107if lt k long 0
108ret int 1
109end
110d = new uchar 32 0
111prov_compute_sha256 part arg 0 ulong k d
112fmt = new uchar 71 0
113fl = digest_format_sha256 d fmt
114w1 = pt_write_all int 1 part fmt 0 fl
115w2 = pt_write_all int 1 msg_nl
116if and w1 w2
117ret int 0
118end
119ret int 1
120end
121
122fn run_check_license to int
123lic = new uchar 128 0
124csv = new uchar 512 0
125kl = argread ulong 2 lic ulong 0 ulong 128
126kc = argread ulong 3 csv ulong 0 ulong 512
127if or le kl long 0 le kc long 0
128w = pt_write_all int 1 msg_denied
129if w
130ret int 1
131end
132ret int 1
133end
134rc = grant_verify_license_csv part lic 0 ulong kl part csv 0 ulong kc
135if ne rc PROV_OK
136w = pt_write_all int 1 msg_denied
137if w
138ret int 1
139end
140ret int 1
141end
142w = pt_write_all int 1 msg_ok
143if not w
144ret int 1
145end
146ret int 0
147end
148
149fn run_check_transition to int
150a1 = new uchar 32 0
151a2 = new uchar 32 0
152k1 = argread ulong 2 a1 ulong 0 ulong 32
153k2 = argread ulong 3 a2 ulong 0 ulong 32
154if or le k1 long 0 le k2 long 0
155w = pt_write_all int 1 msg_denied
156if w
157ret int 1
158end
159ret int 1
160end
161v1 = parse_u64_dec part a1 0 ulong k1
162v2 = parse_u64_dec part a2 0 ulong k2
163if or lt v1 long 0 lt v2 long 0
164w = pt_write_all int 1 msg_denied
165if w
166ret int 1
167end
168ret int 1
169end
170rc = exec_transition_check ulong v1 ulong v2
171if ne rc AE_OK
172w = pt_write_all int 1 msg_denied
173if w
174ret int 1
175end
176ret int 1
177end
178w = pt_write_all int 1 msg_ok
179if not w
180ret int 1
181end
182ret int 0
183end
184
185fn main to int
186argc = argcnt
187if lt argc long 3
188w = pt_write_all int 2 msg_usage
189if w
190ret int 2
191end
192ret int 2
193end
194cmd = new uchar 64 0
195kc = argread ulong 1 cmd ulong 0 ulong 64
196if le kc long 0
197ret int 2
198end
199if pt_slice_eq part cmd 0 ulong kc cmd_uuid
200ret run_check_uuid
201end
202if pt_slice_eq part cmd 0 ulong kc cmd_digest
203ret run_check_digest
204end
205if pt_slice_eq part cmd 0 ulong kc cmd_sha
206ret run_sha256
207end
208if pt_slice_eq part cmd 0 ulong kc cmd_lic
209if lt argc long 4
210w = pt_write_all int 2 msg_usage
211if w
212ret int 2
213end
214ret int 2
215end
216ret run_check_license
217end
218if pt_slice_eq part cmd 0 ulong kc cmd_trans
219if lt argc long 4
220w = pt_write_all int 2 msg_usage
221if w
222ret int 2
223end
224ret int 2
225end
226ret run_check_transition
227end
228w = pt_write_all int 2 msg_usage
229if w
230ret int 2
231end
232ret int 2
233end