| 14 Oct 2025 |
raitobezarius | What about {from,to}{NixBase32,Base16,Base64} as primops? | 15:51:13 |
raitobezarius | Which seems to be that proposal ^ | 15:51:21 |
raitobezarius | Ideally, the primops should live under a namespace, e.g. conversions or something | 15:51:53 |
emily | IIRC Base32 is not unambiguously defined for some sizes of byte string. | 16:03:52 |
emily | so I believe these functions would not round-trip etc. | 16:04:03 |
emily | I am not sure if you would need to manually add/remove padding in Nix code to make the conversions go through | 16:04:38 |
emily | it's at least avoided by convertHash taking specification of a hash which restricts the bit format to one of the "standard" ones | 16:04:48 |
emily | (it would also not be backportable to versions that use a NUL-terminated string representation and would be a permanent(?) divergence from Nix's choice to forbid NULs more thoroughly instead of course, but these may not be issues) | 16:05:51 |
emily | I am also not entirely sure if there are any gremlins in the <algo>:<digest> format etc. which would be a pain to deal with in Nix | 16:06:15 |
emily | though it's probably tolerable if it's just in one lib function in Nixpkgs | 16:06:22 |
raitobezarius | Do you have a clear example of case where {from,to}NixBase32 would not roundtrip? | 16:06:32 |
raitobezarius | It's already known that Nix flavor of base32 is a bit special, but I cannot remember of seeing there was unambiguous cases. If anything, Nix always accepted $BASE32 + any char for a while (and probably still do). | 16:07:06 |
emily | frankly the hash formats are all very weird and I am not sure if it is really better to have their format details exposed to userspace rather than just treating them as opaque but interconvertible blogs | 16:07:17 |
raitobezarius | It never honored any form of strict implementation of RFC4648 | 16:07:22 |
emily | e.g. proliferation of Base32 use doesn't seem like a great thing | 16:07:32 |
emily | I believe there are cases where appending (or prepending?) a NUL byte will not change the result | 16:07:40 |
emily | because of padding | 16:07:45 |
emily | and therefore decoding must fail to round-trip on one of them | 16:07:56 |
emily | I recall running into this when factoring out the Base32 functions | 16:08:03 |
emily | Base32 lacks anything like Base64's = | 16:08:46 |
raitobezarius | There are, but it only cause problem for strict implementations outside of CppNix/Lix | 16:09:48 |
raitobezarius | (i.e. back when we dealt with nixbase32 in snix.) | 16:10:02 |
emily | well, I mean that with to/from functions, Nixpkgs lib will have to implement the <algo>:<digest> and SRI logic 1:1 to match the implementations | 16:10:28 |
raitobezarius | I'm really unhappy about convertHash as a primitive, it also does not enable any form of detection of what pairs does it support and what it can do | 16:10:34 |
emily | this may be more "pure" but it also feels a bit error-prone compared to just having convertHash handle it | 16:10:43 |
emily | but it at least only needs solving once | 16:10:52 |
emily | (unless the quirks change later) | 16:10:55 |
raitobezarius | Yeah, but that direction is easy because the implementations accepts more than they should | 16:10:57 |
raitobezarius | which would be a regression caught by tests hopefully | 16:11:30 |
emily | I think you would need a size parameter | 16:11:35 |