mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: byte => u8
This commit is contained in:
@ -23,7 +23,7 @@ pub fn constant_time_compare(x []byte, y []byte) int {
|
||||
if x.len != y.len {
|
||||
return 0
|
||||
}
|
||||
mut v := byte(0)
|
||||
mut v := u8(0)
|
||||
for i in 0 .. x.len {
|
||||
v |= x[i] ^ y[i]
|
||||
}
|
||||
@ -37,8 +37,8 @@ pub fn constant_time_copy(v int, mut x []byte, y []byte) {
|
||||
if x.len != y.len {
|
||||
panic('subtle: arrays have different lengths')
|
||||
}
|
||||
xmask := byte(v - 1)
|
||||
ymask := byte(~(v - 1))
|
||||
xmask := u8(v - 1)
|
||||
ymask := u8(~(v - 1))
|
||||
for i := 0; i < x.len; i++ {
|
||||
x[i] = x[i] & xmask | y[i] & ymask
|
||||
}
|
||||
|
@ -35,20 +35,20 @@ fn test_constant_time_select() {
|
||||
}
|
||||
|
||||
fn test_constant_time_compare() {
|
||||
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3]) == 1
|
||||
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 9]) == 0
|
||||
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3, 4]) == 0
|
||||
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2]) == 0
|
||||
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 3]) == 1
|
||||
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 9]) == 0
|
||||
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 3, 4]) == 0
|
||||
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2]) == 0
|
||||
}
|
||||
|
||||
fn test_constant_time_copy() {
|
||||
y := [byte(3), 4, 5]
|
||||
mut x := [byte(0), 0, 0]
|
||||
y := [u8(3), 4, 5]
|
||||
mut x := [u8(0), 0, 0]
|
||||
constant_time_copy(0, mut x, y)
|
||||
assert x == [byte(0), 0, 0]
|
||||
assert x == [u8(0), 0, 0]
|
||||
constant_time_copy(1, mut x, y)
|
||||
assert x == y
|
||||
assert x == [byte(3), 4, 5]
|
||||
assert x == [u8(3), 4, 5]
|
||||
}
|
||||
|
||||
fn test_constant_time_less_or_eq() {
|
||||
|
Reference in New Issue
Block a user