From f8a0be4c70efcf60c3306aa84a6c1658a86ee15e Mon Sep 17 00:00:00 2001 From: James Barclay Date: Wed, 17 Aug 2016 16:09:57 -0400 Subject: [PATCH] Return immutable data from generateSecureRandomData:length and use OSStatus to check the status of SecRandomCopyBytes. (#1306) --- Signal/src/crypto/CryptoTools.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Signal/src/crypto/CryptoTools.m b/Signal/src/crypto/CryptoTools.m index 9bd3f6e26..7df5f43dc 100644 --- a/Signal/src/crypto/CryptoTools.m +++ b/Signal/src/crypto/CryptoTools.m @@ -10,11 +10,11 @@ + (NSData *)generateSecureRandomData:(NSUInteger)length { NSMutableData *d = [NSMutableData dataWithLength:length]; - int err = SecRandomCopyBytes(kSecRandomDefault, length, [d mutableBytes]); - if (err != 0) { + OSStatus status = SecRandomCopyBytes(kSecRandomDefault, length, [d mutableBytes]); + if (status != noErr) { [SecurityFailure raise:@"SecRandomCopyBytes failed"]; } - return d; + return [d copy]; } + (uint16_t)generateSecureRandomUInt16 {