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/omega-mv/blob/main/apps/site_builder/radicle_index.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / apps / site_builder / radicle_index.om` 299 lines ยท 5514 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note apps/site_builder/radicle_index.om: pure-Omega Radicle repo index parser and validator 3 note Validates rad:z RIDs, repository names, Git SHA-1/SHA-256 OIDs, 4 note visibility tokens, tab-separated record structure, and canonical sorted index ordering. 5 note Compose after si/directives/om2.om and apps/site_builder/html_feed.om. 6 7 const RAD_OK ulong 0 8 const RAD_ERR_RID_PREFIX ulong 1 9 const RAD_ERR_RID_LEN ulong 2 10 const RAD_ERR_RID_CHAR ulong 3 11 const RAD_ERR_NAME ulong 4 12 const RAD_ERR_OID ulong 5 13 const RAD_ERR_VIS ulong 6 14 const RAD_ERR_FIELDS ulong 7 15 const RAD_ERR_DUPLICATE ulong 8 16 const RAD_ERR_ORDER ulong 9 17 18 text rad_pfx "rad:z" 19 text rad_vis_pub "public" 20 text rad_vis_priv "private" 21 22 fn rad_is_b58 b uchar to bool 23 if and ge b uchar 49 le b uchar 57 24 ret true 25 end 26 if and ge b uchar 65 le b uchar 72 27 ret true 28 end 29 if and ge b uchar 74 le b uchar 78 30 ret true 31 end 32 if and ge b uchar 80 le b uchar 90 33 ret true 34 end 35 if and ge b uchar 97 le b uchar 107 36 ret true 37 end 38 if and ge b uchar 109 le b uchar 122 39 ret true 40 end 41 ret false 42 end 43 44 fn rad_is_lhex b uchar to bool 45 if and ge b uchar 48 le b uchar 57 46 ret true 47 end 48 if and ge b uchar 97 le b uchar 102 49 ret true 50 end 51 ret false 52 end 53 54 fn rad_is_name_ch b uchar to bool 55 if and ge b uchar 97 le b uchar 122 56 ret true 57 end 58 if and ge b uchar 48 le b uchar 57 59 ret true 60 end 61 if or eq b uchar 45 or eq b uchar 46 eq b uchar 95 62 ret true 63 end 64 ret false 65 end 66 67 fn rad_validate_rid rid view uchar * to ulong 68 n = len rid 69 if lt n ulong 5 70 ret RAD_ERR_RID_PREFIX 71 end 72 if not sb_slice_eq part rid ulong 0 ulong 5 rad_pfx 73 ret RAD_ERR_RID_PREFIX 74 end 75 body = sub n ulong 5 76 if or lt body ulong 20 gt body ulong 48 77 ret RAD_ERR_RID_LEN 78 end 79 i = ulong 5 80 while lt i n bound 64 81 if not rad_is_b58 get rid i 82 ret RAD_ERR_RID_CHAR 83 end 84 i = add i ulong 1 85 end 86 ret RAD_OK 87 end 88 89 fn rad_validate_name name view uchar * to ulong 90 n = len name 91 if or eq n ulong 0 gt n ulong 64 92 ret RAD_ERR_NAME 93 end 94 first = get name ulong 0 95 if or eq first uchar 46 eq first uchar 45 96 ret RAD_ERR_NAME 97 end 98 prev_dot = false 99 i = ulong 0 100 while lt i n bound 64 101 b = get name i 102 if not rad_is_name_ch b 103 ret RAD_ERR_NAME 104 end 105 if eq b uchar 46 106 if prev_dot 107 ret RAD_ERR_NAME 108 end 109 prev_dot = true 110 else 111 prev_dot = false 112 end 113 i = add i ulong 1 114 end 115 ret RAD_OK 116 end 117 118 fn rad_validate_oid oid view uchar * to ulong 119 n = len oid 120 if and ne n ulong 40 ne n ulong 64 121 ret RAD_ERR_OID 122 end 123 i = ulong 0 124 while lt i n bound 64 125 if not rad_is_lhex get oid i 126 ret RAD_ERR_OID 127 end 128 i = add i ulong 1 129 end 130 ret RAD_OK 131 end 132 133 fn rad_validate_vis vis view uchar * to ulong 134 if sb_slice_eq vis rad_vis_pub 135 ret RAD_OK 136 end 137 if sb_slice_eq vis rad_vis_priv 138 ret RAD_OK 139 end 140 ret RAD_ERR_VIS 141 end 142 143 fn rad_slice_cmp a view uchar * b view uchar * to int 144 na = len a 145 nb = len b 146 ml = na 147 if lt nb ml 148 ml = nb 149 end 150 if gt ml ulong 128 151 ret int 0 152 end 153 i = ulong 0 154 while lt i ml bound 128 155 ca = get a i 156 cb = get b i 157 if lt ca cb 158 ret int -1 159 end 160 if gt ca cb 161 ret int 1 162 end 163 i = add i ulong 1 164 end 165 if lt na nb 166 ret int -1 167 end 168 if gt na nb 169 ret int 1 170 end 171 ret int 0 172 end 173 174 fn rad_parse_record line view uchar * out_meta edit ulong 8 to ulong 175 n = len line 176 if or eq n ulong 0 gt n ulong 512 177 ret RAD_ERR_FIELDS 178 end 179 tabs = new ulong 4 0 180 tcnt = ulong 0 181 i = ulong 0 182 while lt i n bound 512 183 if eq get line i uchar 9 184 if ge tcnt ulong 3 185 ret RAD_ERR_FIELDS 186 end 187 put tabs tcnt i 188 tcnt = add tcnt ulong 1 189 end 190 i = add i ulong 1 191 end 192 if ne tcnt ulong 3 193 ret RAD_ERR_FIELDS 194 end 195 t0 = get tabs ulong 0 196 t1 = get tabs ulong 1 197 t2 = get tabs ulong 2 198 put out_meta ulong 0 ulong 0 199 put out_meta ulong 1 t0 200 put out_meta ulong 2 add t0 ulong 1 201 put out_meta ulong 3 sub t1 add t0 ulong 1 202 put out_meta ulong 4 add t1 ulong 1 203 put out_meta ulong 5 sub t2 add t1 ulong 1 204 put out_meta ulong 6 add t2 ulong 1 205 put out_meta ulong 7 sub n add t2 ulong 1 206 rc = rad_validate_rid part line ulong 0 t0 207 if ne rc RAD_OK 208 ret rc 209 end 210 rc = rad_validate_name part line get out_meta ulong 2 get out_meta ulong 3 211 if ne rc RAD_OK 212 ret rc 213 end 214 rc = rad_validate_oid part line get out_meta ulong 4 get out_meta ulong 5 215 if ne rc RAD_OK 216 ret rc 217 end 218 rc = rad_validate_vis part line get out_meta ulong 6 get out_meta ulong 7 219 if ne rc RAD_OK 220 ret rc 221 end 222 ret RAD_OK 223 end 224 225 fn rad_copy_rid dst edit uchar 64 src view uchar * to ulong 226 ns = len src 227 if gt ns ulong 64 228 ret ulong 0 229 end 230 i = ulong 0 231 while lt i ns bound 64 232 put dst i get src i 233 i = add i ulong 1 234 end 235 ret ns 236 end 237 238 fn rad_check_line line view uchar * prev_rid edit uchar 64 prev_len edit ulong 1 to ulong 239 meta = new ulong 8 0 240 rc = rad_parse_record line meta 241 if ne rc RAD_OK 242 ret rc 243 end 244 rlen = get meta ulong 1 245 plen = get prev_len ulong 0 246 if gt plen ulong 0 247 c = rad_slice_cmp part prev_rid ulong 0 plen part line ulong 0 rlen 248 if eq c int 0 249 ret RAD_ERR_DUPLICATE 250 end 251 if gt c int 0 252 ret RAD_ERR_ORDER 253 end 254 end 255 nlen = rad_copy_rid prev_rid part line ulong 0 rlen 256 put prev_len ulong 0 nlen 257 ret RAD_OK 258 end 259 260 fn rad_parse_index buf view uchar * out_count edit ulong 1 to ulong 261 n = len buf 262 if gt n ulong 65536 263 ret RAD_ERR_FIELDS 264 end 265 prev_rid = new uchar 64 0 266 prev_len = new ulong 1 0 267 cnt = ulong 0 268 pos = ulong 0 269 while lt pos n bound 65536 270 start = pos 271 while lt pos n bound 65536 272 if eq get buf pos uchar 10 273 break 274 end 275 pos = add pos ulong 1 276 end 277 endp = pos 278 if gt endp start 279 if eq get buf sub endp ulong 1 uchar 13 280 endp = sub endp ulong 1 281 end 282 end 283 llen = sub endp start 284 if gt llen ulong 0 285 if ne get buf start uchar 35 286 rc = rad_check_line part buf start llen prev_rid prev_len 287 if ne rc RAD_OK 288 ret rc 289 end 290 cnt = add cnt ulong 1 291 end 292 end 293 if lt pos n 294 pos = add pos ulong 1 295 end 296 end 297 put out_count ulong 0 cnt 298 ret RAD_OK 299 end