interplane.Get Omega
Read in your language

omtls

omtls: a TLS 1.3 client (RFC 8446) written fresh in seeded Omega, for mailhand. Not audited by a cryptographer. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

omtls / tests / drv / symio.om

271 lines · 5424 bytes Raw Blame History
1note omtls symmetric test drivers: vector-file reader, hex and decimal tokens, result lines.
2note Test code only; never linked into the library. Every name starts with ot_sy_.
3note Reader state st (ulong 10): 0 next unread byte in b, 1 end of buffered bytes, 2 end of file (1) or a line
4note longer than b (2), 3 line start, 4 line end, 5 token cursor, 6 token start, 7 token length, 8 line number.
5text ot_sy_tpass "PASS "
6text ot_sy_tcases " cases="
7text ot_sy_tfail "FAIL "
8text ot_sy_tpn " pass="
9text ot_sy_tfn " fail="
10text ot_sy_tnl "\n"
11text ot_sy_tbad "case-failed "
12text ot_sy_targ " arg="
13text ot_sy_tline " line="
14text ot_sy_tlong "line longer than the read buffer"
15fn ot_sy_put t view uchar * to void
16r = write 1 t 0 len t
17end
18fn ot_sy_num v ulong to void
19d = new uchar 24 0
20i = ulong 24
21x = v
22while true bound 30
23i = sub i 1
24put d i uchar add 48 rem x 10
25x = div x 10
26if eq x 0
27break
28end
29end
30r = write 1 d i sub 24 i
31end
32fn ot_sy_bad area view uchar * a ulong st view ulong 10 to void
33ot_sy_put ot_sy_tbad
34ot_sy_put area
35ot_sy_put ot_sy_targ
36ot_sy_num a
37ot_sy_put ot_sy_tline
38ot_sy_num get st 8
39ot_sy_put ot_sy_tnl
40end
41fn ot_sy_done area view uchar * p ulong f ulong to int
42if and eq f 0 gt p 0
43ot_sy_put ot_sy_tpass
44ot_sy_put area
45ot_sy_put ot_sy_tcases
46ot_sy_num p
47ot_sy_put ot_sy_tnl
48ret 0
49end
50ot_sy_put ot_sy_tfail
51ot_sy_put area
52ot_sy_put ot_sy_tpn
53ot_sy_num p
54ot_sy_put ot_sy_tfn
55ot_sy_num f
56ot_sy_put ot_sy_tnl
57ret 1
58end
59note Open argument i (a path) for reading; p holds the path bytes. Gives the descriptor, or -1.
60fn ot_sy_open i ulong p edit uchar * to int
61n = argread i p 0 len p
62if lt n 1
63ret int -1
64end
65fd = fopen p 0 ulong n 0 0
66if lt fd 0
67ret int -1
68end
69ret int fd
70end
71fn ot_sy_init st edit ulong 10 to void
72for i ulong 10 unroll
73put st i 0
74end
75end
76note Next line of fd into st 3 .. st 4 (newline excluded). False at end of file or on an over-long line (st 2 = 2).
77fn ot_sy_line fd int b edit uchar * st edit ulong 10 to bool
78while true bound 9223372036854775807
79s = get st 0
80e = get st 1
81i = s
82while lt i e bound 9223372036854775807
83if eq get b i 10
84put st 3 s
85put st 4 i
86put st 5 s
87put st 0 add i 1
88put st 8 add get st 8 1
89ret true
90end
91i = add i 1
92end
93if ne get st 2 0
94if lt s e
95put st 3 s
96put st 4 e
97put st 5 s
98put st 0 e
99put st 8 add get st 8 1
100ret true
101end
102ret false
103end
104j = ulong 0
105while lt add s j e bound 9223372036854775807
106put b j get b add s j
107j = add j 1
108end
109put st 0 0
110put st 1 j
111if eq j len b
112put st 2 2
113ot_sy_put ot_sy_tlong
114ot_sy_put ot_sy_tnl
115ret false
116end
117r = read fd b j sub len b j
118if gt r 0
119put st 1 add j ulong r
120else
121put st 2 1
122end
123end
124ret false
125end
126note Next blank-separated token of the current line: st 6 start, st 7 length (0: none left). Gives the length.
127fn ot_sy_tok b view uchar * st edit ulong 10 to ulong
128p = get st 5
129e = get st 4
130while lt p e bound 9223372036854775807
131c = get b p
132if and ne c 32 and ne c 9 ne c 13
133break
134end
135p = add p 1
136end
137q = p
138while lt q e bound 9223372036854775807
139d = get b q
140if or eq d 32 or eq d 9 eq d 13
141break
142end
143q = add q 1
144end
145put st 5 q
146put st 6 p
147put st 7 sub q p
148ret sub q p
149end
150fn ot_sy_is b view uchar * st view ulong 10 t view uchar * to bool
151n = get st 7
152if ne n len t
153ret false
154end
155p = get st 6
156i = ulong 0
157while lt i n bound 9223372036854775807
158if ne get b add p i get t i
159ret false
160end
161i = add i 1
162end
163ret true
164end
165fn ot_sy_hv c uchar to ulong
166if and ge c 48 le c 57
167ret ulong sub c 48
168end
169if and ge c 97 le c 102
170ret ulong sub c 87
171end
172if and ge c 65 le c 70
173ret ulong sub c 55
174end
175ret 16
176end
177note Decode the current token as hex into o; "-" and an empty token are 0 bytes. Gives the byte count, -1 for
178note malformed hex, -2 when o is too short.
179fn ot_sy_hex b view uchar * st view ulong 10 o edit uchar * to long
180p = get st 6
181n = get st 7
182if eq n 0
183ret 0
184end
185if eq n 1
186if eq get b p 45
187ret 0
188end
189end
190if ne and n 1 0
191ret -1
192end
193m = shr n 1
194if gt m len o
195ret -2
196end
197i = ulong 0
198while lt i m bound 9223372036854775807
199hi = ot_sy_hv get b add p shl i 1
200lo = ot_sy_hv get b add add p shl i 1 1
201if or gt hi 15 gt lo 15
202ret -1
203end
204put o i uchar or shl hi 4 lo
205i = add i 1
206end
207ret long m
208end
209note Next token as hex; same results as ot_sy_hex, -3 when the line has no token left.
210fn ot_sy_nhex b view uchar * st edit ulong 10 o edit uchar * to long
211n = ot_sy_tok b st
212if eq n 0
213ret -3
214end
215ret ot_sy_hex b st o
216end
217note The current token as a decimal number (digits only; anything else stops it).
218fn ot_sy_dec b view uchar * st view ulong 10 to ulong
219p = get st 6
220n = get st 7
221v = ulong 0
222i = ulong 0
223while lt i n bound 9223372036854775807
224c = get b add p i
225if or lt c 48 gt c 57
226ret v
227end
228v = add mul v 10 ulong sub c 48
229i = add i 1
230end
231ret v
232end
233fn ot_sy_ndec b view uchar * st edit ulong 10 to ulong
234n = ot_sy_tok b st
235ret ot_sy_dec b st
236end
237fn ot_sy_eq a view uchar * b view uchar * n ulong to bool
238if or gt n len a gt n len b
239ret false
240end
241i = ulong 0
242while lt i n bound 9223372036854775807
243if ne get a i get b i
244ret false
245end
246i = add i 1
247end
248ret true
249end
250note Count one case in r (0 passed, 1 failed); a failure prints its line.
251fn ot_sy_res r edit ulong 4 ok bool area view uchar * st view ulong 10 to void
252if ok
253put r 0 add get r 0 1
254else
255put r 1 add get r 1 1
256ot_sy_bad area 0 st
257end
258end
259note Hash length or bits (32/256, 48/384, 64/512) to the alg id 0/1/2; 9 for anything else.
260fn ot_sy_alg v ulong to ulong
261if or eq v 32 eq v 256
262ret 0
263end
264if or eq v 48 eq v 384
265ret 1
266end
267if or eq v 64 eq v 512
268ret 2
269end
270ret 9
271end