Skip to content

Commit 4d5006f

Browse files
committed
Rename platform-specific constants
Also fixup documentation and error messages
1 parent bbdd583 commit 4d5006f

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/error.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ impl Error {
3131
pub const UNSUPPORTED: Error = internal_error!(0);
3232
/// The platform-specific `errno` returned a non-positive value.
3333
pub const ERRNO_NOT_POSITIVE: Error = internal_error!(1);
34-
/// Call to [`SecRandomCopyBytes`](https://developer.apple.com/documentation/security/1399291-secrandomcopybytes) failed.
35-
pub const SEC_RANDOM_FAILED: Error = internal_error!(3);
36-
/// Call to [`RtlGenRandom`](https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom) failed.
37-
pub const RTL_GEN_RANDOM_FAILED: Error = internal_error!(4);
34+
/// Call to iOS [`SecRandomCopyBytes`](https://developer.apple.com/documentation/security/1399291-secrandomcopybytes) failed.
35+
pub const IOS_SEC_RANDOM: Error = internal_error!(3);
36+
/// Call to Windows [`RtlGenRandom`](https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom) failed.
37+
pub const WINDOWS_RTL_GEN_RANDOM: Error = internal_error!(4);
3838
/// RDRAND instruction failed due to a hardware issue.
3939
pub const FAILED_RDRAND: Error = internal_error!(5);
4040
/// RDRAND instruction unsupported on this target.
@@ -47,8 +47,8 @@ impl Error {
4747
pub const STDWEB_NO_RNG: Error = internal_error!(9);
4848
/// Using `stdweb`, invoking a cryptographic RNG failed.
4949
pub const STDWEB_RNG_FAILED: Error = internal_error!(10);
50-
/// On VxWorks, random number generator is not yet initialized.
51-
pub const RAND_SECURE_FATAL: Error = internal_error!(11);
50+
/// On VxWorks, call to `randSecure` failed (random number generator is not yet initialized).
51+
pub const VXWORKS_RAND_SECURE: Error = internal_error!(11);
5252

5353
/// Codes below this point represent OS Errors (i.e. positive i32 values).
5454
/// Codes at or above this point, but below [`Error::CUSTOM_START`] are
@@ -155,15 +155,15 @@ fn internal_desc(error: Error) -> Option<&'static str> {
155155
match error {
156156
Error::UNSUPPORTED => Some("getrandom: this target is not supported"),
157157
Error::ERRNO_NOT_POSITIVE => Some("errno: did not return a positive value"),
158-
Error::SEC_RANDOM_FAILED => Some("SecRandomCopyBytes: call failed"),
159-
Error::RTL_GEN_RANDOM_FAILED => Some("RtlGenRandom: call failed"),
158+
Error::IOS_SEC_RANDOM => Some("SecRandomCopyBytes: iOS Secuirty framework failure"),
159+
Error::WINDOWS_RTL_GEN_RANDOM => Some("RtlGenRandom: Windows system function failure"),
160160
Error::FAILED_RDRAND => Some("RDRAND: failed multiple times: CPU issue likely"),
161161
Error::NO_RDRAND => Some("RDRAND: instruction not supported"),
162162
Error::BINDGEN_CRYPTO_UNDEF => Some("wasm-bindgen: self.crypto is undefined"),
163163
Error::BINDGEN_GRV_UNDEF => Some("wasm-bindgen: crypto.getRandomValues is undefined"),
164164
Error::STDWEB_NO_RNG => Some("stdweb: no randomness source available"),
165165
Error::STDWEB_RNG_FAILED => Some("stdweb: failed to get randomness"),
166-
Error::RAND_SECURE_FATAL => Some("randSecure: VxWorks RNG module is not initialized"),
166+
Error::VXWORKS_RAND_SECURE => Some("randSecure: VxWorks RNG module is not initialized"),
167167
_ => None,
168168
}
169169
}

src/ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "C" {
2424
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
2525
let ret = unsafe { SecRandomCopyBytes(kSecRandomDefault, dest.len(), dest.as_mut_ptr()) };
2626
if ret == -1 {
27-
Err(Error::SEC_RANDOM_FAILED)
27+
Err(Error::IOS_SEC_RANDOM)
2828
} else {
2929
Ok(())
3030
}

src/vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1616
while !RNG_INIT.load(Relaxed) {
1717
let ret = unsafe { libc::randSecure() };
1818
if ret < 0 {
19-
return Err(Error::RAND_SECURE_FATAL);
19+
return Err(Error::VXWORKS_RAND_SECURE);
2020
} else if ret > 0 {
2121
RNG_INIT.store(true, Relaxed);
2222
break;

src/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1919
for chunk in dest.chunks_mut(u32::max_value() as usize) {
2020
let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr(), chunk.len() as u32) };
2121
if ret == 0 {
22-
return Err(Error::RTL_GEN_RANDOM_FAILED);
22+
return Err(Error::WINDOWS_RTL_GEN_RANDOM);
2323
}
2424
}
2525
Ok(())

0 commit comments

Comments
 (0)