Skip to content

Commit 21e03e8

Browse files
authored
ios: Fix Error checking for SecRandomCopyBytes (#244)
Apple's documentation for SecRandomCopyBytes says that errSecSuccess is returned on success, and all other values indicate failure. https://developer.apple.com/documentation/security/1399291-secrandomcopybytes The SecBase.h header also clearly establishes that `errSecSuccess = 0`: https://opensource.apple.com/source/Security/Security-55471/sec/Security/SecBase.h.auto.html Fixes #243 Signed-off-by: Joe Richey <[email protected]>
1 parent e6e7dd6 commit 21e03e8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/ios.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ extern "C" {
1818
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1919
// Apple's documentation guarantees kSecRandomDefault is a synonym for NULL.
2020
let ret = unsafe { SecRandomCopyBytes(null(), dest.len(), dest.as_mut_ptr()) };
21-
if ret == -1 {
21+
// errSecSuccess (from SecBase.h) is always zero.
22+
if ret != 0 {
2223
Err(Error::IOS_SEC_RANDOM)
2324
} else {
2425
Ok(())

0 commit comments

Comments
 (0)