diff options
| author | Xe Iaso <me@xeiaso.net> | 2025-03-23 08:56:44 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2025-03-25 16:58:30 -0400 |
| commit | 0447a7fd3aa5b832200dbd7ef33b1de52dc79512 (patch) | |
| tree | b8717f1d4ec49046e51cbb86e92894b40858737a /docs/src/components/RandomKey | |
| parent | f29a200f09ca3f720266164421304ed28de57dc6 (diff) | |
| download | anubis-0447a7fd3aa5b832200dbd7ef33b1de52dc79512.tar.xz anubis-0447a7fd3aa5b832200dbd7ef33b1de52dc79512.zip | |
cmd/anubis: allow setting key bytes in flag/envvar
Docs are updated to generate a random key on load and when people press
the recycle button.
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'docs/src/components/RandomKey')
| -rw-r--r-- | docs/src/components/RandomKey/index.tsx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/docs/src/components/RandomKey/index.tsx b/docs/src/components/RandomKey/index.tsx new file mode 100644 index 0000000..4f94a4d --- /dev/null +++ b/docs/src/components/RandomKey/index.tsx @@ -0,0 +1,43 @@ +import { useState, useEffect } from "react"; +import Code from "@theme/CodeInline"; +import BrowserOnly from "@docusaurus/BrowserOnly"; + +// https://www.xaymar.com/articles/2020/12/08/fastest-uint8array-to-hex-string-conversion-in-javascript/ +function toHex(buffer) { + return Array.prototype.map + .call(buffer, (x) => ("00" + x.toString(16)).slice(-2)) + .join(""); +} + +export const genRandomKey = (): String => { + const array = new Uint8Array(32); + self.crypto.getRandomValues(array); + return toHex(array); +}; + +export default function RandomKey() { + return ( + <BrowserOnly fallback={<div>Loading...</div>}> + {() => { + const [key, setKey] = useState<String>(genRandomKey()); + const [refresh, setRefresh] = useState<number>(0); + useEffect(() => { + setKey(genRandomKey); + }, [refresh]); + return ( + <span> + <Code>{key}</Code> + <span style={{ marginLeft: "0.25rem", marginRight: "0.25rem" }} /> + <button + onClick={() => { + setRefresh((n) => n + 1); + }} + > + ♻️ + </button> + </span> + ); + }} + </BrowserOnly> + ); +} |
