1
0
mirror of https://github.com/S2-/securerandomstring.git synced 2025-08-01 18:00:06 +02:00

if the generated string is not long enough, retry

This commit is contained in:
s2
2024-09-26 13:18:22 +02:00
parent 51274ca17b
commit af5b2eaced

View File

@@ -32,7 +32,7 @@ function srs(options, cb) {
string = string.replace(/\//g, '_').replace(/\+/g, '-');
}
if (string.length < length) {
throw new Error(`Generated string is too short. Please catch this Error and try again.`);
return _finish(crypto.randomBytes(length));
}
return string.substr(0, length);
}