Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nimble, uuid: generate UUIDs via std/sysrand, not pragmagic/uuids (ex…
…ercism#777) Replace two Nimble dependencies with our own code. Before this commit, configlet would generate a UUID with the Nimble packages pragmagic/uuids [1] and pragmagic/isaac [2] (itself a port of a C implementation [3]). However, the uuids package doesn't currently work on Windows with Nim 2.0 (due to Nim removing [4] some functions for a deprecated Win32 API). I've created a PR for the package [5], but: - That PR may not be sufficient. - I want to move away from these dependencies anyway (see exercism#424). - Our tests for UUID generation are good enough that we can confidently change the implementation. std/sysrand has been around for 2.5 years, but still warns that it hasn't been formally audited and doesn't guarantee safety for cryptographic purposes [6]. But it's probably good enough for our purposes: there's more use, review, and maintenance of std/sysrand than pragmagic/isaac anyway (whose most recent commit was in 2017, and ISAAC is questionable as a CSPRNG). In the tests, add a test for distinctness, and test more UUIDs. The `configlet uuid` command sets a limit of 1000 UUIDs, so let's assert that nothing strange happens above that number. Pick the number such that the genUuid tests take on the order of 100 ms. We can't make this a much higher number because we compile the tests in debug mode, and `configlet uuid` is intended for generating a small number of UUIDs. But I tested locally that the new implementation could produce 500M distinct valid version 4 UUIDs. As a future optimization we could either read more than 16 bytes each time from the system CSPRNG, or once again use the system CSPRNG to seed a different PRNG. Other benefits of this change: - It makes configlet more portable. Previously, `configlet uuid` would only work on Windows and platforms with `/dev/urandom` [7]. - We remove a gotcha from the nimble file version pinning. - We can rename from `genUUID` to `genUuid` fit our style elsewhere. Closes: exercism#424 [1] https://github.com/pragmagic/uuids/blob/8cb8720b567c/uuids.nim [2] https://github.com/pragmagic/isaac/blob/45a5cbbd54ff/src/isaac.nim [3] https://burtleburtle.net/bob/c/readable.c [4] nim-lang/Nim@612abda4f40b [5] https://www.github.com/pragmagic/uuids/pull/9 [6] https://github.com/nim-lang/Nim/blob/v2.0.0/lib/std/sysrand.nim#L10-L17 [7] https://github.com/pragmagic/uuids/blob/8cb8720b567c/uuids/urandom.nim#L41-L62
- Loading branch information