BlueCryptor icon indicating copy to clipboard operation
BlueCryptor copied to clipboard

Request: Random.generate(hexCharacterCount:)

Open twostraws opened this issue 8 years ago • 0 comments

The Random.generate(byteCount:) is a useful way of generating random bytes, but in my own work I found I was mostly using it to generate random strings for encryption purposes. This meant every call to Random.generate(byteCount:) was followed by a call to CryptoUtils.hexString(from:) to get a Swift string rather than just bytes.

If you could implement a Random.generate(hexCharacterCount:) method that combined the two together, it would be most appreciated. If this were combined with #17, then this code:

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

Would become simply this:

randomString = Random.generate(hexCharacterCount: 128)

(Note: There may well be a better name for this method.)

twostraws avatar Jan 23 '17 19:01 twostraws