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 / interplane / core / main.om

244 lines · 4231 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/interplane/core/main.om: CLI entrypoint for interplane core envelope & policy engine
3note Compose with:
4note si/directives/om2.om om/tls/sha2.om protocol/interplane/core/envelope.om
5note protocol/interplane/core/policy.om protocol/interplane/core/main.om
6
7text ip_cmd_ident "check-ident"
8text ip_cmd_ver "check-version"
9text ip_cmd_eval "eval-policy"
10text ip_cmd_parse "parse-stdin"
11
12text ip_msg_ok "OK\n"
13text ip_msg_allow "ALLOW\n"
14text ip_msg_deny "DENY\n"
15text ip_msg_invalid "INVALID\n"
16text ip_msg_parsed "PARSED "
17text ip_msg_nl "\n"
18text ip_msg_usage "Usage: interplane-core <check-ident <id>|check-version <v>|parse-stdin|eval-policy <rpol> <ops> <orig> <trans> <rop> <cpol>>\n"
19
20fn ip_parse_dec s view uchar * to long
21n = len s
22if eq n ulong 0
23ret long -1
24end
25if gt n ulong 12
26ret long -1
27end
28acc = ulong 0
29i = ulong 0
30while lt i n bound 12
31b = get s i
32if or lt b uchar 48 gt b uchar 57
33ret long -1
34end
35acc = add mul acc ulong 10 sub ulong b ulong 48
36i = add i ulong 1
37end
38ret long acc
39end
40
41fn ip_read_arg_u64 idx ulong to long
42buf = new uchar 32 0
43k = argread idx buf ulong 0 ulong 32
44if le k long 0
45ret long -1
46end
47ret ip_parse_dec part buf 0 ulong k
48end
49
50fn ip_cli_ident to int
51buf = new uchar 128 0
52k = argread ulong 2 buf ulong 0 ulong 128
53if le k long 0
54w = ip_write_all int 1 ip_msg_invalid
55if w
56ret int 1
57end
58ret int 1
59end
60rc = ip_valid_ident part buf 0 ulong k
61if ne rc IP_OK
62w = ip_write_all int 1 ip_msg_invalid
63if w
64ret int 1
65end
66ret int 1
67end
68w = ip_write_all int 1 ip_msg_ok
69if not w
70ret int 1
71end
72ret int 0
73end
74
75fn ip_cli_version to int
76buf = new uchar 64 0
77k = argread ulong 2 buf ulong 0 ulong 64
78if le k long 0
79w = ip_write_all int 1 ip_msg_invalid
80if w
81ret int 1
82end
83ret int 1
84end
85rc = ip_validate_version part buf 0 ulong k
86if ne rc IP_OK
87w = ip_write_all int 1 ip_msg_invalid
88if w
89ret int 1
90end
91ret int 1
92end
93w = ip_write_all int 1 ip_msg_ok
94if not w
95ret int 1
96end
97ret int 0
98end
99
100fn ip_cli_parse_stdin to int
101buf = new uchar 4096 0
102tot = ulong 0
103done = false
104while not done bound 4096
105if ge tot ulong 4096
106break
107end
108remn = sub ulong 4096 tot
109k = read int 0 buf tot remn
110if lt k long 0
111ret int 1
112end
113if eq k long 0
114done = true
115else
116tot = add tot ulong k
117end
118end
119meta = new ulong 4 0
120dig = new uchar 32 0
121rc = ip_parse_envelope part buf 0 tot meta dig
122if ne rc IP_OK
123w = ip_write_all int 1 ip_msg_invalid
124if w
125ret int 1
126end
127ret int 1
128end
129hx = new uchar 64 0
130ip_digest_to_hex dig hx
131w1 = ip_write_all int 1 ip_msg_parsed
132w2 = ip_write_all int 1 hx
133w3 = ip_write_all int 1 ip_msg_nl
134if and w1 and w2 w3
135ret int 0
136end
137ret int 1
138end
139
140fn ip_cli_eval to int
141rpol = ip_read_arg_u64 ulong 2
142aops = ip_read_arg_u64 ulong 3
143orig = ip_read_arg_u64 ulong 4
144tr = ip_read_arg_u64 ulong 5
145rop = ip_read_arg_u64 ulong 6
146cpol = ip_read_arg_u64 ulong 7
147if lt rpol long 0
148w = ip_write_all int 1 ip_msg_deny
149if w
150ret int 1
151end
152ret int 1
153end
154if lt aops long 0
155w = ip_write_all int 1 ip_msg_deny
156if w
157ret int 1
158end
159ret int 1
160end
161if lt orig long 0
162w = ip_write_all int 1 ip_msg_deny
163if w
164ret int 1
165end
166ret int 1
167end
168if lt tr long 0
169w = ip_write_all int 1 ip_msg_deny
170if w
171ret int 1
172end
173ret int 1
174end
175if lt rop long 0
176w = ip_write_all int 1 ip_msg_deny
177if w
178ret int 1
179end
180ret int 1
181end
182if lt cpol long 0
183w = ip_write_all int 1 ip_msg_deny
184if w
185ret int 1
186end
187ret int 1
188end
189rc = ip_eval_policy ulong rpol ulong aops ulong orig ulong tr ulong rop ulong cpol
190if ne rc POL_OK
191w = ip_write_all int 1 ip_msg_deny
192if w
193ret int 1
194end
195ret int 1
196end
197w = ip_write_all int 1 ip_msg_allow
198if not w
199ret int 1
200end
201ret int 0
202end
203
204fn main to int
205argc = argcnt
206if lt argc long 2
207w = ip_write_all int 2 ip_msg_usage
208if w
209ret int 2
210end
211ret int 2
212end
213cmd = new uchar 64 0
214kc = argread ulong 1 cmd ulong 0 ulong 64
215if le kc long 0
216ret int 2
217end
218if ip_slice_eq part cmd 0 ulong kc ip_cmd_parse
219ret ip_cli_parse_stdin
220end
221if ip_slice_eq part cmd 0 ulong kc ip_cmd_ident
222if lt argc long 3
223ret int 2
224end
225ret ip_cli_ident
226end
227if ip_slice_eq part cmd 0 ulong kc ip_cmd_ver
228if lt argc long 3
229ret int 2
230end
231ret ip_cli_version
232end
233if ip_slice_eq part cmd 0 ulong kc ip_cmd_eval
234if lt argc long 8
235ret int 2
236end
237ret ip_cli_eval
238end
239w = ip_write_all int 2 ip_msg_usage
240if w
241ret int 2
242end
243ret int 2
244end