| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2023-06-06 04:07:05 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2024-01-10 17:58:50 UTC |
| parent | 081252452d18403cb3bbf239562ef26d2e32434f |
| xmpp/ID.hx | +5 | -23 |
diff --git a/xmpp/ID.hx b/xmpp/ID.hx index 9167fa5..046a09f 100644 --- a/xmpp/ID.hx +++ b/xmpp/ID.hx @@ -1,39 +1,21 @@ package xmpp; -import haxe.crypto.Base64; -import haxe.io.Bytes; - -#if nodejs -import js.node.Crypto; -#end +import hx.strings.RandomStrings; class ID { public static function tiny():String { - return Base64.urlEncode(getRandomBytes(3)); + return RandomStrings.randomAsciiAlphaNumeric(6); } public static function short():String { - return Base64.urlEncode(getRandomBytes(9)); + return RandomStrings.randomAsciiAlphaNumeric(18); } public static function medium():String { - return Base64.urlEncode(getRandomBytes(18)); + return RandomStrings.randomAsciiAlphaNumeric(32); } public static function long():String { - return Base64.urlEncode(getRandomBytes(27)); - } - -#if nodejs - private static function getRandomBytes(n:Int):Bytes { - return Crypto.randomBytes(n).hxToBytes(); + return RandomStrings.randomUUIDv4(); } -#elseif js - private static function getRandomBytes(n:Int):Bytes { - var array = new js.lib.Uint8Array(n); - js.Browser.window.crypto.getRandomValues(array); - return Bytes.ofData(array.buffer); - } -#end - }