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
omega-mv / apps / interplane-forge / collab / co9comp.om
| 1 | note collab/co9comp.om (ForgePatches): Phase A of docs/collab-write.md, the compose store. |
| 2 | note The web composes and checks a comment, a review, a new issue or a new patch; it never writes to |
| 3 | note Radicle. A checked compose is kept in memory for 15 minutes in one of 32 slots, bound to the |
| 4 | note session's CSRF token, the repo and a 128-bit random id (/dev/urandom); GET compose/<cid> shows the |
| 5 | note preview and the exact rad or git command the author runs in a clone, signing with their own key. |
| 6 | note Kinds: 1 issue comment, 2 patch comment, 3 patch review, 4 new issue, 5 new patch; 0 free slot. |
| 7 | text tcurnd "/dev/urandom" |
| 8 | global gczk ulong 32 |
| 9 | global gczt ulong 32 |
| 10 | global gczix ulong 32 |
| 11 | global gczid uchar 1024 |
| 12 | global gczcs uchar 1024 |
| 13 | global gcztg uchar 1280 |
| 14 | global gczrv uchar 1280 |
| 15 | global gczrn ulong 32 |
| 16 | global gczf ulong 32 |
| 17 | global gczti uchar 8192 |
| 18 | global gcztl ulong 32 |
| 19 | global gczb uchar 1920000 |
| 20 | global gczbl ulong 32 |
| 21 | note staging for cozsave: title, flags (1 accept, 2 reject, 3 review without verdict, 8 draft), revision |
| 22 | global gcsti uchar 256 |
| 23 | global gcstil ulong 1 |
| 24 | global gcsf ulong 1 |
| 25 | global gcsrv ulong 1 |
| 26 | note ---- slots |
| 27 | fn conow to ulong |
| 28 | ret div ulong realns 1000000000 |
| 29 | end |
| 30 | fn cozlive s ulong to bool |
| 31 | if eq get gczk s 0 |
| 32 | ret false |
| 33 | end |
| 34 | ret le sub conow get gczt s 900 |
| 35 | end |
| 36 | note cozslot: a free or expired slot, else the oldest |
| 37 | fn cozslot to ulong |
| 38 | w = ulong 0 |
| 39 | for s ulong 32 |
| 40 | if eq cozlive s false |
| 41 | ret s |
| 42 | end |
| 43 | if lt get gczt s get gczt w |
| 44 | w = s |
| 45 | end |
| 46 | end |
| 47 | ret w |
| 48 | end |
| 49 | note cozsave kd n: store a compose of kind kd with body gcfv[0,n) and the staged title, flags and |
| 50 | note revision; the slot, or 99 when no random id could be read |
| 51 | fn cozsave kd ulong n ulong to ulong |
| 52 | s = cozslot |
| 53 | if eq cozrand s false |
| 54 | ret ulong 99 |
| 55 | end |
| 56 | put gczk s kd |
| 57 | put gczt s conow |
| 58 | put gczix s get fridx 0 |
| 59 | put gczf s get gcsf 0 |
| 60 | put gczbl s n |
| 61 | o = mul s 60000 |
| 62 | for k ulong n bound 60000 |
| 63 | put gczb add o k get gcfv k |
| 64 | end |
| 65 | cozsave2 s |
| 66 | ret s |
| 67 | end |
| 68 | fn cozsave2 s ulong to void |
| 69 | for k ulong 32 |
| 70 | put gczcs add mul s 32 k get fcsrf k |
| 71 | end |
| 72 | for k ulong 40 |
| 73 | put gcztg add mul s 40 k get gcid k |
| 74 | end |
| 75 | r = get gcsrv 0 |
| 76 | put gczrn s add r 1 |
| 77 | if lt r 64 |
| 78 | for k ulong 40 |
| 79 | put gczrv add mul s 40 k get gcrv add mul r 40 k |
| 80 | end |
| 81 | end |
| 82 | n = get gcstil 0 |
| 83 | put gcztl s n |
| 84 | for k ulong n bound 256 |
| 85 | put gczti add mul s 256 k get gcsti k |
| 86 | end |
| 87 | end |
| 88 | note cozrand s: the slot's id, 32 lowercase hex characters of 16 bytes from /dev/urandom |
| 89 | fn cozrand s ulong to bool |
| 90 | b = new uchar 16 0 |
| 91 | fd = fopen tcurnd 0 len tcurnd 524288 0 |
| 92 | if lt fd 0 |
| 93 | ret false |
| 94 | end |
| 95 | r = read int fd b 0 16 |
| 96 | x = fclose int fd |
| 97 | if ne r 16 |
| 98 | ret false |
| 99 | end |
| 100 | for i ulong 16 |
| 101 | v = get b i |
| 102 | put gczid add mul s 32 mul i 2 cohxd shr v 4 |
| 103 | put gczid add add mul s 32 mul i 2 1 cohxd and v 15 |
| 104 | end |
| 105 | ret true |
| 106 | end |
| 107 | fn cohxd v uchar to uchar |
| 108 | if lt v 10 |
| 109 | ret uchar add v 48 |
| 110 | end |
| 111 | ret uchar add v 87 |
| 112 | end |
| 113 | note cozfind a: the live slot whose id is frest[a,a+32), made in this session (CSRF token) for this |
| 114 | note repo; 99 when there is none |
| 115 | fn cozfind a ulong to ulong |
| 116 | if or ne get fcsrfl 0 32 gt add a 32 get frestl 0 |
| 117 | ret ulong 99 |
| 118 | end |
| 119 | for s ulong 32 |
| 120 | if cozlive s |
| 121 | if cozmat s a |
| 122 | ret s |
| 123 | end |
| 124 | end |
| 125 | end |
| 126 | ret ulong 99 |
| 127 | end |
| 128 | fn cozmat s ulong a ulong to bool |
| 129 | if ne get gczix s get fridx 0 |
| 130 | ret false |
| 131 | end |
| 132 | d = uchar 0 |
| 133 | for k ulong 32 |
| 134 | d = or d xor get gczid add mul s 32 k get frest add a k |
| 135 | d = or d xor get gczcs add mul s 32 k get fcsrf k |
| 136 | end |
| 137 | ret eq d 0 |
| 138 | end |