From 4155719422d416fb9af8cc6266697ebe16264538 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Tue, 25 Mar 2025 17:02:48 -0400 Subject: cmd/anubis: allow setting key bytes in flag/envvar (#97) * 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 * review feedback fixups Signed-off-by: Xe Iaso * Update cmd/anubis/main.go Signed-off-by: Xe Iaso * Apply suggestions from code review Co-authored-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Signed-off-by: Xe Iaso --------- Signed-off-by: Xe Iaso Co-authored-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- docs/src/components/RandomKey/index.tsx | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 docs/src/components/RandomKey/index.tsx (limited to 'docs/src') diff --git a/docs/src/components/RandomKey/index.tsx b/docs/src/components/RandomKey/index.tsx new file mode 100644 index 0000000..e7ced3e --- /dev/null +++ b/docs/src/components/RandomKey/index.tsx @@ -0,0 +1,42 @@ +import { useState, useCallback } 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 ( + Loading...}> + {() => { + const [key, setKey] = useState(genRandomKey()); + const genRandomKeyCb = useCallback(() => { + setKey(genRandomKey()); + }); + return ( + + {key} + + + + ); + }} + + ); +} -- cgit v1.2.3