Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omtls/blob/main/tests/drv/x5io.om
# 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
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `main` Branches Tags History
`omtls / tests / drv / x5io.om`
338 lines ยท 6493 bytes Raw Blame History
1 note SPDX-License-Identifier: Apache-2.0
2 note x5io.om: test-driver helpers shared by tests/drv/{tm,der,x509}.om (not part of the library).
3 note Output to stdout, a whole vector file in memory, one line at a time split into tokens on
4 note spaces and tabs, decimal and hex tokens, and the CONTRACT summary line.
5 note Lines that are empty or start with "#" are skipped. A path token is relative to the
6 note directory of the vector file that names it.
7 global ot_x5_ziob uchar 32
8 global ot_x5_zib uchar `8388608`
9 note ot_x5_zik: token k starts at 2k and has length 2k+1 (k < 32); 64 count; 65 file length;
10 note 66 read position; 67 directory prefix length; 68 passes; 69 failures; 70 line number
11 global ot_x5_zik ulong 72
12 global ot_x5_zip uchar 4096
13 note ot_x5_zpf: the directory prefix of the vector file being read
14 global ot_x5_zpf uchar 4096
15 text ot_x5_zsF "FAIL "
16 text ot_x5_zsP "PASS "
17 text ot_x5_zsL " line "
18 text ot_x5_zsS " "
19 text ot_x5_zsC ": "
20 text ot_x5_zsN "\n"
21 text ot_x5_zsc " cases="
22 text ot_x5_zsp " pass="
23 text ot_x5_zsf " fail="
24 text ot_x5_zsm "-"
25
26 note ot_x5_ziw: all of t to stdout; exit 90 when stdout fails
27 fn ot_x5_ziw t view uchar * to void
28 p = ulong 0
29 while lt p len t bound `1000000`
30 k = write 1 t p sub len t p
31 if le k 0
32 exit 90
33 end
34 p = add p ulong k
35 end
36 end
37
38 fn ot_x5_ziwb o ulong n ulong to void
39 p = o
40 e = add o n
41 while lt p e bound `1000000`
42 k = write 1 ot_x5_zib p sub e p
43 if le k 0
44 exit 90
45 end
46 p = add p ulong k
47 end
48 end
49
50 note ot_x5_ziu: v in decimal, no newline
51 fn ot_x5_ziu v ulong to void
52 i = ulong 31
53 n = v
54 while true bound 21
55 i = sub i 1
56 put ot_x5_ziob i uchar add rem n 10 48
57 n = div n 10
58 if eq n 0
59 break
60 end
61 end
62 p = i
63 while lt p 31 bound 32
64 k = write 1 ot_x5_ziob p sub 31 p
65 if le k 0
66 exit 90
67 end
68 p = add p ulong k
69 end
70 end
71
72 note ot_x5_zil: v in decimal with a sign, no newline
73 fn ot_x5_zil v long to void
74 if lt v 0
75 ot_x5_ziw ot_x5_zsm
76 ot_x5_ziu add ulong neg add v 1 1
77 ret
78 end
79 ot_x5_ziu ulong v
80 end
81
82 fn ot_x5_ztk k ulong to ulong
83 ret get ot_x5_zik mul k 2
84 end
85 fn ot_x5_ztl k ulong to ulong
86 ret get ot_x5_zik add mul k 2 1
87 end
88 fn ot_x5_ztn to ulong
89 ret get ot_x5_zik 64
90 end
91
92 note ot_x5_zitw: token k to stdout
93 fn ot_x5_zitw k ulong to void
94 ot_x5_ziwb ot_x5_ztk k ot_x5_ztl k
95 end
96
97 note ot_x5_ziread: read the file named by argument a into ot_x5_zib; false when it cannot
98 fn ot_x5_ziread a ulong to bool
99 k = argread a ot_x5_zip 0 4000
100 if lt k 0
101 ret false
102 end
103 n = ulong k
104 put ot_x5_zik 67 0
105 for i ulong n bound `16777216`
106 if eq get ot_x5_zip i 47
107 put ot_x5_zik 67 add i 1
108 end
109 end
110 for i ulong get ot_x5_zik 67 bound `16777216`
111 put ot_x5_zpf i get ot_x5_zip i
112 end
113 fd = fopen ot_x5_zip 0 n 0 0
114 if lt fd 0
115 ret false
116 end
117 t = ulong 0
118 while true bound `1000000`
119 r = read int fd ot_x5_zib t sub len ot_x5_zib t
120 if lt r 0
121 c = fclose int fd
122 ret false
123 end
124 if eq r 0
125 break
126 end
127 t = add t ulong r
128 if eq t len ot_x5_zib
129 c = fclose int fd
130 ret false
131 end
132 end
133 c = fclose int fd
134 put ot_x5_zik 65 t
135 put ot_x5_zik 66 0
136 put ot_x5_zik 70 0
137 ret true
138 end
139
140 note ot_x5_zipath: the directory prefix of the vector file, then token k, in ot_x5_zip; the length
141 fn ot_x5_zipath k ulong to ulong
142 d = get ot_x5_zik 67
143 n = ot_x5_ztl k
144 if gt add d n 4000
145 ret 0
146 end
147 for i ulong d bound `16777216`
148 put ot_x5_zip i get ot_x5_zpf i
149 end
150 o = ot_x5_ztk k
151 for i ulong n bound `16777216`
152 put ot_x5_zip add d i get ot_x5_zib add o i
153 end
154 ret add d n
155 end
156
157 note ot_x5_ziline: the next line that is not empty and not a "#" comment, split into tokens
158 fn ot_x5_ziline to bool
159 e = get ot_x5_zik 65
160 while lt get ot_x5_zik 66 e bound `16777216`
161 p = get ot_x5_zik 66
162 q = p
163 while lt q e bound `16777216`
164 if eq get ot_x5_zib q 10
165 break
166 end
167 q = add q 1
168 end
169 put ot_x5_zik 66 add q 1
170 put ot_x5_zik 70 add get ot_x5_zik 70 1
171 ot_x5_zisplit p q
172 if gt ot_x5_ztn 0
173 if ne get ot_x5_zib ot_x5_ztk 0 35
174 ret true
175 end
176 end
177 end
178 ret false
179 end
180
181 fn ot_x5_zisp c uchar to bool
182 ret or or eq c 32 eq c 9 eq c 13
183 end
184
185 fn ot_x5_zisplit p ulong q ulong to void
186 n = ulong 0
187 i = p
188 while lt i q bound `16777216`
189 if ot_x5_zisp get ot_x5_zib i
190 i = add i 1
191 else
192 s = i
193 while lt i q bound `16777216`
194 if ot_x5_zisp get ot_x5_zib i
195 break
196 end
197 i = add i 1
198 end
199 if lt n 32
200 put ot_x5_zik mul n 2 s
201 put ot_x5_zik add mul n 2 1 sub i s
202 n = add n 1
203 end
204 end
205 end
206 put ot_x5_zik 64 n
207 end
208
209 note ot_x5_zteq: token k is exactly t
210 fn ot_x5_zteq k ulong t view uchar * to bool
211 if ge k ot_x5_ztn
212 ret false
213 end
214 if ne ot_x5_ztl k len t
215 ret false
216 end
217 o = ot_x5_ztk k
218 for i ulong len t bound `16777216`
219 if ne get ot_x5_zib add o i get t i
220 ret false
221 end
222 end
223 ret true
224 end
225
226 note ot_x5_ztdec: token k as a signed decimal; 0 with ot_x5_zik 71 set to 1 when it is not one
227 fn ot_x5_ztdec k ulong to long
228 put ot_x5_zik 71 1
229 if ge k ot_x5_ztn
230 ret 0
231 end
232 o = ot_x5_ztk k
233 n = ot_x5_ztl k
234 ng = false
235 if gt n 0
236 if eq get ot_x5_zib o 45
237 ng = true
238 o = add o 1
239 n = sub n 1
240 end
241 end
242 if or eq n 0 gt n 18
243 ret 0
244 end
245 v = long 0
246 for i ulong n bound `16777216`
247 c = get ot_x5_zib add o i
248 if or lt c 48 gt c 57
249 ret 0
250 end
251 v = add mul v 10 long sub c 48
252 end
253 put ot_x5_zik 71 0
254 if ng
255 ret neg v
256 end
257 ret v
258 end
259
260 fn ot_x5_zhx c uchar to ulong
261 if and ge c 48 le c 57
262 ret ulong sub c 48
263 end
264 if and ge c 97 le c 102
265 ret ulong add sub c 97 10
266 end
267 if and ge c 65 le c 70
268 ret ulong add sub c 65 10
269 end
270 ret 255
271 end
272
273 note ot_x5_zthex: token k as hex bytes into ot_der_m at offset o; the byte count or -1. "-" is empty.
274 fn ot_x5_zthex k ulong o ulong to long
275 if ge k ot_x5_ztn
276 ret -1
277 end
278 s = ot_x5_ztk k
279 n = ot_x5_ztl k
280 if and eq n 1 eq get ot_x5_zib s 45
281 ret 0
282 end
283 if ne rem n 2 0
284 ret -1
285 end
286 m = div n 2
287 for i ulong m bound `16777216`
288 a = ot_x5_zhx get ot_x5_zib add s mul i 2
289 b = ot_x5_zhx get ot_x5_zib add s add mul i 2 1
290 if or gt a 15 gt b 15
291 ret -1
292 end
293 put ot_der_m add o i uchar or shl a 4 b
294 end
295 ret long m
296 end
297
298 note ot_x5_zifail: one FAILED case line: "FAIL line : "
299 fn ot_x5_zifail area view uchar * why view uchar * to void
300 put ot_x5_zik 69 add get ot_x5_zik 69 1
301 ot_x5_ziw ot_x5_zsF
302 ot_x5_ziw area
303 ot_x5_ziw ot_x5_zsL
304 ot_x5_ziu get ot_x5_zik 70
305 ot_x5_ziw ot_x5_zsS
306 if gt ot_x5_ztn 1
307 ot_x5_zitw 1
308 end
309 ot_x5_ziw ot_x5_zsC
310 ot_x5_ziw why
311 ot_x5_ziw ot_x5_zsN
312 end
313
314 fn ot_x5_zipass to void
315 put ot_x5_zik 68 add get ot_x5_zik 68 1
316 end
317
318 note ot_x5_ziend: the CONTRACT summary line; the exit status
319 fn ot_x5_ziend area view uchar * to int
320 p = get ot_x5_zik 68
321 f = get ot_x5_zik 69
322 if and eq f 0 gt p 0
323 ot_x5_ziw ot_x5_zsP
324 ot_x5_ziw area
325 ot_x5_ziw ot_x5_zsc
326 ot_x5_ziu p
327 ot_x5_ziw ot_x5_zsN
328 ret 0
329 end
330 ot_x5_ziw ot_x5_zsF
331 ot_x5_ziw area
332 ot_x5_ziw ot_x5_zsp
333 ot_x5_ziu p
334 ot_x5_ziw ot_x5_zsf
335 ot_x5_ziu f
336 ot_x5_ziw ot_x5_zsN
337 ret 1
338 end