Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Random.generate() be non-throwing? #17

Open
twostraws opened this issue Jan 23, 2017 · 0 comments
Open

Can Random.generate() be non-throwing? #17

twostraws opened this issue Jan 23, 2017 · 0 comments

Comments

@twostraws
Copy link

When I need to generate some random data for a string, I'd run code like this:

if let randomBytes = try? Random.generate(byteCount: 64) {
    randomString = CryptoUtils.hexString(from: randomBytes)
} else {
    randomString = generateMyOwnRandomStringSomehow()
}

If I'm trying to generate something important, e.g. a salt, the generateMyOwnRandomStringSomehow() is a weak point because it relies on users to have some idea of PRNG techniques. Is it possible to make Random.generate() always return a value, perhaps by implementing a second generation algorithm that can be used if the preferred algorithm fails?

(Note: the answer may well be "No", but I'm following the "if you don't ask, you don't get" approach.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants