interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / ipl / om / landrec.om

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