Skip to content

Commit 0731ec8

Browse files
committed
I changed this file's source code more rust-like (especially for functions' returned values)
1 parent c6436e8 commit 0731ec8

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/rust-crypto/util.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn supports_aesni() -> bool {
2525
asm!("")
2626
}
2727

28-
return (flags & 0x02000000) != 0;
28+
(flags & 0x02000000) != 0
2929
}
3030

3131
#[cfg(target_arch = "x86")]
@@ -54,7 +54,7 @@ unsafe fn fixed_time_eq_asm(mut lhsp: *const u8, mut rhsp: *const u8, mut count:
5454
: "volatile" // flags
5555
);
5656

57-
return result == 0;
57+
result == 0
5858
}
5959

6060
#[cfg(target_arch = "arm")]
@@ -82,25 +82,24 @@ unsafe fn fixed_time_eq_asm(mut lhsp: *const u8, mut rhsp: *const u8, mut count:
8282
: "volatile" // flags
8383
);
8484

85-
return result == 0;
85+
result == 0
8686
}
8787

8888
/// Compare two vectors using a fixed number of operations. If the two vectors are not of equal
8989
/// length, the function returns false immediately.
9090
pub fn fixed_time_eq(lhs: &[u8], rhs: &[u8]) -> bool {
9191
if lhs.len() != rhs.len() {
92-
return false;
93-
}
94-
if lhs.len() == 0 {
95-
return true;
96-
}
97-
98-
let count = lhs.len();
99-
100-
unsafe {
101-
let lhsp = lhs.unsafe_get(0);
102-
let rhsp = rhs.unsafe_get(0);
103-
return fixed_time_eq_asm(lhsp, rhsp, count);
92+
false
93+
} else if lhs.len() == 0 {
94+
true
95+
} else {
96+
let count = lhs.len();
97+
98+
unsafe {
99+
let lhsp = lhs.unsafe_get(0);
100+
let rhsp = rhs.unsafe_get(0);
101+
fixed_time_eq_asm(lhsp, rhsp, count)
102+
}
104103
}
105104
}
106105

0 commit comments

Comments
 (0)