1
0
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:
Alexander Medvednikov
2022-04-15 14:58:56 +03:00
parent b49d873217
commit d4a0d6f73c
221 changed files with 1365 additions and 1365 deletions

View File

@ -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
}

View File

@ -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() {