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