Skip to content

Commit f8a0be4

Browse files
futureimperfectmichaelkirk
authored andcommitted
Return immutable data from generateSecureRandomData:length and use OSStatus to check the status of SecRandomCopyBytes. (signalapp#1306)
1 parent b29174a commit f8a0be4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Signal/src/crypto/CryptoTools.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ @implementation CryptoTools
1010

1111
+ (NSData *)generateSecureRandomData:(NSUInteger)length {
1212
NSMutableData *d = [NSMutableData dataWithLength:length];
13-
int err = SecRandomCopyBytes(kSecRandomDefault, length, [d mutableBytes]);
14-
if (err != 0) {
13+
OSStatus status = SecRandomCopyBytes(kSecRandomDefault, length, [d mutableBytes]);
14+
if (status != noErr) {
1515
[SecurityFailure raise:@"SecRandomCopyBytes failed"];
1616
}
17-
return d;
17+
return [d copy];
1818
}
1919

2020
+ (uint16_t)generateSecureRandomUInt16 {

0 commit comments

Comments
 (0)