From 7d1ccf7dcdff9909b96e952693b0a2f555c38ca9 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 15 Apr 2022 18:35:56 +0300 Subject: [PATCH] all: handle fixed []u8 --- vlib/crypto/ed25519/internal/edwards25519/extra.v | 4 ++-- vlib/crypto/ed25519/internal/edwards25519/extra_test.v | 6 +++--- vlib/crypto/ed25519/internal/edwards25519/point.v | 6 +++--- vlib/crypto/ed25519/internal/edwards25519/scalar.v | 6 +++--- vlib/crypto/ed25519/internal/edwards25519/scalar_test.v | 2 +- vlib/crypto/md5/md5.v | 2 +- vlib/strconv/format_mem.c.v | 2 +- vlib/v/ast/table.v | 2 +- vlib/v/ast/types.v | 2 +- vlib/v/checker/containers.v | 2 +- vlib/v/fmt/fmt.v | 2 +- vlib/v/gen/js/js.v | 2 +- vlib/v/parser/containers.v | 4 ++-- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/vlib/crypto/ed25519/internal/edwards25519/extra.v b/vlib/crypto/ed25519/internal/edwards25519/extra.v index 56c53bf6dd..c6dd6a4dad 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/extra.v +++ b/vlib/crypto/ed25519/internal/edwards25519/extra.v @@ -89,11 +89,11 @@ fn is_on_curve(x Element, y Element, z Element, t Element) bool { pub fn (mut v Point) bytes_montgomery() []u8 { // This function is outlined to make the allocations inline in the caller // rather than happen on the heap. - mut buf := [32]byte{} + mut buf := [32]u8{} return v.bytes_montgomery_generic(mut buf) } -fn (mut v Point) bytes_montgomery_generic(mut buf [32]byte) []u8 { +fn (mut v Point) bytes_montgomery_generic(mut buf [32]u8) []u8 { check_initialized(v) // RFC 7748, Section 4.1 provides the bilinear map to calculate the diff --git a/vlib/crypto/ed25519/internal/edwards25519/extra_test.v b/vlib/crypto/ed25519/internal/edwards25519/extra_test.v index bad706515e..af492a9e40 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/extra_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/extra_test.v @@ -23,7 +23,7 @@ fn testsuite_begin() { // // Disabled curve25519 not available yet, but maybe can use own curve25519 /* -fn fn_mon(scalar [32]byte) bool { +fn fn_mon(scalar [32]u8) bool { mut s := new_scalar().set_bytes_with_clamping(scalar[..]) p := (&Point{}).scalar_base_mult(s) got := p.bytes_montgomery() @@ -32,7 +32,7 @@ fn fn_mon(scalar [32]byte) bool { } fn test_bytes_montgomery() { - /* f := fn(scalar [32]byte) bool { + /* f := fn(scalar [32]u8) bool { s := new_scalar().set_bytes_with_clamping(scalar[..]) p := (&Point{}).scalar_base_mult(s) got := p.bytes_montgomery() @@ -88,7 +88,7 @@ fn fn_cofactor(mut data []u8) bool { // 8 * p == (8 * s) * B mut sc := Scalar{ - s: [32]byte{} + s: [32]u8{} } sc.s[0] = u8(0x08) s.multiply(s, sc) diff --git a/vlib/crypto/ed25519/internal/edwards25519/point.v b/vlib/crypto/ed25519/internal/edwards25519/point.v index 5e3f645691..c3f1cc0021 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/point.v +++ b/vlib/crypto/ed25519/internal/edwards25519/point.v @@ -204,11 +204,11 @@ fn (mut v AffineCached) zero() AffineCached { pub fn (mut v Point) bytes() []u8 { // This function is outlined to make the allocations inline in the caller // rather than happen on the heap. - mut buf := [32]byte{} + mut buf := [32]u8{} return v.bytes_generic(mut buf) } -fn (mut v Point) bytes_generic(mut buf [32]byte) []u8 { +fn (mut v Point) bytes_generic(mut buf [32]u8) []u8 { check_initialized(v) mut zinv := Element{} @@ -226,7 +226,7 @@ fn (mut v Point) bytes_generic(mut buf [32]byte) []u8 { return out } -fn copy_field_element(mut buf [32]byte, mut v Element) []u8 { +fn copy_field_element(mut buf [32]u8, mut v Element) []u8 { // this fail in test /* copy(mut buf[..], v.bytes()) diff --git a/vlib/crypto/ed25519/internal/edwards25519/scalar.v b/vlib/crypto/ed25519/internal/edwards25519/scalar.v index 6cd411081b..eb90cc29e9 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/scalar.v +++ b/vlib/crypto/ed25519/internal/edwards25519/scalar.v @@ -18,7 +18,7 @@ struct Scalar { mut: // s is the Scalar value in little-endian. The value is always reduced // between operations. - s [32]byte + s [32]u8 } pub const ( @@ -210,7 +210,7 @@ fn load4(inp []u8) i64 { // Output: // s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l // where l = 2^252 + 27742317777372353535851937790883648493. -fn sc_mul_add(mut s [32]byte, a [32]byte, b [32]byte, c [32]byte) { +fn sc_mul_add(mut s [32]u8, a [32]u8, b [32]u8, c [32]u8) { a0 := 2097151 & load3(a[..]) a1 := 2097151 & (load4(a[2..]) >> 5) a2 := 2097151 & (load3(a[5..]) >> 2) @@ -653,7 +653,7 @@ fn sc_mul_add(mut s [32]byte, a [32]byte, b [32]byte, c [32]byte) { // Output: // s[0]+256*s[1]+...+256^31*s[31] = s mod l // where l = 2^252 + 27742317777372353535851937790883648493. -fn sc_reduce(mut out [32]byte, mut s []u8) { +fn sc_reduce(mut out [32]u8, mut s []u8) { assert out.len == 32 assert s.len == 64 mut s0 := 2097151 & load3(s[..]) diff --git a/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v b/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v index 09c80e6c82..5f8420b2e8 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v @@ -101,7 +101,7 @@ fn test_scalar_set_canonical_bytes_round_trip() ? { const ( sc_error = Scalar{ - s: [32]byte{init: (u8(-1))} + s: [32]u8{init: (u8(-1))} } ) diff --git a/vlib/crypto/md5/md5.v b/vlib/crypto/md5/md5.v index 6a13f506bb..1b7cd28dc3 100644 --- a/vlib/crypto/md5/md5.v +++ b/vlib/crypto/md5/md5.v @@ -105,7 +105,7 @@ pub fn (mut d Digest) checksum() []u8 { // 8 bytes representing the message length in bits. // // 1 byte end marker :: 0-63 padding bytes :: 8 byte length - // tmp := [1 + 63 + 8]byte{0x80} + // tmp := [1 + 63 + 8]u8{0x80} mut tmp := []u8{len: (1 + 63 + 8)} tmp[0] = 0x80 pad := ((55 - d.len) % 64) // calculate number of padding bytes diff --git a/vlib/strconv/format_mem.c.v b/vlib/strconv/format_mem.c.v index ea09b02027..44c9be8f24 100644 --- a/vlib/strconv/format_mem.c.v +++ b/vlib/strconv/format_mem.c.v @@ -81,7 +81,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { /* // Legacy version // max u64 18446744073709551615 => 20 byte - mut buf := [32]byte{} + mut buf := [32]u8{} mut i := 20 mut d1 := d for i >= (21 - n_char) { diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 39e1f94dae..34c985ae78 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -1407,7 +1407,7 @@ pub fn (mut t Table) complete_interface_check() { // // `128 > [16]u8` // -// `608 > [76]byte` +// `608 > [76]u8` pub fn (mut t Table) bitsize_to_type(bit_size int) Type { match bit_size { 8 { diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 1862b5cae7..63be8af531 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -950,7 +950,7 @@ pub mut: pub struct ArrayFixed { pub: size int - size_expr Expr // used by fmt for e.g. ´[my_const]byte´ + size_expr Expr // used by fmt for e.g. ´[my_const]u8´ pub mut: elem_type Type } diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index 754b1ef6cd..ba8ce66916 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -177,7 +177,7 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { } node.elem_type = elem_type } else if node.is_fixed && node.exprs.len == 1 && node.elem_type != ast.void_type { - // [50]byte + // [50]u8 mut fixed_size := i64(0) init_expr := node.exprs[0] c.expr(init_expr) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 5430241a55..5502b2d62c 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1578,7 +1578,7 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) { f.indent-- } f.write(']') - // `[100]byte` + // `[100]u8` if node.is_fixed { if node.has_val { f.write('!') diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 26821b9f99..be6d027cda 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -2119,7 +2119,7 @@ fn (mut g JsGen) gen_array_init_expr(it ast.ArrayInit) { g.expr(it.len_expr) g.write(')') } else if it.is_fixed && it.exprs.len == 1 { - // [100]byte codegen + // [100]u8 codegen t1 := g.new_tmp_var() t2 := g.new_tmp_var() g.writeln('(function() {') diff --git a/vlib/v/parser/containers.v b/vlib/v/parser/containers.v index beb6a40a21..f925f942b9 100644 --- a/vlib/v/parser/containers.v +++ b/vlib/v/parser/containers.v @@ -43,7 +43,7 @@ fn (mut p Parser) array_init() ast.ArrayInit { } last_pos = p.tok.pos() } else { - // [1,2,3] or [const]byte + // [1,2,3] or [const]u8 old_inside_array_lit := p.inside_array_lit p.inside_array_lit = true pre_cmnts = p.eat_comments() @@ -66,7 +66,7 @@ fn (mut p Parser) array_init() ast.ArrayInit { last_pos = p.tok.pos() p.check(.rsbr) if exprs.len == 1 && p.tok.kind in [.name, .amp, .lsbr] && p.tok.line_nr == line_nr { - // [100]byte + // [100]u8 elem_type = p.parse_type() last_pos = p.tok.pos() is_fixed = true