interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / ipl / om / landrec.om
| 1 | om2 |
| 2 | note landrec.om: the one place that decides what a native Interplane record may say. |
| 3 | note landrec project NAME BRANCH VISIBILITY OWNER ALIAS NONCE |
| 4 | note landrec land NAME BRANCH OLD NEW RECEIPT VERDICT REQUEST |
| 5 | note landrec successor NAME OLD NEW PUB REASON |
| 6 | note landrec check name|branch|request|owner|pub|reason VALUE exit 0 when VALUE satisfies that rule, else 1 |
| 7 | note project and land check every field and print the canonical payload (the exact bytes a chain |
| 8 | note record commits to) on stdout, exit 0. A field that breaks its rule prints "REFUSED <field>" on |
| 9 | note stderr, exit 1, and nothing on stdout. Wrong word or argument count: usage on stderr, exit 2. |
| 10 | note Field rules. NAME: one or more bytes of letters digits . _ - starting with a letter or digit, never |
| 11 | note ending in a dot (two names that differ only in case are refused by the store, not here). |
| 12 | note BRANCH: one or more bytes of letters digits . _ - / ; no leading - . / ; no trailing . / ; no ".." |
| 13 | note "//" or "/." inside; no part ending in ".lock" (git refuses those). OLD, NEW: 40 lowercase hex |
| 14 | note digits (a commit; OLD is 40 zeros when the branch has no head yet). RECEIPT, VERDICT: 64 |
| 15 | note lowercase hex digits (SHA-256 of the file). REQUEST: one or more bytes of letters digits . _ - |
| 16 | note (the caller's own id; the same id never lands twice). NONCE: 32 lowercase hex digits, random, |
| 17 | note made once when the project is created, so that projects created separately get, by chance, different ids. |
| 18 | note VISIBILITY: public or private. OWNER, and successor OLD and NEW: an SSH key fingerprint, SHA256: |
| 19 | note and 43 base64 characters. PUB: 68 characters of base64 (A-Za-z0-9+/), the blob of one ssh-ed25519 |
| 20 | note public key with no comment (51 decoded bytes, no padding). REASON: - or the same bytes as REQUEST. |
| 21 | note ALIAS: - or the project's old id, rad:z and 20..60 letters and digits (history lookups only). |
| 22 | note No field can hold a space, a tab or a line feed, so a payload line is never ambiguous. |
| 23 | note Sizes. No field has a length chosen here. (The store writes a name or branch longer than the |
| 24 | note chain format's 128-byte subject field into that field as a digest, and refuses only what the |
| 25 | note file system cannot hold as a folder or a branch.) |
| 26 | note Nothing else has a size chosen here. ab holds one argument and is 131072 bytes, the most Linux |
| 27 | note lets one argument be (MAX_ARG_STRLEN, terminator included), so no argument a process can be |
| 28 | note started with is cut or refused for its length. ob holds one payload. The longest is a land |
| 29 | note record whose name, branch and request are each the longest argument, 131071 bytes: 18 for the |
| 30 | note first line, 131080 + 131079 + 131080 for those three lines, 45 + 45 for old and new, 73 + 73 for |
| 31 | note receipt and verdict, 393493 bytes in all; ob is 400000. The loop bounds 200000 and 2000000 are |
| 32 | note above those sizes. (A run-time pool would say this more directly, but at this compiler pin |
| 33 | note argread refuses a pool as its buffer, error 7.) |
| 34 | global ab uchar 131072 |
| 35 | global ob uchar 400000 |
| 36 | global ol ulong 1 |
| 37 | text tland "land" |
| 38 | text tproj "project" |
| 39 | text tcheck "check" |
| 40 | text tname "name" |
| 41 | text tbr "branch" |
| 42 | text trq "request" |
| 43 | text hland "interplane-land 1\n" |
| 44 | text hproj "interplane-project 1\n" |
| 45 | text kproj "project " |
| 46 | text kbranch "branch " |
| 47 | text kold "old " |
| 48 | text knew "new " |
| 49 | text krec "receipt " |
| 50 | text kver "verdict " |
| 51 | text kreq "request " |
| 52 | text kvis "visibility " |
| 53 | text kown "owner " |
| 54 | text kali "alias " |
| 55 | text knon "nonce " |
| 56 | text tref "REFUSED " |
| 57 | text tnl "\n" |
| 58 | text tpub "public" |
| 59 | text tpriv "private" |
| 60 | text tsha "SHA256:" |
| 61 | text trad "rad:z" |
| 62 | text tsucc "successor" |
| 63 | text hsucc "interplane-successor 1\n" |
| 64 | text kpub "pub " |
| 65 | text kreason "reason " |
| 66 | text tpubk "pub" |
| 67 | text treason "reason" |
| 68 | text town "owner" |
| 69 | text tusage "usage: landrec project NAME BRANCH VISIBILITY OWNER ALIAS NONCE | landrec land NAME BRANCH OLD NEW RECEIPT VERDICT REQUEST | landrec successor NAME OLD NEW PUB REASON | landrec check name|branch|request|owner|pub|reason VALUE\n" |
| 70 | fn islow c uchar to bool |
| 71 | ret and ge c 97 le c 122 |
| 72 | end |
| 73 | fn isup c uchar to bool |
| 74 | ret and ge c 65 le c 90 |
| 75 | end |
| 76 | fn isdig c uchar to bool |
| 77 | ret and ge c 48 le c 57 |
| 78 | end |
| 79 | fn isaln c uchar to bool |
| 80 | ret or (islow c) (or (isup c) (isdig c)) |
| 81 | end |
| 82 | fn nope b bool to bool |
| 83 | if b |
| 84 | ret false |
| 85 | end |
| 86 | ret true |
| 87 | end |
| 88 | note loada: argument i into ab; the length, or a negative host error |
| 89 | fn loada i ulong to long |
| 90 | ret argread i ab 0 131072 |
| 91 | end |
| 92 | note same: ab[0,n) equals the text t |
| 93 | fn same t view uchar * n ulong to bool |
| 94 | if ne n len t |
| 95 | ret false |
| 96 | end |
| 97 | j = ulong 0 |
| 98 | while lt j n bound 256 |
| 99 | if ne get ab j get t j |
| 100 | ret false |
| 101 | end |
| 102 | j = add j 1 |
| 103 | end |
| 104 | ret true |
| 105 | end |
| 106 | fn hexn n ulong want ulong to bool |
| 107 | if ne n want |
| 108 | ret false |
| 109 | end |
| 110 | j = ulong 0 |
| 111 | while lt j n bound 256 |
| 112 | c = get ab j |
| 113 | if nope or (isdig c) (and ge c 97 le c 102) |
| 114 | ret false |
| 115 | end |
| 116 | j = add j 1 |
| 117 | end |
| 118 | ret true |
| 119 | end |
| 120 | fn namec c uchar to bool |
| 121 | ret or (isaln c) (or eq c 46 (or eq c 95 eq c 45)) |
| 122 | end |
| 123 | fn isname n ulong to bool |
| 124 | if eq n 0 |
| 125 | ret false |
| 126 | end |
| 127 | f = get ab 0 |
| 128 | if nope and (isaln f) (ne get ab sub n 1 46) |
| 129 | ret false |
| 130 | end |
| 131 | j = ulong 0 |
| 132 | while lt j n bound 200000 |
| 133 | if nope namec get ab j |
| 134 | ret false |
| 135 | end |
| 136 | j = add j 1 |
| 137 | end |
| 138 | ret true |
| 139 | end |
| 140 | fn refc c uchar to bool |
| 141 | ret or (isaln c) (or eq c 46 (or eq c 95 (or eq c 45 eq c 47))) |
| 142 | end |
| 143 | note lockat: ab[e-5,e) is ".lock" |
| 144 | fn lockat e ulong to bool |
| 145 | if lt e 5 |
| 146 | ret false |
| 147 | end |
| 148 | s = sub e 5 |
| 149 | if ne get ab s 46 |
| 150 | ret false |
| 151 | end |
| 152 | if ne get ab add s 1 108 |
| 153 | ret false |
| 154 | end |
| 155 | if ne get ab add s 2 111 |
| 156 | ret false |
| 157 | end |
| 158 | if ne get ab add s 3 99 |
| 159 | ret false |
| 160 | end |
| 161 | ret eq get ab add s 4 107 |
| 162 | end |
| 163 | fn isref n ulong to bool |
| 164 | if eq n 0 |
| 165 | ret false |
| 166 | end |
| 167 | f = get ab 0 |
| 168 | if or eq f 45 or eq f 46 eq f 47 |
| 169 | ret false |
| 170 | end |
| 171 | l = get ab sub n 1 |
| 172 | if or eq l 46 eq l 47 |
| 173 | ret false |
| 174 | end |
| 175 | p = uchar 0 |
| 176 | j = ulong 0 |
| 177 | while lt j n bound 200000 |
| 178 | c = get ab j |
| 179 | if nope refc c |
| 180 | ret false |
| 181 | end |
| 182 | if and eq c 46 or eq p 46 eq p 47 |
| 183 | ret false |
| 184 | end |
| 185 | if and eq c 47 eq p 47 |
| 186 | ret false |
| 187 | end |
| 188 | if and eq c 47 (lockat j) |
| 189 | ret false |
| 190 | end |
| 191 | p = c |
| 192 | j = add j 1 |
| 193 | end |
| 194 | ret nope lockat n |
| 195 | end |
| 196 | fn isreq n ulong to bool |
| 197 | if eq n 0 |
| 198 | ret false |
| 199 | end |
| 200 | j = ulong 0 |
| 201 | while lt j n bound 200000 |
| 202 | if nope namec get ab j |
| 203 | ret false |
| 204 | end |
| 205 | j = add j 1 |
| 206 | end |
| 207 | ret true |
| 208 | end |
| 209 | fn isfp n ulong to bool |
| 210 | if ne n 50 |
| 211 | ret false |
| 212 | end |
| 213 | j = ulong 0 |
| 214 | while lt j 7 bound 8 |
| 215 | if ne get ab j get tsha j |
| 216 | ret false |
| 217 | end |
| 218 | j = add j 1 |
| 219 | end |
| 220 | while lt j 50 bound 64 |
| 221 | c = get ab j |
| 222 | if nope or (isaln c) (or eq c 43 eq c 47) |
| 223 | ret false |
| 224 | end |
| 225 | j = add j 1 |
| 226 | end |
| 227 | ret true |
| 228 | end |
| 229 | fn isalias n ulong to bool |
| 230 | if eq n 0 |
| 231 | ret false |
| 232 | end |
| 233 | if and eq n 1 eq get ab 0 45 |
| 234 | ret true |
| 235 | end |
| 236 | if or lt n 25 gt n 65 |
| 237 | ret false |
| 238 | end |
| 239 | j = ulong 0 |
| 240 | while lt j 5 bound 8 |
| 241 | if ne get ab j get trad j |
| 242 | ret false |
| 243 | end |
| 244 | j = add j 1 |
| 245 | end |
| 246 | while lt j n bound 256 |
| 247 | if nope isaln get ab j |
| 248 | ret false |
| 249 | end |
| 250 | j = add j 1 |
| 251 | end |
| 252 | ret true |
| 253 | end |
| 254 | fn isb64c c uchar to bool |
| 255 | ret or (isaln c) (or eq c 43 eq c 47) |
| 256 | end |
| 257 | note ispub: the 68-character ssh-ed25519 public-key blob, no padding, no comment |
| 258 | fn ispub n ulong to bool |
| 259 | if ne n 68 |
| 260 | ret false |
| 261 | end |
| 262 | j = ulong 0 |
| 263 | while lt j n bound 128 |
| 264 | if nope isb64c get ab j |
| 265 | ret false |
| 266 | end |
| 267 | j = add j 1 |
| 268 | end |
| 269 | ret true |
| 270 | end |
| 271 | fn isreason n ulong to bool |
| 272 | if and eq n 1 eq get ab 0 45 |
| 273 | ret true |
| 274 | end |
| 275 | ret isreq n |
| 276 | end |
| 277 | note valid: field rule k for ab[0,n) |
| 278 | fn valid k ulong n ulong to bool |
| 279 | if eq k 1 |
| 280 | ret isname n |
| 281 | end |
| 282 | if eq k 2 |
| 283 | ret isref n |
| 284 | end |
| 285 | if eq k 3 |
| 286 | ret hexn n 40 |
| 287 | end |
| 288 | if eq k 4 |
| 289 | ret hexn n 64 |
| 290 | end |
| 291 | if eq k 5 |
| 292 | ret isreq n |
| 293 | end |
| 294 | if eq k 6 |
| 295 | ret isfp n |
| 296 | end |
| 297 | if eq k 7 |
| 298 | ret or (same tpub n) (same tpriv n) |
| 299 | end |
| 300 | if eq k 8 |
| 301 | ret isalias n |
| 302 | end |
| 303 | if eq k 9 |
| 304 | ret hexn n 32 |
| 305 | end |
| 306 | if eq k 10 |
| 307 | ret ispub n |
| 308 | end |
| 309 | if eq k 11 |
| 310 | ret isreason n |
| 311 | end |
| 312 | ret false |
| 313 | end |
| 314 | note room: a payload never needs more than ob; exit 91 says this note is wrong |
| 315 | fn room n ulong to void |
| 316 | if gt n 400000 |
| 317 | exit 91 |
| 318 | end |
| 319 | end |
| 320 | fn emit t view uchar * to void |
| 321 | o = get ol 0 |
| 322 | m = len t |
| 323 | room add o m |
| 324 | j = ulong 0 |
| 325 | while lt j m bound 4096 |
| 326 | put ob add o j get t j |
| 327 | j = add j 1 |
| 328 | end |
| 329 | put ol 0 add o m |
| 330 | end |
| 331 | fn emita n ulong to void |
| 332 | o = get ol 0 |
| 333 | room add o n |
| 334 | j = ulong 0 |
| 335 | while lt j n bound 200000 |
| 336 | put ob add o j get ab j |
| 337 | j = add j 1 |
| 338 | end |
| 339 | put ol 0 add o n |
| 340 | end |
| 341 | fn errw t view uchar * to void |
| 342 | k = write 2 t 0 len t |
| 343 | end |
| 344 | note putf: argument i must satisfy rule k; append "key value\n" to the payload, or refuse |
| 345 | fn putf i ulong key view uchar * k ulong to void |
| 346 | r = loada i |
| 347 | if lt r 0 |
| 348 | errw tref |
| 349 | errw key |
| 350 | errw tnl |
| 351 | exit 1 |
| 352 | end |
| 353 | n = ulong r |
| 354 | if nope valid k n |
| 355 | errw tref |
| 356 | errw key |
| 357 | errw tnl |
| 358 | exit 1 |
| 359 | end |
| 360 | emit key |
| 361 | emita n |
| 362 | emit tnl |
| 363 | end |
| 364 | fn flush to void |
| 365 | e = get ol 0 |
| 366 | p = ulong 0 |
| 367 | while lt p e bound 2000000 |
| 368 | k = write 1 ob p sub e p |
| 369 | if le k 0 |
| 370 | exit 90 |
| 371 | end |
| 372 | p = add p ulong k |
| 373 | end |
| 374 | end |
| 375 | note docheck: landrec check RULE VALUE |
| 376 | fn docheck to int |
| 377 | r = loada 2 |
| 378 | if lt r 0 |
| 379 | ret 2 |
| 380 | end |
| 381 | m = ulong r |
| 382 | k = ulong 0 |
| 383 | if same tname m |
| 384 | k = 1 |
| 385 | end |
| 386 | if same tbr m |
| 387 | k = 2 |
| 388 | end |
| 389 | if same trq m |
| 390 | k = 5 |
| 391 | end |
| 392 | if same town m |
| 393 | k = 6 |
| 394 | end |
| 395 | if same tpubk m |
| 396 | k = 10 |
| 397 | end |
| 398 | if same treason m |
| 399 | k = 11 |
| 400 | end |
| 401 | if eq k 0 |
| 402 | ret 2 |
| 403 | end |
| 404 | v = loada 3 |
| 405 | if lt v 0 |
| 406 | ret 1 |
| 407 | end |
| 408 | if valid k ulong v |
| 409 | ret 0 |
| 410 | end |
| 411 | ret 1 |
| 412 | end |
| 413 | fn main to int |
| 414 | put ol 0 0 |
| 415 | c = argcnt |
| 416 | if lt c 2 |
| 417 | errw tusage |
| 418 | ret 2 |
| 419 | end |
| 420 | r = loada 1 |
| 421 | if lt r 0 |
| 422 | errw tusage |
| 423 | ret 2 |
| 424 | end |
| 425 | m = ulong r |
| 426 | isl = same tland m |
| 427 | isp = same tproj m |
| 428 | if and (same tcheck m) eq c 4 |
| 429 | ret docheck |
| 430 | end |
| 431 | if and isl eq c 9 |
| 432 | emit hland |
| 433 | putf 2 kproj 1 |
| 434 | putf 3 kbranch 2 |
| 435 | putf 4 kold 3 |
| 436 | putf 5 knew 3 |
| 437 | putf 6 krec 4 |
| 438 | putf 7 kver 4 |
| 439 | putf 8 kreq 5 |
| 440 | flush |
| 441 | ret 0 |
| 442 | end |
| 443 | if and isp eq c 8 |
| 444 | emit hproj |
| 445 | putf 2 kproj 1 |
| 446 | putf 3 kbranch 2 |
| 447 | putf 4 kvis 7 |
| 448 | putf 5 kown 6 |
| 449 | putf 6 kali 8 |
| 450 | putf 7 knon 9 |
| 451 | flush |
| 452 | ret 0 |
| 453 | end |
| 454 | if and (same tsucc m) eq c 7 |
| 455 | emit hsucc |
| 456 | putf 2 kproj 1 |
| 457 | putf 3 kold 6 |
| 458 | putf 4 knew 6 |
| 459 | putf 5 kpub 10 |
| 460 | putf 6 kreason 11 |
| 461 | flush |
| 462 | ret 0 |
| 463 | end |
| 464 | errw tusage |
| 465 | ret 2 |
| 466 | end |