diff --git a/cmd/tools/bench/wyhash.v b/cmd/tools/bench/wyhash.v index aa24ac850f..5104434ef1 100644 --- a/cmd/tools/bench/wyhash.v +++ b/cmd/tools/bench/wyhash.v @@ -14,7 +14,7 @@ fn main() { mut checksum := u64(0) mut start_pos := 0 mut bgenerating := benchmark.start() - mut bytepile := []byte{} + mut bytepile := []u8{} for _ in 0 .. sample_size * max_str_len { bytepile << u8(rand.int_in_range(40, 125) or { 40 }) } diff --git a/cmd/tools/vast/vast.v b/cmd/tools/vast/vast.v index 3bfbc4ea60..46124e73da 100644 --- a/cmd/tools/vast/vast.v +++ b/cmd/tools/vast/vast.v @@ -2209,7 +2209,7 @@ fn (t Tree) array_node_int(nodes []int) &Node { return arr } -fn (t Tree) array_node_u8(nodes []byte) &Node { +fn (t Tree) array_node_u8(nodes []u8) &Node { mut arr := new_array() for node in nodes { arr.add_item(t.number_node(node)) diff --git a/cmd/tools/vbin2v.v b/cmd/tools/vbin2v.v index 975b8fe6b5..8f22974c76 100644 --- a/cmd/tools/vbin2v.v +++ b/cmd/tools/vbin2v.v @@ -46,7 +46,7 @@ fn (context Context) footer() string { return ')\n' } -fn (context Context) file2v(bname string, fbytes []byte, bn_max int) string { +fn (context Context) file2v(bname string, fbytes []u8, bn_max int) string { mut sb := strings.new_builder(1000) bn_diff_len := bn_max - bname.len sb.write_string('\t${bname}_len' + ' '.repeat(bn_diff_len - 4) + ' = $fbytes.len\n') @@ -73,7 +73,7 @@ fn (context Context) file2v(bname string, fbytes []byte, bn_max int) string { return sb.str() } -fn (context Context) bname_and_bytes(file string) ?(string, []byte) { +fn (context Context) bname_and_bytes(file string) ?(string, []u8) { fname := os.file_name(file) fname_escaped := fname.replace_each(['.', '_', '-', '_']) byte_name := '$context.prefix$fname_escaped'.to_lower() @@ -120,7 +120,7 @@ fn main() { if context.write_file != '' && os.file_ext(context.write_file) !in ['.vv', '.v'] { context.write_file += '.v' } - mut file_byte_map := map[string][]byte{} + mut file_byte_map := map[string][]u8{} for file in real_files { bname, fbytes := context.bname_and_bytes(file) or { eprintln(err.msg()) diff --git a/examples/net_udp_server_and_client.v b/examples/net_udp_server_and_client.v index a69d17889c..03a3e0b189 100644 --- a/examples/net_udp_server_and_client.v +++ b/examples/net_udp_server_and_client.v @@ -9,7 +9,7 @@ fn main() { println('------------------------------------------') is_server := '-l' in os.args port := cmdline.option(os.args, '-p', '40001').int() - mut buf := []byte{len: 100} + mut buf := []u8{len: 100} if is_server { println('UDP echo server, listening for udp packets on port: $port') mut c := net.listen_udp(':$port') ? diff --git a/examples/pendulum-simulation/modules/sim/img/ppm.v b/examples/pendulum-simulation/modules/sim/img/ppm.v index b7d5ba3f92..e6c940085e 100644 --- a/examples/pendulum-simulation/modules/sim/img/ppm.v +++ b/examples/pendulum-simulation/modules/sim/img/ppm.v @@ -35,14 +35,14 @@ pub fn (s ImageSettings) to_grid_settings() sim.GridSettings { pub struct PPMWriter { mut: file os.File - cache []byte + cache []u8 cache_size int } pub fn ppm_writer_for_fname(fname string, settings ImageSettings) ?&PPMWriter { mut writer := &PPMWriter{ cache_size: settings.cache_size - cache: []byte{cap: settings.cache_size} + cache: []u8{cap: settings.cache_size} } writer.start_for_file(fname, settings) ? return writer diff --git a/examples/sokol/06_obj_viewer/modules/obj/util.v b/examples/sokol/06_obj_viewer/modules/obj/util.v index a1e596a97a..3726e65c42 100644 --- a/examples/sokol/06_obj_viewer/modules/obj/util.v +++ b/examples/sokol/06_obj_viewer/modules/obj/util.v @@ -23,10 +23,10 @@ pub fn read_lines_from_file(file_path string) []string { return rows } -// read a file as []byte -pub fn read_bytes_from_file(file_path string) []byte { +// read a file as []u8 +pub fn read_bytes_from_file(file_path string) []u8 { mut path := '' - mut buffer := []byte{} + mut buffer := []u8{} $if android { path = 'models/' + file_path buffer = os.read_apk_asset(path) or { diff --git a/examples/viewer/view.v b/examples/viewer/view.v index 5b322cc894..c7bfce1d69 100644 --- a/examples/viewer/view.v +++ b/examples/viewer/view.v @@ -215,9 +215,9 @@ fn (mut app App) read_bytes(path string) bool { return true } -// read a file as []byte -pub fn read_bytes_from_file(file_path string) []byte { - mut buffer := []byte{} +// read a file as []u8 +pub fn read_bytes_from_file(file_path string) []u8 { + mut buffer := []u8{} buffer = os.read_bytes(file_path) or { eprintln('ERROR: Texure file: [$file_path] NOT FOUND.') exit(0) diff --git a/vlib/bitfield/bitfield.v b/vlib/bitfield/bitfield.v index 07cc913a81..9ae8d1d097 100644 --- a/vlib/bitfield/bitfield.v +++ b/vlib/bitfield/bitfield.v @@ -26,7 +26,7 @@ const ( // from_bytes converts a byte array into a bitfield. // [0x0F, 0x01] => 0000 1111 0000 0001 -pub fn from_bytes(input []byte) BitField { +pub fn from_bytes(input []u8) BitField { mut output := new(input.len * 8) for i, b in input { mut ob := u8(0) @@ -61,7 +61,7 @@ pub fn from_bytes(input []byte) BitField { // from_bytes_lowest_bits_first converts a byte array into a bitfield // [0x0F, 0x01] => 1111 0000 1000 0000 -pub fn from_bytes_lowest_bits_first(input []byte) BitField { +pub fn from_bytes_lowest_bits_first(input []u8) BitField { mut output := new(input.len * 8) for i, b in input { output.field[i / 4] |= u32(b) << ((i % 4) * 8) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 1a914a8b0c..e78254468c 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -839,7 +839,7 @@ pub fn (a []string) str() string { // hex returns a string with the hexadecimal representation // of the byte elements of the array. -pub fn (b []byte) hex() string { +pub fn (b []u8) hex() string { mut hex := unsafe { malloc_noscan(b.len * 2 + 1) } mut dst_i := 0 for i in b { @@ -865,7 +865,7 @@ pub fn (b []byte) hex() string { // Returns the number of elements copied. // NOTE: This is not an `array` method. It is a function that takes two arrays of bytes. // See also: `arrays.copy`. -pub fn copy(mut dst []byte, src []byte) int { +pub fn copy(mut dst []u8, src []u8) int { min := if dst.len < src.len { dst.len } else { src.len } if min > 0 { unsafe { vmemmove(&u8(dst.data), src.data, min) } @@ -913,10 +913,10 @@ pub fn (a array) pointers() []voidptr { return res } -// vbytes on`voidptr` makes a V []byte structure from a C style memory buffer. +// vbytes on`voidptr` makes a V []u8 structure from a C style memory buffer. // NOTE: the data is reused, NOT copied! [unsafe] -pub fn (data voidptr) vbytes(len int) []byte { +pub fn (data voidptr) vbytes(len int) []u8 { res := array{ element_size: 1 data: data @@ -926,9 +926,9 @@ pub fn (data voidptr) vbytes(len int) []byte { return res } -// vbytes on `&byte` makes a V []byte structure from a C style memory buffer. +// vbytes on `&byte` makes a V []u8 structure from a C style memory buffer. // NOTE: the data is reused, NOT copied! [unsafe] -pub fn (data &byte) vbytes(len int) []byte { +pub fn (data &byte) vbytes(len int) []u8 { return unsafe { voidptr(data).vbytes(len) } } diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index aaffbc916a..ac0987f9cc 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -525,9 +525,9 @@ pub fn (c u8) is_capital() bool { } // clone clones the byte array, and returns the newly created copy. -pub fn (b []u8) clone() []byte { - mut res := []byte{len: b.len} - // mut res := make([]byte, {repeat:b.len}) +pub fn (b []u8) clone() []u8 { + mut res := []u8{len: b.len} + // mut res := make([]u8, {repeat:b.len}) for i in 0 .. b.len { res[i] = b[i] } diff --git a/vlib/builtin/js/array.js.v b/vlib/builtin/js/array.js.v index 021ac160df..803c9e47b3 100644 --- a/vlib/builtin/js/array.js.v +++ b/vlib/builtin/js/array.js.v @@ -373,7 +373,7 @@ pub fn (mut a array) delete_last() { pub fn (a &array) free() { } -// todo: once (a []byte) will work rewrite this +// todo: once (a []u8) will work rewrite this pub fn (a array) bytestr() string { res := '' #for (let i = 0;i < a.arr.len.valueOf();i++) res.str += String.fromCharCode(a.arr.get(new int(i))) @@ -487,7 +487,7 @@ pub interface JS.Float64Array { every(JS.EveryFn) JS.Boolean } -pub fn uint8_array(arr []byte) JS.Uint8Array { +pub fn uint8_array(arr []u8) JS.Uint8Array { #let tmp = new Array(); for elem in arr { diff --git a/vlib/builtin/js/int.js.v b/vlib/builtin/js/int.js.v index eae88fcd13..0874643b7d 100644 --- a/vlib/builtin/js/int.js.v +++ b/vlib/builtin/js/int.js.v @@ -142,7 +142,7 @@ pub fn (x byte) hex() string { // hex returns a string with the hexadecimal representation // of the byte elements of the array. -pub fn (b []byte) hex() string { +pub fn (b []u8) hex() string { mut hex := '' for i in b { mut z := i diff --git a/vlib/builtin/js/string.js.v b/vlib/builtin/js/string.js.v index bc457be743..ce533b8b50 100644 --- a/vlib/builtin/js/string.js.v +++ b/vlib/builtin/js/string.js.v @@ -85,13 +85,13 @@ pub fn (s string) split(dot string) []string { return arr } -pub fn (s string) bytes() []byte { +pub fn (s string) bytes() []u8 { sep := '' tmparr := s.str.split(sep.str).map(fn (it JS.Any) JS.Any { return JS.Any(u8(JS.String(it).charCodeAt(JS.Number(0)))) }) _ := tmparr - mut arr := []byte{} + mut arr := []u8{} #arr = new array(new array_buffer({arr: tmparr,index_start: new int(0),len: new int(tmparr.length)})) return arr @@ -500,7 +500,7 @@ pub fn (s string) strip_margin_custom(del byte) string { } // don't know how much space the resulting string will be, but the max it // can be is this big - mut ret := []byte{} + mut ret := []u8{} #ret = new array() mut count := 0 diff --git a/vlib/builtin/linux_bare/old/linuxsys_bare.v b/vlib/builtin/linux_bare/old/linuxsys_bare.v index 9588b16849..496f3f4dd8 100644 --- a/vlib/builtin/linux_bare/old/linuxsys_bare.v +++ b/vlib/builtin/linux_bare/old/linuxsys_bare.v @@ -404,7 +404,7 @@ pub fn sys_dup2(oldfd int, newfd int) (i64, Errno) { } // 59 sys_execve const char *filename const char *const argv[] const char *const envp[] -// pub fn sys_execve(filename byteptr, argv []byteptr, envp []byteptr) int { +// pub fn sys_execve(filename byteptr, argv []u8ptr, envp []u8ptr) int { // return sys_call3(59, filename, argv, envp) //} diff --git a/vlib/builtin/string_charptr_byteptr_helpers.v b/vlib/builtin/string_charptr_byteptr_helpers.v index 8d39129c21..c1bb7b3e21 100644 --- a/vlib/builtin/string_charptr_byteptr_helpers.v +++ b/vlib/builtin/string_charptr_byteptr_helpers.v @@ -2,9 +2,9 @@ module builtin // Note: this file will be removed soon -// byteptr.vbytes() - makes a V []byte structure from a C style memory buffer. Note: the data is reused, NOT copied! +// byteptr.vbytes() - makes a V []u8 structure from a C style memory buffer. Note: the data is reused, NOT copied! [unsafe] -pub fn (data byteptr) vbytes(len int) []byte { +pub fn (data byteptr) vbytes(len int) []u8 { return unsafe { voidptr(data).vbytes(len) } } diff --git a/vlib/compress/zlib/zlib.v b/vlib/compress/zlib/zlib.v index 78081635a6..36b4722eee 100644 --- a/vlib/compress/zlib/zlib.v +++ b/vlib/compress/zlib/zlib.v @@ -11,7 +11,7 @@ fn C.tinfl_decompress_mem_to_heap(source_buf voidptr, source_buf_len usize, out_ // compresses an array of bytes using zlib and returns the compressed bytes in a new array // Example: compressed := zlib.compress(b) ? [manualfree] -pub fn compress(data []byte) ?[]byte { +pub fn compress(data []u8) ?[]u8 { if u64(data.len) > zlib.max_size { return error('data too large ($data.len > $zlib.max_size)') } @@ -38,7 +38,7 @@ pub fn compress(data []byte) ?[]byte { // decompresses an array of bytes using zlib and returns the decompressed bytes in a new array // Example: decompressed := zlib.decompress(b) ? [manualfree] -pub fn decompress(data []byte) ?[]byte { +pub fn decompress(data []u8) ?[]u8 { mut out_len := usize(0) // flags = TINFL_FLAG_PARSE_ZLIB_HEADER (0x1) diff --git a/vlib/crypto/aes/aes.v b/vlib/crypto/aes/aes.v index 5c4bc45b69..a159048f3e 100644 --- a/vlib/crypto/aes/aes.v +++ b/vlib/crypto/aes/aes.v @@ -28,7 +28,7 @@ mut: // The key argument should be the AES key, // either 16, 24, or 32 bytes to select // AES-128, AES-192, or AES-256. -pub fn new_cipher(key []byte) cipher.Block { +pub fn new_cipher(key []u8) cipher.Block { k := key.len match k { 16, 24, 32 { @@ -52,7 +52,7 @@ pub fn (c &AesCipher) block_size() int { // NOTE: `dst` and `src` are both mutable for performance reasons. // NOTE: `dst` and `src` must both be pre-allocated to the correct length. // NOTE: `dst` and `src` may be the same (overlapping entirely). -pub fn (c &AesCipher) encrypt(mut dst []byte, src []byte) { +pub fn (c &AesCipher) encrypt(mut dst []u8, src []u8) { if src.len < aes.block_size { panic('crypto.aes: input not full block') } @@ -71,7 +71,7 @@ pub fn (c &AesCipher) encrypt(mut dst []byte, src []byte) { // NOTE: `dst` and `src` are both mutable for performance reasons. // NOTE: `dst` and `src` must both be pre-allocated to the correct length. // NOTE: `dst` and `src` may be the same (overlapping entirely). -pub fn (c &AesCipher) decrypt(mut dst []byte, src []byte) { +pub fn (c &AesCipher) decrypt(mut dst []u8, src []u8) { if src.len < aes.block_size { panic('crypto.aes: input not full block') } diff --git a/vlib/crypto/aes/block_generic.v b/vlib/crypto/aes/block_generic.v index f0a290cf8b..aa5b21535c 100644 --- a/vlib/crypto/aes/block_generic.v +++ b/vlib/crypto/aes/block_generic.v @@ -38,7 +38,7 @@ module aes import encoding.binary // Encrypt one block from src into dst, using the expanded key xk. -fn encrypt_block_generic(xk []u32, mut dst []byte, src []byte) { +fn encrypt_block_generic(xk []u32, mut dst []u8, src []u8) { _ = src[15] // early bounds check mut s0 := binary.big_endian_u32(src[..4]) mut s1 := binary.big_endian_u32(src[4..8]) @@ -85,7 +85,7 @@ fn encrypt_block_generic(xk []u32, mut dst []byte, src []byte) { } // Decrypt one block from src into dst, using the expanded key xk. -fn decrypt_block_generic(xk []u32, mut dst []byte, src []byte) { +fn decrypt_block_generic(xk []u32, mut dst []u8, src []u8) { _ = src[15] // early bounds check mut s0 := binary.big_endian_u32(src[0..4]) mut s1 := binary.big_endian_u32(src[4..8]) @@ -143,7 +143,7 @@ fn rotw(w u32) u32 { // Key expansion algorithm. See FIPS-197, Figure 11. // Their rcon[i] is our powx[i-1] << 24. -fn expand_key_generic(key []byte, mut enc []u32, mut dec []u32) { +fn expand_key_generic(key []u8, mut enc []u32, mut dec []u32) { // Encryption key setup. mut i := 0 nk := key.len / 4 diff --git a/vlib/crypto/aes/cypher_generic.v b/vlib/crypto/aes/cypher_generic.v index e4ef590c40..84faea9103 100644 --- a/vlib/crypto/aes/cypher_generic.v +++ b/vlib/crypto/aes/cypher_generic.v @@ -7,7 +7,7 @@ import crypto.cipher // new_cipher_generic creates and returns a new cipher.Block // this is the generiv v version, no arch optimisations -fn new_cipher_generic(key []byte) cipher.Block { +fn new_cipher_generic(key []u8) cipher.Block { n := key.len + 28 mut c := AesCipher{ enc: []u32{len: n} diff --git a/vlib/crypto/bcrypt/bcrypt.v b/vlib/crypto/bcrypt/bcrypt.v index 290b7e2e49..82ad2875c9 100644 --- a/vlib/crypto/bcrypt/bcrypt.v +++ b/vlib/crypto/bcrypt/bcrypt.v @@ -20,8 +20,8 @@ pub const ( pub struct Hashed { mut: - hash []byte - salt []byte + hash []u8 + salt []u8 cost int major string minor string @@ -31,14 +31,14 @@ const magic_cipher_data = [u8(0x4f), 0x72, 0x70, 0x68, 0x65, 0x61, 0x6e, 0x42, 0 0x6c, 0x64, 0x65, 0x72, 0x53, 0x63, 0x72, 0x79, 0x44, 0x6f, 0x75, 0x62, 0x74] // generate_from_password return a bcrypt string from Hashed struct. -pub fn generate_from_password(password []byte, cost int) ?string { +pub fn generate_from_password(password []u8, cost int) ?string { mut p := new_from_password(password, cost) or { return error('Error: $err') } x := p.hash_u8() return x.bytestr() } // compare_hash_and_password compares a bcrypt hashed password with its possible hashed version. -pub fn compare_hash_and_password(password []byte, hashed_password []byte) ? { +pub fn compare_hash_and_password(password []u8, hashed_password []u8) ? { mut p := new_from_hash(hashed_password) or { return error('Error: $err') } p.salt << `=` p.salt << `=` @@ -64,7 +64,7 @@ pub fn generate_salt() string { } // new_from_password converting from password to a Hashed struct with bcrypt. -fn new_from_password(password []byte, cost int) ?&Hashed { +fn new_from_password(password []u8, cost int) ?&Hashed { mut cost_ := cost if cost < bcrypt.min_cost { cost_ = bcrypt.default_cost @@ -86,7 +86,7 @@ fn new_from_password(password []byte, cost int) ?&Hashed { } // new_from_hash converting from hashed data to a Hashed struct. -fn new_from_hash(hashed_secret []byte) ?&Hashed { +fn new_from_hash(hashed_secret []u8) ?&Hashed { mut tmp := hashed_secret.clone() if tmp.len < bcrypt.min_hash_size { return error('hash to short') @@ -106,8 +106,8 @@ fn new_from_hash(hashed_secret []byte) ?&Hashed { } // bcrypt hashing passwords. -fn bcrypt(password []byte, cost int, salt []byte) ?[]byte { - mut cipher_data := []byte{len: 72 - bcrypt.magic_cipher_data.len, init: 0} +fn bcrypt(password []u8, cost int, salt []u8) ?[]u8 { + mut cipher_data := []u8{len: 72 - bcrypt.magic_cipher_data.len, init: 0} cipher_data << bcrypt.magic_cipher_data mut bf := expensive_blowfish_setup(password, u32(cost), salt) or { return err } @@ -123,7 +123,7 @@ fn bcrypt(password []byte, cost int, salt []byte) ?[]byte { } // expensive_blowfish_setup generate a Blowfish cipher, given key, cost and salt. -fn expensive_blowfish_setup(key []byte, cost u32, salt []byte) ?&blowfish.Blowfish { +fn expensive_blowfish_setup(key []u8, cost u32, salt []u8) ?&blowfish.Blowfish { csalt := base64.decode(salt.bytestr()) mut bf := blowfish.new_salted_cipher(key, csalt) or { return err } @@ -140,8 +140,8 @@ fn expensive_blowfish_setup(key []byte, cost u32, salt []byte) ?&blowfish.Blowfi } // hash_byte converts the hash value to a byte array. -fn (mut h Hashed) hash_u8() []byte { - mut arr := []byte{len: 65, init: 0} +fn (mut h Hashed) hash_u8() []u8 { + mut arr := []u8{len: 65, init: 0} arr[0] = `$` arr[1] = h.major[0] mut n := 2 @@ -164,7 +164,7 @@ fn (mut h Hashed) hash_u8() []byte { } // decode_version decode bcrypt version. -fn (mut h Hashed) decode_version(sbytes []byte) ?int { +fn (mut h Hashed) decode_version(sbytes []u8) ?int { if sbytes[0] != `$` { return error("bcrypt hashes must start with '$'") } @@ -181,7 +181,7 @@ fn (mut h Hashed) decode_version(sbytes []byte) ?int { } // decode_cost extracts the value of cost and returns the next index in the array. -fn (mut h Hashed) decode_cost(sbytes []byte) ?int { +fn (mut h Hashed) decode_cost(sbytes []u8) ?int { cost := sbytes[0..2].bytestr().int() check_cost(cost) or { return err } h.cost = cost diff --git a/vlib/crypto/blowfish/block.v b/vlib/crypto/blowfish/block.v index 205642208f..c1ecdd8378 100644 --- a/vlib/crypto/blowfish/block.v +++ b/vlib/crypto/blowfish/block.v @@ -1,7 +1,7 @@ module blowfish // expand_key performs a key expansion on the given Blowfish cipher. -pub fn expand_key(key []byte, mut bf Blowfish) { +pub fn expand_key(key []u8, mut bf Blowfish) { mut j := 0 for i := 0; i < 18; i++ { mut d := u32(0) @@ -41,7 +41,7 @@ pub fn expand_key(key []byte, mut bf Blowfish) { } // expand_key_with_salt using salt to expand the key. -pub fn expand_key_with_salt(key []byte, salt []byte, mut bf Blowfish) { +pub fn expand_key_with_salt(key []u8, salt []u8, mut bf Blowfish) { mut j := 0 for i := 0; i < 18; i++ { bf.p[i] ^= get_next_word(key, &j) @@ -128,7 +128,7 @@ fn setup_tables(l u32, r u32, mut bf Blowfish) []u32 { // get_next_word returns the next big-endian u32 value from the byte // slice at the given position in a circular manner, updating the position. -fn get_next_word(b []byte, pos &int) u32 { +fn get_next_word(b []u8, pos &int) u32 { mut w := u32(0) mut j := 0 unsafe { diff --git a/vlib/crypto/blowfish/blowfish.v b/vlib/crypto/blowfish/blowfish.v index 2770737b33..af1ea99849 100644 --- a/vlib/crypto/blowfish/blowfish.v +++ b/vlib/crypto/blowfish/blowfish.v @@ -8,7 +8,7 @@ pub mut: // new_cipher creates and returns a new Blowfish cipher. // The key argument should be the Blowfish key, from 1 to 56 bytes. -pub fn new_cipher(key []byte) ?Blowfish { +pub fn new_cipher(key []u8) ?Blowfish { mut bf := Blowfish{} unsafe { vmemcpy(&bf.p[0], &p[0], int(sizeof(bf.p))) } unsafe { vmemcpy(&bf.s[0], &s[0], int(sizeof(bf.s))) } @@ -21,7 +21,7 @@ pub fn new_cipher(key []byte) ?Blowfish { } // new_salted_cipher returns a new Blowfish cipher that folds a salt into its key schedule. -pub fn new_salted_cipher(key []byte, salt []byte) ?Blowfish { +pub fn new_salted_cipher(key []u8, salt []u8) ?Blowfish { if salt.len == 0 { return new_cipher(key) } @@ -36,7 +36,7 @@ pub fn new_salted_cipher(key []byte, salt []byte) ?Blowfish { } // encrypt encrypts the 8-byte buffer src using the key k and stores the result in dst. -pub fn (mut bf Blowfish) encrypt(mut dst []byte, src []byte) { +pub fn (mut bf Blowfish) encrypt(mut dst []u8, src []u8) { l := u32(src[0]) << 24 | u32(src[1]) << 16 | u32(src[2]) << 8 | u32(src[3]) r := u32(src[4]) << 24 | u32(src[5]) << 16 | u32(src[6]) << 8 | u32(src[7]) arr := setup_tables(l, r, mut bf) diff --git a/vlib/crypto/cipher/aes_cbc_test.v b/vlib/crypto/cipher/aes_cbc_test.v index 7c37ac5603..487f1c271f 100644 --- a/vlib/crypto/cipher/aes_cbc_test.v +++ b/vlib/crypto/cipher/aes_cbc_test.v @@ -19,13 +19,13 @@ fn test_aes_cbc() { println('test_aes_cbc ok') } -fn aes_cbc_en(mut src []byte, key []byte, iv []byte) { +fn aes_cbc_en(mut src []u8, key []u8, iv []u8) { block := aes.new_cipher(key) mut mode := cipher.new_cbc(block, iv) mode.encrypt_blocks(mut src, src.clone()) } -fn aes_cbc_de(mut src []byte, key []byte, iv []byte) { +fn aes_cbc_de(mut src []u8, key []u8, iv []u8) { block := aes.new_cipher(key) mut mode := cipher.new_cbc(block, iv) mode.decrypt_blocks(mut src, src.clone()) diff --git a/vlib/crypto/cipher/aes_cfb_test.v b/vlib/crypto/cipher/aes_cfb_test.v index 1fa7a437b2..ccf626664d 100644 --- a/vlib/crypto/cipher/aes_cfb_test.v +++ b/vlib/crypto/cipher/aes_cfb_test.v @@ -16,13 +16,13 @@ fn test_aes_cfb() { println('test_aes_cfb ok') } -fn aes_cfb_en(mut src []byte, key []byte, iv []byte) { +fn aes_cfb_en(mut src []u8, key []u8, iv []u8) { block := aes.new_cipher(key) mut mode := cipher.new_cfb_encrypter(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn aes_cfb_de(mut src []byte, key []byte, iv []byte) { +fn aes_cfb_de(mut src []u8, key []u8, iv []u8) { block := aes.new_cipher(key) mut mode := cipher.new_cfb_decrypter(block, iv) mode.xor_key_stream(mut src, src.clone()) diff --git a/vlib/crypto/cipher/aes_ctr_test.v b/vlib/crypto/cipher/aes_ctr_test.v index 06ad8313a5..31847c0265 100644 --- a/vlib/crypto/cipher/aes_ctr_test.v +++ b/vlib/crypto/cipher/aes_ctr_test.v @@ -16,13 +16,13 @@ fn test_aes_ctr() { println('test_aes_ctr ok') } -fn aes_ctr_en(mut src []byte, key []byte, iv []byte) { +fn aes_ctr_en(mut src []u8, key []u8, iv []u8) { block := aes.new_cipher(key) mode := cipher.new_ctr(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn aes_ctr_de(mut src []byte, key []byte, iv []byte) { +fn aes_ctr_de(mut src []u8, key []u8, iv []u8) { block := aes.new_cipher(key) mode := cipher.new_ctr(block, iv) mode.xor_key_stream(mut src, src.clone()) diff --git a/vlib/crypto/cipher/aes_ofb_test.v b/vlib/crypto/cipher/aes_ofb_test.v index 40e32a51f6..20e0f8a7a2 100644 --- a/vlib/crypto/cipher/aes_ofb_test.v +++ b/vlib/crypto/cipher/aes_ofb_test.v @@ -18,13 +18,13 @@ fn test_aes_ofb() { println('test_aes_ofb ok') } -fn aes_ofb_en(mut src []byte, key []byte, iv []byte) { +fn aes_ofb_en(mut src []u8, key []u8, iv []u8) { block := aes.new_cipher(key) mut mode := cipher.new_ofb(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn aes_ofb_de(mut src []byte, key []byte, iv []byte) { +fn aes_ofb_de(mut src []u8, key []u8, iv []u8) { block := aes.new_cipher(key) mut mode := cipher.new_ofb(block, iv) mode.xor_key_stream(mut src, src.clone()) diff --git a/vlib/crypto/cipher/cbc.v b/vlib/crypto/cipher/cbc.v index 694a69923f..67730e3d8e 100644 --- a/vlib/crypto/cipher/cbc.v +++ b/vlib/crypto/cipher/cbc.v @@ -15,24 +15,24 @@ struct Cbc { mut: b Block block_size int - iv []byte - tmp []byte + iv []u8 + tmp []u8 } // internal -fn new_des_cbc(b Block, iv []byte) Cbc { +fn new_des_cbc(b Block, iv []u8) Cbc { return Cbc{ b: b block_size: b.block_size iv: iv.clone() - tmp: []byte{len: b.block_size} + tmp: []u8{len: b.block_size} } } // new_cbc returns a `DesCbc` which encrypts in cipher block chaining // mode, using the given Block. The length of iv must be the same as the // Block's block size. -pub fn new_cbc(b Block, iv []byte) Cbc { +pub fn new_cbc(b Block, iv []u8) Cbc { if iv.len != b.block_size { panic('crypto.cipher.new_cbc_encrypter: IV length must equal block size') } @@ -41,7 +41,7 @@ pub fn new_cbc(b Block, iv []byte) Cbc { // encrypt_blocks encrypts the blocks in `src_` to `dst_`. // Please note: `dst_` is mutable for performance reasons. -pub fn (mut x Cbc) encrypt_blocks(mut dst_ []byte, src_ []byte) { +pub fn (mut x Cbc) encrypt_blocks(mut dst_ []u8, src_ []u8) { unsafe { mut dst := *dst_ mut src := src_ @@ -75,7 +75,7 @@ pub fn (mut x Cbc) encrypt_blocks(mut dst_ []byte, src_ []byte) { // decrypt_blocks decrypts the blocks in `src` to `dst`. // Please note: `dst` is mutable for performance reasons. -pub fn (mut x Cbc) decrypt_blocks(mut dst []byte, src []byte) { +pub fn (mut x Cbc) decrypt_blocks(mut dst []u8, src []u8) { if src.len % x.block_size != 0 { panic('crypto.cipher: input not full blocks') } @@ -113,7 +113,7 @@ pub fn (mut x Cbc) decrypt_blocks(mut dst []byte, src []byte) { x.tmp = x.iv } -fn (mut x Cbc) set_iv(iv []byte) { +fn (mut x Cbc) set_iv(iv []u8) { if iv.len != x.iv.len { panic('cipher: incorrect length IV') } diff --git a/vlib/crypto/cipher/cfb.v b/vlib/crypto/cipher/cfb.v index 2c4747cd81..a2853df914 100644 --- a/vlib/crypto/cipher/cfb.v +++ b/vlib/crypto/cipher/cfb.v @@ -13,8 +13,8 @@ import crypto.internal.subtle struct Cfb { mut: b Block - next []byte - out []byte + next []u8 + out []u8 out_used int decrypt bool @@ -23,26 +23,26 @@ mut: // new_cfb_encrypter returns a `Cfb` which encrypts with cipher feedback mode, // using the given Block. The iv must be the same length as the Block's block // size -pub fn new_cfb_encrypter(b Block, iv []byte) Cfb { +pub fn new_cfb_encrypter(b Block, iv []u8) Cfb { return new_cfb(b, iv, false) } // new_cfb_decrypter returns a `Cfb` which decrypts with cipher feedback mode, // using the given Block. The iv must be the same length as the Block's block // size -pub fn new_cfb_decrypter(b Block, iv []byte) Cfb { +pub fn new_cfb_decrypter(b Block, iv []u8) Cfb { return new_cfb(b, iv, true) } -fn new_cfb(b Block, iv []byte, decrypt bool) Cfb { +fn new_cfb(b Block, iv []u8, decrypt bool) Cfb { block_size := b.block_size if iv.len != block_size { panic('cipher.new_cfb: IV length must be equal block size') } mut x := Cfb{ b: b - out: []byte{len: b.block_size} - next: []byte{len: b.block_size} + out: []u8{len: b.block_size} + next: []u8{len: b.block_size} out_used: block_size decrypt: decrypt } @@ -50,7 +50,7 @@ fn new_cfb(b Block, iv []byte, decrypt bool) Cfb { return x } -pub fn (mut x Cfb) xor_key_stream(mut dst_ []byte, src_ []byte) { +pub fn (mut x Cfb) xor_key_stream(mut dst_ []u8, src_ []u8) { unsafe { mut dst := *dst_ mut src := src_ diff --git a/vlib/crypto/cipher/cipher.v b/vlib/crypto/cipher/cipher.v index 97de4448df..78290aabda 100644 --- a/vlib/crypto/cipher/cipher.v +++ b/vlib/crypto/cipher/cipher.v @@ -8,9 +8,9 @@ module cipher // extend that capability to streams of blocks. interface Block { block_size int // block_size returns the cipher's block size. - encrypt(mut dst []byte, src []byte) // Encrypt encrypts the first block in src into dst. + encrypt(mut dst []u8, src []u8) // Encrypt encrypts the first block in src into dst. // Dst and src must overlap entirely or not at all. - decrypt(mut dst []byte, src []byte) // Decrypt decrypts the first block in src into dst. + decrypt(mut dst []u8, src []u8) // Decrypt decrypts the first block in src into dst. // Dst and src must overlap entirely or not at all. } @@ -26,14 +26,14 @@ interface Stream { // Multiple calls to xor_key_stream behave as if the concatenation of // the src buffers was passed in a single run. That is, Stream // maintains state and does not reset at each xor_key_stream call. - xor_key_stream(mut dst []byte, src []byte) + xor_key_stream(mut dst []u8, src []u8) } // A BlockMode represents a block cipher running in a block-based mode (CBC, // ECB etc). interface BlockMode { block_size int // block_size returns the mode's block size. - crypt_blocks(mut dst []byte, src []byte) // crypt_blocks encrypts or decrypts a number of blocks. The length of + crypt_blocks(mut dst []u8, src []u8) // crypt_blocks encrypts or decrypts a number of blocks. The length of // src must be a multiple of the block size. Dst and src must overlap // entirely or not at all. // @@ -48,8 +48,8 @@ interface BlockMode { // Utility routines -// fn dup(p []byte) []byte { -// q := make([]byte, p.len) +// fn dup(p []u8) []u8 { +// q := make([]u8, p.len) // copy(mut q, p) // return q // } diff --git a/vlib/crypto/cipher/ctr.v b/vlib/crypto/cipher/ctr.v index 28fb427215..b23be26257 100644 --- a/vlib/crypto/cipher/ctr.v +++ b/vlib/crypto/cipher/ctr.v @@ -16,27 +16,27 @@ import crypto.internal.subtle struct Ctr { mut: b Block - next []byte - out []byte + next []u8 + out []u8 out_used int } // new_ctr returns a Ctr which encrypts/decrypts using the given Block in // counter mode. The length of iv must be the same as the Block's block size. -pub fn new_ctr(b Block, iv []byte) Ctr { +pub fn new_ctr(b Block, iv []u8) Ctr { block_size := b.block_size if iv.len != block_size { panic('cipher.new_cfb: IV length must be equal block size') } return Ctr{ b: b - out: []byte{len: b.block_size} + out: []u8{len: b.block_size} next: iv.clone() out_used: block_size } } -pub fn (x &Ctr) xor_key_stream(mut dst_ []byte, src_ []byte) { +pub fn (x &Ctr) xor_key_stream(mut dst_ []u8, src_ []u8) { unsafe { mut dst := *dst_ mut src := src_ diff --git a/vlib/crypto/cipher/des_cbc_test.v b/vlib/crypto/cipher/des_cbc_test.v index bdc6d62852..2c437e02e5 100644 --- a/vlib/crypto/cipher/des_cbc_test.v +++ b/vlib/crypto/cipher/des_cbc_test.v @@ -29,25 +29,25 @@ fn test_des_cbc() { println('test_des_cbc ok') } -fn des_cbc_en(mut src []byte, key []byte, iv []byte) { +fn des_cbc_en(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) mut mode := cipher.new_cbc(block, iv) mode.encrypt_blocks(mut src, src.clone()) } -fn des_cbc_de(mut src []byte, key []byte, iv []byte) { +fn des_cbc_de(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) mut mode := cipher.new_cbc(block, iv) mode.decrypt_blocks(mut src, src.clone()) } -fn triple_des_cbc_en(mut src []byte, key []byte, iv []byte) { +fn triple_des_cbc_en(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) mut mode := cipher.new_cbc(block, iv) mode.encrypt_blocks(mut src, src.clone()) } -fn triple_des_cbc_de(mut src []byte, key []byte, iv []byte) { +fn triple_des_cbc_de(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) mut mode := cipher.new_cbc(block, iv) mode.decrypt_blocks(mut src, src.clone()) diff --git a/vlib/crypto/cipher/des_cfb_test.v b/vlib/crypto/cipher/des_cfb_test.v index b5143e86e0..70117204bc 100644 --- a/vlib/crypto/cipher/des_cfb_test.v +++ b/vlib/crypto/cipher/des_cfb_test.v @@ -29,25 +29,25 @@ fn test_des_cfb() { println('test_des_cfb ok') } -fn des_cfb_en(mut src []byte, key []byte, iv []byte) { +fn des_cfb_en(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) mut mode := cipher.new_cfb_encrypter(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn des_cfb_de(mut src []byte, key []byte, iv []byte) { +fn des_cfb_de(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) mut mode := cipher.new_cfb_decrypter(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn triple_des_cfb_en(mut src []byte, key []byte, iv []byte) { +fn triple_des_cfb_en(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) mut mode := cipher.new_cfb_encrypter(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn triple_des_cfb_de(mut src []byte, key []byte, iv []byte) { +fn triple_des_cfb_de(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) mut mode := cipher.new_cfb_decrypter(block, iv) mode.xor_key_stream(mut src, src.clone()) diff --git a/vlib/crypto/cipher/des_ctr_test.v b/vlib/crypto/cipher/des_ctr_test.v index 9a204877ed..0c173dfc81 100644 --- a/vlib/crypto/cipher/des_ctr_test.v +++ b/vlib/crypto/cipher/des_ctr_test.v @@ -29,25 +29,25 @@ fn test_des_ctr() { println('test_des_ctr ok') } -fn des_ctr_en(mut src []byte, key []byte, iv []byte) { +fn des_ctr_en(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) mode := cipher.new_ctr(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn des_ctr_de(mut src []byte, key []byte, iv []byte) { +fn des_ctr_de(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) mode := cipher.new_ctr(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn triple_des_ctr_en(mut src []byte, key []byte, iv []byte) { +fn triple_des_ctr_en(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) mode := cipher.new_ctr(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn triple_des_ctr_de(mut src []byte, key []byte, iv []byte) { +fn triple_des_ctr_de(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) mode := cipher.new_ctr(block, iv) mode.xor_key_stream(mut src, src.clone()) diff --git a/vlib/crypto/cipher/des_ofb_test.v b/vlib/crypto/cipher/des_ofb_test.v index 966cfb4c11..86e791b8d1 100644 --- a/vlib/crypto/cipher/des_ofb_test.v +++ b/vlib/crypto/cipher/des_ofb_test.v @@ -29,25 +29,25 @@ fn test_des_ofb() { println('test_des_ofb ok') } -fn des_ofb_en(mut src []byte, key []byte, iv []byte) { +fn des_ofb_en(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) mut mode := cipher.new_ofb(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn des_ofb_de(mut src []byte, key []byte, iv []byte) { +fn des_ofb_de(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) mut mode := cipher.new_ofb(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn triple_des_ofb_en(mut src []byte, key []byte, iv []byte) { +fn triple_des_ofb_en(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) mut mode := cipher.new_ofb(block, iv) mode.xor_key_stream(mut src, src.clone()) } -fn triple_des_ofb_de(mut src []byte, key []byte, iv []byte) { +fn triple_des_ofb_de(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) mut mode := cipher.new_ofb(block, iv) mode.xor_key_stream(mut src, src.clone()) diff --git a/vlib/crypto/cipher/ofb.v b/vlib/crypto/cipher/ofb.v index eaaa1259e5..dbfc3bcad8 100644 --- a/vlib/crypto/cipher/ofb.v +++ b/vlib/crypto/cipher/ofb.v @@ -12,30 +12,30 @@ import crypto.internal.subtle struct Ofb { mut: b Block - next []byte - out []byte + next []u8 + out []u8 out_used int } // new_ofb returns a Ofb that encrypts or decrypts using the block cipher b // in output feedback mode. The initialization vector iv's length must be equal // to b's block size. -pub fn new_ofb(b Block, iv []byte) Ofb { +pub fn new_ofb(b Block, iv []u8) Ofb { block_size := b.block_size if iv.len != block_size { panic('cipher.new_ofb: IV length must be equal block size') } mut x := Ofb{ b: b - out: []byte{len: b.block_size} - next: []byte{len: b.block_size} + out: []u8{len: b.block_size} + next: []u8{len: b.block_size} out_used: block_size } copy(mut x.next, iv) return x } -pub fn (mut x Ofb) xor_key_stream(mut dst_ []byte, src_ []byte) { +pub fn (mut x Ofb) xor_key_stream(mut dst_ []u8, src_ []u8) { unsafe { mut dst := *dst_ mut src := src_ diff --git a/vlib/crypto/cipher/xor_generic.v b/vlib/crypto/cipher/xor_generic.v index a7b04c1600..60fee2fde4 100644 --- a/vlib/crypto/cipher/xor_generic.v +++ b/vlib/crypto/cipher/xor_generic.v @@ -6,7 +6,7 @@ module cipher // NOTE: Implement other versions (joe-c) // xor_bytes xors the bytes in a and b. The destination should have enough // space, otherwise xor_bytes will panic. Returns the number of bytes xor'd. -pub fn xor_bytes(mut dst []byte, a []byte, b []byte) int { +pub fn xor_bytes(mut dst []u8, a []u8, b []u8) int { mut n := a.len if b.len < n { n = b.len @@ -20,7 +20,7 @@ pub fn xor_bytes(mut dst []byte, a []byte, b []byte) int { // safe_xor_bytes XORs the bytes in `a` and `b` into `dst` it does so `n` times. // Please note: `n` needs to be smaller or equal than the length of `a` and `b`. -pub fn safe_xor_bytes(mut dst []byte, a []byte, b []byte, n int) { +pub fn safe_xor_bytes(mut dst []u8, a []u8, b []u8, n int) { for i in 0 .. n { dst[i] = a[i] ^ b[i] } @@ -28,6 +28,6 @@ pub fn safe_xor_bytes(mut dst []byte, a []byte, b []byte, n int) { // xor_words XORs multiples of 4 or 8 bytes (depending on architecture.) // The slice arguments `a` and `b` are assumed to be of equal length. -pub fn xor_words(mut dst []byte, a []byte, b []byte) { +pub fn xor_words(mut dst []u8, a []u8, b []u8) { safe_xor_bytes(mut dst, a, b, b.len) } diff --git a/vlib/crypto/des/block.v b/vlib/crypto/des/block.v index 619068b669..c5faf0378f 100644 --- a/vlib/crypto/des/block.v +++ b/vlib/crypto/des/block.v @@ -23,7 +23,7 @@ fn feistel(ll u32, rr u32, k0 u64, k1 u64) (u32, u32) { return l, r } -fn crypt_block(subkeys []u64, mut dst []byte, src []byte, decrypt bool) { +fn crypt_block(subkeys []u64, mut dst []u8, src []u8, decrypt bool) { mut b := binary.big_endian_u64(src) b = permute_initial_block(b) @@ -51,17 +51,17 @@ fn crypt_block(subkeys []u64, mut dst []byte, src []byte, decrypt bool) { } // Encrypt one block from src into dst, using the subkeys. -pub fn encrypt_block(subkeys []u64, mut dst []byte, src []byte) { +pub fn encrypt_block(subkeys []u64, mut dst []u8, src []u8) { crypt_block(subkeys, mut dst, src, false) } // Decrypt one block from src into dst, using the subkeys. -fn decrypt_block(subkeys []u64, mut dst []byte, src []byte) { +fn decrypt_block(subkeys []u64, mut dst []u8, src []u8) { crypt_block(subkeys, mut dst, src, true) } // general purpose function to perform DES block permutations -fn permute_block(src u64, permutation []byte) u64 { +fn permute_block(src u64, permutation []u8) u64 { mut block := u64(0) for position, n in permutation { bit := (src >> u64(u8(n))) & 1 diff --git a/vlib/crypto/des/des.v b/vlib/crypto/des/des.v index 0aeca8bfd0..2df40afdc1 100644 --- a/vlib/crypto/des/des.v +++ b/vlib/crypto/des/des.v @@ -25,7 +25,7 @@ mut: } // NewCipher creates and returns a new cipher.Block. -pub fn new_cipher(key []byte) cipher.Block { +pub fn new_cipher(key []u8) cipher.Block { if key.len != 8 { panic('crypto.aes: invalid key size') } @@ -36,7 +36,7 @@ pub fn new_cipher(key []byte) cipher.Block { } // creates 16 56-bit subkeys from the original key -fn (mut c DesCipher) generate_subkeys(key_bytes []byte) { +fn (mut c DesCipher) generate_subkeys(key_bytes []u8) { // feistel_box_once.do(initFeistel_box) // apply PC1 permutation to key @@ -56,7 +56,7 @@ fn (mut c DesCipher) generate_subkeys(key_bytes []byte) { } } -pub fn (c &DesCipher) encrypt(mut dst []byte, src []byte) { +pub fn (c &DesCipher) encrypt(mut dst []u8, src []u8) { if src.len < des.block_size { panic('crypto/des: input not full block') } @@ -69,7 +69,7 @@ pub fn (c &DesCipher) encrypt(mut dst []byte, src []byte) { encrypt_block(c.subkeys[..], mut dst, src) } -pub fn (c &DesCipher) decrypt(mut dst []byte, src []byte) { +pub fn (c &DesCipher) decrypt(mut dst []u8, src []u8) { if src.len < des.block_size { panic('crypto/des: input not full block') } @@ -83,7 +83,7 @@ pub fn (c &DesCipher) decrypt(mut dst []byte, src []byte) { } // NewTripleDesCipher creates and returns a new cipher.Block. -pub fn new_triple_des_cipher(key []byte) cipher.Block { +pub fn new_triple_des_cipher(key []u8) cipher.Block { if key.len != 24 { panic('crypto.des: invalid key size') } @@ -94,7 +94,7 @@ pub fn new_triple_des_cipher(key []byte) cipher.Block { return c } -pub fn (c &TripleDesCipher) encrypt(mut dst []byte, src []byte) { +pub fn (c &TripleDesCipher) encrypt(mut dst []u8, src []u8) { if src.len < des.block_size { panic('crypto/des: input not full block') } @@ -130,7 +130,7 @@ pub fn (c &TripleDesCipher) encrypt(mut dst []byte, src []byte) { binary.big_endian_put_u64(mut dst, permute_final_block(pre_output)) } -pub fn (c &TripleDesCipher) decrypt(mut dst []byte, src []byte) { +pub fn (c &TripleDesCipher) decrypt(mut dst []u8, src []u8) { if src.len < des.block_size { panic('crypto/des: input not full block') } diff --git a/vlib/crypto/des/des_test.v b/vlib/crypto/des/des_test.v index 13f3182bf9..be24c53a62 100644 --- a/vlib/crypto/des/des_test.v +++ b/vlib/crypto/des/des_test.v @@ -29,22 +29,22 @@ fn test_des() { println('test_des ok') } -fn des_en(mut src []byte, key []byte, iv []byte) { +fn des_en(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) block.encrypt(mut src, src.clone()) } -fn des_de(mut src []byte, key []byte, iv []byte) { +fn des_de(mut src []u8, key []u8, iv []u8) { block := des.new_cipher(key) block.decrypt(mut src, src.clone()) } -fn triple_des_en(mut src []byte, key []byte, iv []byte) { +fn triple_des_en(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) block.encrypt(mut src, src.clone()) } -fn triple_des_de(mut src []byte, key []byte, iv []byte) { +fn triple_des_de(mut src []u8, key []u8, iv []u8) { block := des.new_triple_des_cipher(key) inbuf := src.clone() block.decrypt(mut src, inbuf) diff --git a/vlib/crypto/ed25519/ed25519.v b/vlib/crypto/ed25519/ed25519.v index b9643c46c8..c4aafb39d9 100644 --- a/vlib/crypto/ed25519/ed25519.v +++ b/vlib/crypto/ed25519/ed25519.v @@ -18,39 +18,39 @@ pub const signature_size = 64 pub const seed_size = 32 // `PublicKey` is Ed25519 public keys. -pub type PublicKey = []byte +pub type PublicKey = []u8 // equal reports whether p and x have the same value. -pub fn (p PublicKey) equal(x []byte) bool { +pub fn (p PublicKey) equal(x []u8) bool { return subtle.constant_time_compare(p, PublicKey(x)) == 1 } // PrivateKey is Ed25519 private keys -pub type PrivateKey = []byte +pub type PrivateKey = []u8 // seed returns the private key seed corresponding to priv. // RFC 8032's private keys correspond to seeds in this module. -pub fn (priv PrivateKey) seed() []byte { - mut seed := []byte{len: ed25519.seed_size} +pub fn (priv PrivateKey) seed() []u8 { + mut seed := []u8{len: ed25519.seed_size} copy(mut seed, priv[..32]) return seed } -// public_key returns the []byte corresponding to priv. +// public_key returns the []u8 corresponding to priv. pub fn (priv PrivateKey) public_key() PublicKey { assert priv.len == ed25519.private_key_size - mut publickey := []byte{len: ed25519.public_key_size} + mut publickey := []u8{len: ed25519.public_key_size} copy(mut publickey, priv[32..]) return PublicKey(publickey) } // currentyly x not `crypto.PrivateKey` -pub fn (priv PrivateKey) equal(x []byte) bool { +pub fn (priv PrivateKey) equal(x []u8) bool { return subtle.constant_time_compare(priv, PrivateKey(x)) == 1 } // sign signs the given message with priv. -pub fn (priv PrivateKey) sign(message []byte) ?[]byte { +pub fn (priv PrivateKey) sign(message []u8) ?[]u8 { /* if opts.HashFunc() != crypto.Hash(0) { return nil, errors.New("ed25519: cannot sign hashed message") @@ -60,13 +60,13 @@ pub fn (priv PrivateKey) sign(message []byte) ?[]byte { } // sign`signs the message with privatekey and returns a signature -pub fn sign(privatekey PrivateKey, message []byte) ?[]byte { - mut signature := []byte{len: ed25519.signature_size} +pub fn sign(privatekey PrivateKey, message []u8) ?[]u8 { + mut signature := []u8{len: ed25519.signature_size} sign_generic(mut signature, privatekey, message) ? return signature } -fn sign_generic(mut signature []byte, privatekey []byte, message []byte) ? { +fn sign_generic(mut signature []u8, privatekey []u8, message []u8) ? { if privatekey.len != ed25519.private_key_size { panic('ed25519: bad private key length: $privatekey.len') } @@ -81,7 +81,7 @@ fn sign_generic(mut signature []byte, privatekey []byte, message []byte) ? { mh.write(prefix) ? mh.write(message) ? - mut msg_digest := []byte{cap: sha512.size} + mut msg_digest := []u8{cap: sha512.size} msg_digest = mh.sum(msg_digest) mut r := edwards25519.new_scalar() @@ -95,7 +95,7 @@ fn sign_generic(mut signature []byte, privatekey []byte, message []byte) ? { kh.write(publickey) ? kh.write(message) ? - mut hram_digest := []byte{cap: sha512.size} + mut hram_digest := []u8{cap: sha512.size} hram_digest = kh.sum(hram_digest) mut k := edwards25519.new_scalar() k.set_uniform_bytes(hram_digest) ? @@ -108,7 +108,7 @@ fn sign_generic(mut signature []byte, privatekey []byte, message []byte) ? { } // verify reports whether sig is a valid signature of message by publickey. -pub fn verify(publickey PublicKey, message []byte, sig []byte) ?bool { +pub fn verify(publickey PublicKey, message []u8, sig []u8) ?bool { if publickey.len != ed25519.public_key_size { return error('ed25519: bad public key length: $publickey.len') } @@ -125,7 +125,7 @@ pub fn verify(publickey PublicKey, message []byte, sig []byte) ?bool { kh.write(publickey) ? kh.write(message) ? - mut hram_digest := []byte{cap: sha512.size} + mut hram_digest := []u8{cap: sha512.size} hram_digest = kh.sum(hram_digest) mut k := edwards25519.new_scalar() @@ -148,7 +148,7 @@ pub fn generate_key() ?(PublicKey, PrivateKey) { mut seed := rand.bytes(ed25519.seed_size) ? privatekey := new_key_from_seed(seed) - mut publickey := []byte{len: ed25519.public_key_size} + mut publickey := []u8{len: ed25519.public_key_size} copy(mut publickey, privatekey[32..]) return publickey, privatekey @@ -156,14 +156,14 @@ pub fn generate_key() ?(PublicKey, PrivateKey) { // new_key_from_seed calculates a private key from a seed. private keys of RFC 8032 // correspond to seeds in this module -pub fn new_key_from_seed(seed []byte) PrivateKey { +pub fn new_key_from_seed(seed []u8) PrivateKey { // Outline the function body so that the returned key can be stack-allocated. - mut privatekey := []byte{len: ed25519.private_key_size} + mut privatekey := []u8{len: ed25519.private_key_size} new_key_from_seed_generic(mut privatekey, seed) return PrivateKey(privatekey) } -fn new_key_from_seed_generic(mut privatekey []byte, seed []byte) { +fn new_key_from_seed_generic(mut privatekey []u8, seed []u8) { if seed.len != ed25519.seed_size { panic('ed25519: bad seed length: $seed.len') } diff --git a/vlib/crypto/ed25519/internal/ed25519_test.v b/vlib/crypto/ed25519/internal/ed25519_test.v index 0e0795d2b4..0985641ec5 100644 --- a/vlib/crypto/ed25519/internal/ed25519_test.v +++ b/vlib/crypto/ed25519/internal/ed25519_test.v @@ -19,7 +19,7 @@ const contents = os.read_lines(os.join_path(testdata, 'sign.input')) or { panic( /* struct ZeroReader {} -fn (z ZeroReader) read(mut buf []byte) ?int { +fn (z ZeroReader) read(mut buf []u8) ?int { for i, _ in buf { buf[i] = 0 } @@ -96,7 +96,7 @@ fn works_check_on_sign_input_string(item string) bool { // assert pubkey.len == public_key_size sig = sig[..ed25519.signature_size] - mut priv := []byte{len: ed25519.private_key_size} + mut priv := []u8{len: ed25519.private_key_size} copy(mut priv[..], privbytes) copy(mut priv[32..], pubkey) @@ -181,7 +181,7 @@ fn test_input_from_djb_ed25519_crypto_sign_input_without_syncpool() ? { assert pubkey.len == public_key_size sig = sig[..signature_size] - mut priv := []byte{len: ed25519.private_key_size} + mut priv := []u8{len: ed25519.private_key_size} copy(mut priv[..], privbytes) copy(mut priv[32..], pubkey) diff --git a/vlib/crypto/ed25519/internal/edwards25519/element.v b/vlib/crypto/ed25519/internal/edwards25519/element.v index 0bff87d3cc..85e0e63cbd 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/element.v +++ b/vlib/crypto/ed25519/internal/edwards25519/element.v @@ -624,7 +624,7 @@ pub fn (mut v Element) set(a Element) Element { // Consistent with RFC 7748, the most significant bit (the high bit of the // last byte) is ignored, and non-canonical values (2^255-19 through 2^255-1) // are accepted. Note that this is laxer than specified by RFC 8032. -pub fn (mut v Element) set_bytes(x []byte) ?Element { +pub fn (mut v Element) set_bytes(x []u8) ?Element { if x.len != 32 { return error('edwards25519: invalid edwards25519 element input size') } @@ -650,19 +650,19 @@ pub fn (mut v Element) set_bytes(x []byte) ?Element { } // bytes returns the canonical 32-byte little-endian encoding of v. -pub fn (mut v Element) bytes() []byte { +pub fn (mut v Element) bytes() []u8 { // This function is outlined to make the allocations inline in the caller // rather than happen on the heap. // out := v.bytes_generic() return v.bytes_generic() } -fn (mut v Element) bytes_generic() []byte { - mut out := []byte{len: 32} +fn (mut v Element) bytes_generic() []u8 { + mut out := []u8{len: 32} v = v.reduce() - mut buf := []byte{len: 8} + mut buf := []u8{len: 8} idxs := [v.l0, v.l1, v.l2, v.l3, v.l4] for i, l in idxs { bits_offset := i * 51 @@ -725,7 +725,7 @@ pub fn (mut v Element) mult_32(x Element, y u32) Element { return v } -fn swap_endianness(mut buf []byte) []byte { +fn swap_endianness(mut buf []u8) []u8 { for i := 0; i < buf.len / 2; i++ { buf[i], buf[buf.len - i - 1] = buf[buf.len - i - 1], buf[i] } diff --git a/vlib/crypto/ed25519/internal/edwards25519/element_test.v b/vlib/crypto/ed25519/internal/edwards25519/element_test.v index 845f886d39..8625ff3bb4 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/element_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/element_test.v @@ -230,7 +230,7 @@ fn test_set_bytes_reduced() { struct FeRTTest { mut: fe Element - b []byte + b []u8 } fn test_set_bytes_from_dalek_test_vectors() ? { @@ -395,7 +395,7 @@ fn test_bytes_big_equivalence() ? { assert fe == fe1 - mut buf := []byte{len: 32} // pad with zeroes + mut buf := []u8{len: 32} // pad with zeroes fedtobig := fe1.to_big_integer() mut fedbig_bytes, _ := fedtobig.bytes() copy(mut buf, fedbig_bytes) // does not need to do swap_endianness diff --git a/vlib/crypto/ed25519/internal/edwards25519/extra.v b/vlib/crypto/ed25519/internal/edwards25519/extra.v index 199d208b1f..56c53bf6dd 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/extra.v +++ b/vlib/crypto/ed25519/internal/edwards25519/extra.v @@ -86,14 +86,14 @@ fn is_on_curve(x Element, y Element, z Element, t Element) bool { // Note that bytes_montgomery only encodes the u-coordinate, so v and -v encode // to the same value. If v is the identity point, bytes_montgomery returns 32 // zero bytes, analogously to the X25519 function. -pub fn (mut v Point) bytes_montgomery() []byte { +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{} return v.bytes_montgomery_generic(mut buf) } -fn (mut v Point) bytes_montgomery_generic(mut buf [32]byte) []byte { +fn (mut v Point) bytes_montgomery_generic(mut buf [32]byte) []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 61ae54ab54..bad706515e 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/extra_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/extra_test.v @@ -70,7 +70,7 @@ const ( loworder_bytes = hex.decode(loworder_string) or { panic(err) } ) -fn fn_cofactor(mut data []byte) bool { +fn fn_cofactor(mut data []u8) bool { if data.len != 64 { panic('data.len should be 64') } diff --git a/vlib/crypto/ed25519/internal/edwards25519/point.v b/vlib/crypto/ed25519/internal/edwards25519/point.v index f0bc7d35eb..5e3f645691 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/point.v +++ b/vlib/crypto/ed25519/internal/edwards25519/point.v @@ -117,7 +117,7 @@ fn (mut v ProjectiveP2) zero() ProjectiveP2 { // Note that set_bytes accepts all non-canonical encodings of valid points. // That is, it follows decoding rules that match most implementations in // the ecosystem rather than RFC 8032. -pub fn (mut v Point) set_bytes(x []byte) ?Point { +pub fn (mut v Point) set_bytes(x []u8) ?Point { // Specifically, the non-canonical encodings that are accepted are // 1) the ones where the edwards25519 element is not reduced (see the // (*edwards25519.Element).set_bytes docs) and @@ -201,14 +201,14 @@ fn (mut v AffineCached) zero() AffineCached { // bytes returns the canonical 32-byte encoding of v, according to RFC 8032, // Section 5.1.2. -pub fn (mut v Point) bytes() []byte { +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{} return v.bytes_generic(mut buf) } -fn (mut v Point) bytes_generic(mut buf [32]byte) []byte { +fn (mut v Point) bytes_generic(mut buf [32]byte) []u8 { check_initialized(v) mut zinv := Element{} @@ -226,7 +226,7 @@ fn (mut v Point) bytes_generic(mut buf [32]byte) []byte { return out } -fn copy_field_element(mut buf [32]byte, mut v Element) []byte { +fn copy_field_element(mut buf [32]byte, mut v Element) []u8 { // this fail in test /* copy(mut buf[..], v.bytes()) @@ -234,7 +234,7 @@ fn copy_field_element(mut buf [32]byte, mut v Element) []byte { */ // this pass the test - mut out := []byte{len: 32} + mut out := []u8{len: 32} for i := 0; i <= buf.len - 1; i++ { out[i] = v.bytes()[i] } diff --git a/vlib/crypto/ed25519/internal/edwards25519/scalar.v b/vlib/crypto/ed25519/internal/edwards25519/scalar.v index 13d17994ea..6cd411081b 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/scalar.v +++ b/vlib/crypto/ed25519/internal/edwards25519/scalar.v @@ -86,11 +86,11 @@ pub fn (mut s Scalar) set(x Scalar) Scalar { // set_uniform_bytes sets s to an uniformly distributed value given 64 uniformly // distributed random bytes. If x is not of the right length, set_uniform_bytes // returns an error, and the receiver is unchanged. -pub fn (mut s Scalar) set_uniform_bytes(x []byte) ?Scalar { +pub fn (mut s Scalar) set_uniform_bytes(x []u8) ?Scalar { if x.len != 64 { return error('edwards25519: invalid set_uniform_bytes input length') } - mut wide_bytes := []byte{len: 64} + mut wide_bytes := []u8{len: 64} copy(mut wide_bytes, x) // for i, item in x { // wide_bytes[i] = item @@ -102,11 +102,11 @@ pub fn (mut s Scalar) set_uniform_bytes(x []byte) ?Scalar { // set_canonical_bytes sets s = x, where x is a 32-byte little-endian encoding of // s, and returns s. If x is not a canonical encoding of s, set_canonical_bytes // returns an error, and the receiver is unchanged. -pub fn (mut s Scalar) set_canonical_bytes(x []byte) ?Scalar { +pub fn (mut s Scalar) set_canonical_bytes(x []u8) ?Scalar { if x.len != 32 { return error('invalid scalar length') } - // mut bb := []byte{len:32} + // mut bb := []u8{len:32} mut ss := Scalar{} for i, item in x { ss.s[i] = item @@ -152,7 +152,7 @@ fn is_reduced(s Scalar) bool { // expected as long as it is applied to points on the prime order subgroup, like // in Ed25519. In fact, it is lost to history why RFC 8032 adopted the // irrelevant RFC 7748 clamping, but it is now required for compatibility. -pub fn (mut s Scalar) set_bytes_with_clamping(x []byte) ?Scalar { +pub fn (mut s Scalar) set_bytes_with_clamping(x []u8) ?Scalar { // The description above omits the purpose of the high bits of the clamping // for brevity, but those are also lost to reductions, and are also // irrelevant to edwards25519 as they protect against a specific @@ -161,7 +161,7 @@ pub fn (mut s Scalar) set_bytes_with_clamping(x []byte) ?Scalar { return error('edwards25519: invalid set_bytes_with_clamping input length') } - mut wide_bytes := []byte{len: 64, cap: 64} + mut wide_bytes := []u8{len: 64, cap: 64} copy(mut wide_bytes, x) // for i, item in x { // wide_bytes[i] = item @@ -174,8 +174,8 @@ pub fn (mut s Scalar) set_bytes_with_clamping(x []byte) ?Scalar { } // bytes returns the canonical 32-byte little-endian encoding of s. -pub fn (mut s Scalar) bytes() []byte { - mut buf := []byte{len: 32} +pub fn (mut s Scalar) bytes() []u8 { + mut buf := []u8{len: 32} copy(mut buf, s.s[..]) return buf } @@ -187,14 +187,14 @@ pub fn (s Scalar) equal(t Scalar) int { // sc_mul_add and sc_reduce are ported from the public domain, “ref10” // implementation of ed25519 from SUPERCOP. -fn load3(inp []byte) i64 { +fn load3(inp []u8) i64 { mut r := i64(inp[0]) r |= i64(inp[1]) * 256 // << 8 r |= i64(inp[2]) * 65536 // << 16 return r } -fn load4(inp []byte) i64 { +fn load4(inp []u8) i64 { mut r := i64(inp[0]) r |= i64(inp[1]) * 256 r |= i64(inp[2]) * 65536 @@ -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 []byte) { +fn sc_reduce(mut out [32]byte, 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 acddc2f541..09c80e6c82 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v @@ -134,7 +134,7 @@ fn test_scalar_set_uniform_bytes() ? { assert m.abs_cmp(scbig) == 0 // NEED FIX } -fn bigint_from_le_bytes(b []byte) big.Integer { +fn bigint_from_le_bytes(b []u8) big.Integer { mut bc := b.clone() buf := swap_endianness(mut bc) // WITHOUT THIS, some test would fail bg := big.integer_from_bytes(buf) diff --git a/vlib/crypto/hmac/hmac.v b/vlib/crypto/hmac/hmac.v index faca186b61..3a07dd9bac 100644 --- a/vlib/crypto/hmac/hmac.v +++ b/vlib/crypto/hmac/hmac.v @@ -5,14 +5,14 @@ module hmac import crypto.internal.subtle const ( - ipad = []byte{len: 256, init: 0x36} // TODO is 256 enough?? - opad = []byte{len: 256, init: 0x5C} - npad = []byte{len: 256, init: 0} + ipad = []u8{len: 256, init: 0x36} // TODO is 256 enough?? + opad = []u8{len: 256, init: 0x5C} + npad = []u8{len: 256, init: 0} ) // new returns a HMAC byte array, depending on the hash algorithm used. -pub fn new(key []byte, data []byte, hash_func fn ([]byte) []byte, blocksize int) []byte { - mut b_key := []byte{} +pub fn new(key []u8, data []u8, hash_func fn ([]u8) []u8, blocksize int) []u8 { + mut b_key := []u8{} if key.len <= blocksize { b_key = key.clone() // TODO: remove .clone() once https://github.com/vlang/v/issues/6604 gets fixed } else { @@ -21,13 +21,13 @@ pub fn new(key []byte, data []byte, hash_func fn ([]byte) []byte, blocksize int) if b_key.len < blocksize { b_key << hmac.npad[..blocksize - b_key.len] } - mut inner := []byte{} + mut inner := []u8{} for i, b in hmac.ipad[..blocksize] { inner << b_key[i] ^ b } inner << data inner_hash := hash_func(inner) - mut outer := []byte{cap: b_key.len} + mut outer := []u8{cap: b_key.len} for i, b in hmac.opad[..blocksize] { outer << b_key[i] ^ b } @@ -39,6 +39,6 @@ pub fn new(key []byte, data []byte, hash_func fn ([]byte) []byte, blocksize int) // equal compares 2 MACs for equality, without leaking timing info. // Note: if the lengths of the 2 MACs are different, probably a completely different // hash function was used to generate them => no useful timing information. -pub fn equal(mac1 []byte, mac2 []byte) bool { +pub fn equal(mac1 []u8, mac2 []u8) bool { return subtle.constant_time_compare(mac1, mac2) == 1 } diff --git a/vlib/crypto/internal/subtle/aliasing.v b/vlib/crypto/internal/subtle/aliasing.v index 471111bd3c..90ac938c5e 100644 --- a/vlib/crypto/internal/subtle/aliasing.v +++ b/vlib/crypto/internal/subtle/aliasing.v @@ -8,7 +8,7 @@ module subtle // NOTE: require unsafe in future // any_overlap reports whether x and y share memory at any (not necessarily // corresponding) index. The memory beyond the slice length is ignored. -pub fn any_overlap(x []byte, y []byte) bool { +pub fn any_overlap(x []u8, y []u8) bool { // NOTE: Remember to come back to this (joe-c) return x.len > 0 && y.len > 0 && // &x.data[0] <= &y.data[y.len-1] && // &y.data[0] <= &x.data[x.len-1] @@ -21,7 +21,7 @@ pub fn any_overlap(x []byte, y []byte) bool { // // inexact_overlap can be used to implement the requirements of the crypto/cipher // AEAD, Block, BlockMode and Stream interfaces. -pub fn inexact_overlap(x []byte, y []byte) bool { +pub fn inexact_overlap(x []u8, y []u8) bool { if x.len == 0 || y.len == 0 || unsafe { &x[0] == &y[0] } { return false } diff --git a/vlib/crypto/internal/subtle/comparison.v b/vlib/crypto/internal/subtle/comparison.v index 38cd09c449..ba3bd381ad 100644 --- a/vlib/crypto/internal/subtle/comparison.v +++ b/vlib/crypto/internal/subtle/comparison.v @@ -19,7 +19,7 @@ pub fn constant_time_select(v int, x int, y int) int { // constant_time_compare returns 1 when x and y have equal contents. // The runtime of this function is proportional of the length of x and y. // It is *NOT* dependent on their content. -pub fn constant_time_compare(x []byte, y []byte) int { +pub fn constant_time_compare(x []u8, y []u8) int { if x.len != y.len { return 0 } @@ -33,7 +33,7 @@ pub fn constant_time_compare(x []byte, y []byte) int { // constant_time_copy copies the contents of y into x, when v == 1. // When v == 0, x is left unchanged. this function is undefined, when // v takes any other value -pub fn constant_time_copy(v int, mut x []byte, y []byte) { +pub fn constant_time_copy(v int, mut x []u8, y []u8) { if x.len != y.len { panic('subtle: arrays have different lengths') } diff --git a/vlib/crypto/md5/md5.v b/vlib/crypto/md5/md5.v index 496e18053f..6a13f506bb 100644 --- a/vlib/crypto/md5/md5.v +++ b/vlib/crypto/md5/md5.v @@ -28,14 +28,14 @@ const ( struct Digest { mut: s []u32 - x []byte + x []u8 nx int len u64 } fn (mut d Digest) reset() { d.s = []u32{len: (4)} - d.x = []byte{len: md5.block_size} + d.x = []u8{len: md5.block_size} d.s[0] = u32(md5.init0) d.s[1] = u32(md5.init1) d.s[2] = u32(md5.init2) @@ -52,7 +52,7 @@ pub fn new() &Digest { } // write writes the contents of `p_` to the internal hash representation. -pub fn (mut d Digest) write(p_ []byte) ?int { +pub fn (mut d Digest) write(p_ []u8) ?int { unsafe { mut p := p_ nn := p.len @@ -87,7 +87,7 @@ pub fn (mut d Digest) write(p_ []byte) ?int { } // sum returns the md5 sum of the bytes in `b_in`. -pub fn (d &Digest) sum(b_in []byte) []byte { +pub fn (d &Digest) sum(b_in []u8) []u8 { // Make a copy of d so that caller can keep writing and summing. mut d0 := *d hash := d0.checksum() @@ -99,14 +99,14 @@ pub fn (d &Digest) sum(b_in []byte) []byte { } // checksum returns the byte checksum of the `Digest`. -pub fn (mut d Digest) checksum() []byte { +pub fn (mut d Digest) checksum() []u8 { // Append 0x80 to the end of the message and then append zeros // until the length is a multiple of 56 bytes. Finally append // 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} - mut tmp := []byte{len: (1 + 63 + 8)} + mut tmp := []u8{len: (1 + 63 + 8)} tmp[0] = 0x80 pad := ((55 - d.len) % 64) // calculate number of padding bytes binary.little_endian_put_u64(mut tmp[1 + pad..], d.len << 3) // append length in bits @@ -116,7 +116,7 @@ pub fn (mut d Digest) checksum() []byte { if d.nx != 0 { panic('d.nx != 0') } - mut digest := []byte{len: md5.size} + mut digest := []u8{len: md5.size} binary.little_endian_put_u32(mut digest, d.s[0]) binary.little_endian_put_u32(mut digest[4..], d.s[1]) binary.little_endian_put_u32(mut digest[8..], d.s[2]) @@ -125,13 +125,13 @@ pub fn (mut d Digest) checksum() []byte { } // sum returns the MD5 checksum of the data. -pub fn sum(data []byte) []byte { +pub fn sum(data []u8) []u8 { mut d := new() d.write(data) or { panic(err) } return d.checksum() } -fn block(mut dig Digest, p []byte) { +fn block(mut dig Digest, p []u8) { // For now just use block_generic until we have specific // architecture optimized versions block_generic(mut dig, p) diff --git a/vlib/crypto/md5/md5block_generic.v b/vlib/crypto/md5/md5block_generic.v index e66f5c3c59..f4020a177c 100644 --- a/vlib/crypto/md5/md5block_generic.v +++ b/vlib/crypto/md5/md5block_generic.v @@ -11,7 +11,7 @@ module md5 import math.bits import encoding.binary -fn block_generic(mut dig Digest, p []byte) { +fn block_generic(mut dig Digest, p []u8) { // load state mut a := dig.s[0] mut b := dig.s[1] diff --git a/vlib/crypto/rand/rand.v b/vlib/crypto/rand/rand.v index 7925895d05..07e462e226 100644 --- a/vlib/crypto/rand/rand.v +++ b/vlib/crypto/rand/rand.v @@ -18,6 +18,6 @@ pub fn (err ReadError) msg() string { // See also rand.bytes(), if you do not need really random bytes, // but instead pseudo random ones, from a pseudo random generator // that can be seeded, and that is usually faster. -pub fn bytes(bytes_needed int) ?[]byte { +pub fn bytes(bytes_needed int) ?[]u8 { return read(bytes_needed) } diff --git a/vlib/crypto/rand/rand_darwin.c.v b/vlib/crypto/rand/rand_darwin.c.v index f2efdd8b24..b71b2cbdfd 100644 --- a/vlib/crypto/rand/rand_darwin.c.v +++ b/vlib/crypto/rand/rand_darwin.c.v @@ -11,8 +11,8 @@ module rand fn C.SecRandomCopyBytes(rnd C.SecRandomRef, count usize, bytes voidptr) int // read returns an array of `bytes_needed` random bytes read from the OS. -pub fn read(bytes_needed int) ?[]byte { - mut buffer := []byte{len: bytes_needed} +pub fn read(bytes_needed int) ?[]u8 { + mut buffer := []u8{len: bytes_needed} status := C.SecRandomCopyBytes(C.SecRandomRef(0), bytes_needed, buffer.data) if status != 0 { return IError(&ReadError{}) diff --git a/vlib/crypto/rand/rand_default.c.v b/vlib/crypto/rand/rand_default.c.v index bcaf950f39..86afc848fb 100644 --- a/vlib/crypto/rand/rand_default.c.v +++ b/vlib/crypto/rand/rand_default.c.v @@ -4,6 +4,6 @@ module rand // read returns an array of `bytes_needed` random bytes read from the OS. -pub fn read(bytes_needed int) ?[]byte { +pub fn read(bytes_needed int) ?[]u8 { return error('rand.read is not implemented on this platform') } diff --git a/vlib/crypto/rand/rand_linux.c.v b/vlib/crypto/rand/rand_linux.c.v index 3cd68cd293..03fa9541f3 100644 --- a/vlib/crypto/rand/rand_linux.c.v +++ b/vlib/crypto/rand/rand_linux.c.v @@ -10,7 +10,7 @@ const ( ) // read returns an array of `bytes_needed` random bytes read from the OS. -pub fn read(bytes_needed int) ?[]byte { +pub fn read(bytes_needed int) ?[]u8 { mut buffer := unsafe { vcalloc_noscan(bytes_needed) } mut bytes_read := 0 mut remaining_bytes := bytes_needed diff --git a/vlib/crypto/rand/rand_solaris.c.v b/vlib/crypto/rand/rand_solaris.c.v index 97dc8952ed..35bfd8af89 100644 --- a/vlib/crypto/rand/rand_solaris.c.v +++ b/vlib/crypto/rand/rand_solaris.c.v @@ -13,7 +13,7 @@ const ( ) // read returns an array of `bytes_needed` random bytes read from the OS. -pub fn read(bytes_needed int) ?[]byte { +pub fn read(bytes_needed int) ?[]u8 { mut buffer := unsafe { malloc_noscan(bytes_needed) } mut bytes_read := 0 mut remaining_bytes := bytes_needed diff --git a/vlib/crypto/rand/rand_windows.c.v b/vlib/crypto/rand/rand_windows.c.v index 79267efc3b..b6ac92b55c 100644 --- a/vlib/crypto/rand/rand_windows.c.v +++ b/vlib/crypto/rand/rand_windows.c.v @@ -14,8 +14,8 @@ const ( ) // read returns an array of `bytes_needed` random bytes read from the OS. -pub fn read(bytes_needed int) ?[]byte { - mut buffer := []byte{len: bytes_needed} +pub fn read(bytes_needed int) ?[]u8 { + mut buffer := []u8{len: bytes_needed} // use bcrypt_use_system_preferred_rng because we passed null as algo status := C.BCryptGenRandom(0, buffer.data, bytes_needed, rand.bcrypt_use_system_preferred_rng) if status != rand.status_success { diff --git a/vlib/crypto/rand/utils.v b/vlib/crypto/rand/utils.v index 9ce01e26b9..52ed7b600e 100644 --- a/vlib/crypto/rand/utils.v +++ b/vlib/crypto/rand/utils.v @@ -35,7 +35,7 @@ pub fn int_u64(max u64) ?u64 { return n } -fn bytes_to_u64(b []byte) []u64 { +fn bytes_to_u64(b []u8) []u64 { ws := 64 / 8 mut z := []u64{len: ((b.len + ws - 1) / ws)} mut i := b.len diff --git a/vlib/crypto/rc4/rc4.v b/vlib/crypto/rc4/rc4.v index 0bcaff30f3..f05aac8964 100644 --- a/vlib/crypto/rc4/rc4.v +++ b/vlib/crypto/rc4/rc4.v @@ -22,7 +22,7 @@ mut: // new_cipher creates and returns a new Cipher. The key argument should be the // RC4 key, at least 1 byte and at most 256 bytes. -pub fn new_cipher(key []byte) ?Cipher { +pub fn new_cipher(key []u8) ?Cipher { if key.len < 1 || key.len > 256 { return error('crypto.rc4: invalid key size ' + key.len.str()) } @@ -56,7 +56,7 @@ pub fn (mut c Cipher) reset() { // xor_key_stream sets dst to the result of XORing src with the key stream. // Dst and src must overlap entirely or not at all. -pub fn (mut c Cipher) xor_key_stream(mut dst []byte, mut src []byte) { +pub fn (mut c Cipher) xor_key_stream(mut dst []u8, mut src []u8) { if src.len == 0 { return } diff --git a/vlib/crypto/sha1/sha1.v b/vlib/crypto/sha1/sha1.v index 04678f7822..fc3d5d3304 100644 --- a/vlib/crypto/sha1/sha1.v +++ b/vlib/crypto/sha1/sha1.v @@ -30,13 +30,13 @@ const ( struct Digest { mut: h []u32 - x []byte + x []u8 nx int len u64 } fn (mut d Digest) reset() { - d.x = []byte{len: sha1.chunk} + d.x = []u8{len: sha1.chunk} d.h = []u32{len: (5)} d.h[0] = u32(sha1.init0) d.h[1] = u32(sha1.init1) @@ -56,7 +56,7 @@ pub fn new() &Digest { // write writes the contents of `p_` to the internal hash representation. [manualfree] -pub fn (mut d Digest) write(p_ []byte) ?int { +pub fn (mut d Digest) write(p_ []u8) ?int { nn := p_.len unsafe { mut p := p_ @@ -91,7 +91,7 @@ pub fn (mut d Digest) write(p_ []byte) ?int { } // sum returns a copy of the generated sum of the bytes in `b_in`. -pub fn (d &Digest) sum(b_in []byte) []byte { +pub fn (d &Digest) sum(b_in []u8) []u8 { // Make a copy of d so that caller can keep writing and summing. mut d0 := *d hash := d0.checksum() @@ -103,10 +103,10 @@ pub fn (d &Digest) sum(b_in []byte) []byte { } // checksum returns the current byte checksum of the `Digest`. -pub fn (mut d Digest) checksum() []byte { +pub fn (mut d Digest) checksum() []u8 { mut len := d.len // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. - mut tmp := []byte{len: (64)} + mut tmp := []u8{len: (64)} tmp[0] = 0x80 if int(len) % 64 < 56 { d.write(tmp[..56 - int(len) % 64]) or { panic(err) } @@ -117,7 +117,7 @@ pub fn (mut d Digest) checksum() []byte { len <<= 3 binary.big_endian_put_u64(mut tmp, len) d.write(tmp[..8]) or { panic(err) } - mut digest := []byte{len: sha1.size} + mut digest := []u8{len: sha1.size} binary.big_endian_put_u32(mut digest, d.h[0]) binary.big_endian_put_u32(mut digest[4..], d.h[1]) binary.big_endian_put_u32(mut digest[8..], d.h[2]) @@ -127,13 +127,13 @@ pub fn (mut d Digest) checksum() []byte { } // sum returns the SHA-1 checksum of the bytes passed in `data`. -pub fn sum(data []byte) []byte { +pub fn sum(data []u8) []u8 { mut d := new() d.write(data) or { panic(err) } return d.checksum() } -fn block(mut dig Digest, p []byte) { +fn block(mut dig Digest, p []u8) { // For now just use block_generic until we have specific // architecture optimized versions block_generic(mut dig, p) diff --git a/vlib/crypto/sha1/sha1block_generic.v b/vlib/crypto/sha1/sha1block_generic.v index 4f660855d1..d03bd8f400 100644 --- a/vlib/crypto/sha1/sha1block_generic.v +++ b/vlib/crypto/sha1/sha1block_generic.v @@ -15,7 +15,7 @@ const ( _k3 = 0xCA62C1D6 ) -fn block_generic(mut dig Digest, p_ []byte) { +fn block_generic(mut dig Digest, p_ []u8) { unsafe { mut p := p_ mut w := []u32{len: (16)} diff --git a/vlib/crypto/sha256/sha256.v b/vlib/crypto/sha256/sha256.v index e8bd91833c..b350923bd8 100644 --- a/vlib/crypto/sha256/sha256.v +++ b/vlib/crypto/sha256/sha256.v @@ -42,7 +42,7 @@ const ( struct Digest { mut: h []u32 - x []byte + x []u8 nx int len u64 is224 bool // mark if this digest is SHA-224 @@ -50,7 +50,7 @@ mut: fn (mut d Digest) reset() { d.h = []u32{len: (8)} - d.x = []byte{len: sha256.chunk} + d.x = []u8{len: sha256.chunk} if !d.is224 { d.h[0] = u32(sha256.init0) d.h[1] = u32(sha256.init1) @@ -90,7 +90,7 @@ pub fn new224() &Digest { } // write writes the contents of `p_` to the internal hash representation. -pub fn (mut d Digest) write(p_ []byte) ?int { +pub fn (mut d Digest) write(p_ []u8) ?int { unsafe { mut p := p_ nn := p.len @@ -125,7 +125,7 @@ pub fn (mut d Digest) write(p_ []byte) ?int { } // sum returns the SHA256 or SHA224 checksum of digest with the data. -pub fn (d &Digest) sum(b_in []byte) []byte { +pub fn (d &Digest) sum(b_in []u8) []u8 { // Make a copy of d so that caller can keep writing and summing. mut d0 := *d hash := d0.checksum() @@ -143,10 +143,10 @@ pub fn (d &Digest) sum(b_in []byte) []byte { } // checksum returns the current byte checksum of the Digest. -pub fn (mut d Digest) checksum() []byte { +pub fn (mut d Digest) checksum() []u8 { mut len := d.len // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. - mut tmp := []byte{len: (64)} + mut tmp := []u8{len: (64)} tmp[0] = 0x80 if int(len) % 64 < 56 { d.write(tmp[..56 - int(len) % 64]) or { panic(err) } @@ -160,7 +160,7 @@ pub fn (mut d Digest) checksum() []byte { if d.nx != 0 { panic('d.nx != 0') } - mut digest := []byte{len: sha256.size} + mut digest := []u8{len: sha256.size} binary.big_endian_put_u32(mut digest, d.h[0]) binary.big_endian_put_u32(mut digest[4..], d.h[1]) binary.big_endian_put_u32(mut digest[8..], d.h[2]) @@ -176,28 +176,28 @@ pub fn (mut d Digest) checksum() []byte { // sum returns the SHA256 checksum of the bytes in `data`. // Example: assert sha256.sum('V'.bytes()).len > 0 == true -pub fn sum(data []byte) []byte { +pub fn sum(data []u8) []u8 { return sum256(data) } // sum256 returns the SHA256 checksum of the data. -pub fn sum256(data []byte) []byte { +pub fn sum256(data []u8) []u8 { mut d := new() d.write(data) or { panic(err) } return d.checksum() } // sum224 returns the SHA224 checksum of the data. -pub fn sum224(data []byte) []byte { +pub fn sum224(data []u8) []u8 { mut d := new224() d.write(data) or { panic(err) } sum := d.checksum() - mut sum224 := []byte{len: sha256.size224} + mut sum224 := []u8{len: sha256.size224} copy(mut sum224, sum[..sha256.size224]) return sum224 } -fn block(mut dig Digest, p []byte) { +fn block(mut dig Digest, p []u8) { // For now just use block_generic until we have specific // architecture optimized versions block_generic(mut dig, p) diff --git a/vlib/crypto/sha256/sha256block_generic.v b/vlib/crypto/sha256/sha256block_generic.v index 46416b636d..96dc9da2fc 100644 --- a/vlib/crypto/sha256/sha256block_generic.v +++ b/vlib/crypto/sha256/sha256block_generic.v @@ -78,7 +78,7 @@ const ( ] ) -fn block_generic(mut dig Digest, p_ []byte) { +fn block_generic(mut dig Digest, p_ []u8) { unsafe { mut p := p_ mut w := []u32{len: (64)} diff --git a/vlib/crypto/sha512/sha512.v b/vlib/crypto/sha512/sha512.v index 6327ab3fe9..4aebaf0abd 100644 --- a/vlib/crypto/sha512/sha512.v +++ b/vlib/crypto/sha512/sha512.v @@ -64,7 +64,7 @@ const ( struct Digest { mut: h []u64 - x []byte + x []u8 nx int len u64 function crypto.Hash @@ -72,7 +72,7 @@ mut: fn (mut d Digest) reset() { d.h = []u64{len: (8)} - d.x = []byte{len: sha512.chunk} + d.x = []u8{len: sha512.chunk} match d.function { .sha384 { d.h[0] = sha512.init0_384 @@ -149,7 +149,7 @@ fn new384() &Digest { } // write writes the contents of `p_` to the internal hash representation. -pub fn (mut d Digest) write(p_ []byte) ?int { +pub fn (mut d Digest) write(p_ []u8) ?int { unsafe { mut p := p_ nn := p.len @@ -184,7 +184,7 @@ pub fn (mut d Digest) write(p_ []byte) ?int { } // sum returns the SHA512 or SHA384 checksum of digest with the data bytes in `b_in` -pub fn (d &Digest) sum(b_in []byte) []byte { +pub fn (d &Digest) sum(b_in []u8) []u8 { // Make a copy of d so that caller can keep writing and summing. mut d0 := *d hash := d0.checksum() @@ -215,10 +215,10 @@ pub fn (d &Digest) sum(b_in []byte) []byte { } // checksum returns the current byte checksum of the Digest. -pub fn (mut d Digest) checksum() []byte { +pub fn (mut d Digest) checksum() []u8 { // Padding. Add a 1 bit and 0 bits until 112 bytes mod 128. mut len := d.len - mut tmp := []byte{len: (128)} + mut tmp := []u8{len: (128)} tmp[0] = 0x80 if int(len) % 128 < 112 { d.write(tmp[..112 - int(len) % 128]) or { panic(err) } @@ -233,7 +233,7 @@ pub fn (mut d Digest) checksum() []byte { if d.nx != 0 { panic('d.nx != 0') } - mut digest := []byte{len: sha512.size} + mut digest := []u8{len: sha512.size} binary.big_endian_put_u64(mut digest, d.h[0]) binary.big_endian_put_u64(mut digest[8..], d.h[1]) binary.big_endian_put_u64(mut digest[16..], d.h[2]) @@ -248,43 +248,43 @@ pub fn (mut d Digest) checksum() []byte { } // sum512 returns the SHA512 checksum of the data. -pub fn sum512(data []byte) []byte { +pub fn sum512(data []u8) []u8 { mut d := new_digest(.sha512) d.write(data) or { panic(err) } return d.checksum() } // sum384 returns the SHA384 checksum of the data. -pub fn sum384(data []byte) []byte { +pub fn sum384(data []u8) []u8 { mut d := new_digest(.sha384) d.write(data) or { panic(err) } sum := d.checksum() - mut sum384 := []byte{len: sha512.size384} + mut sum384 := []u8{len: sha512.size384} copy(mut sum384, sum[..sha512.size384]) return sum384 } // sum512_224 returns the Sum512/224 checksum of the data. -pub fn sum512_224(data []byte) []byte { +pub fn sum512_224(data []u8) []u8 { mut d := new_digest(.sha512_224) d.write(data) or { panic(err) } sum := d.checksum() - mut sum224 := []byte{len: sha512.size224} + mut sum224 := []u8{len: sha512.size224} copy(mut sum224, sum[..sha512.size224]) return sum224 } // sum512_256 returns the Sum512/256 checksum of the data. -pub fn sum512_256(data []byte) []byte { +pub fn sum512_256(data []u8) []u8 { mut d := new_digest(.sha512_256) d.write(data) or { panic(err) } sum := d.checksum() - mut sum256 := []byte{len: sha512.size256} + mut sum256 := []u8{len: sha512.size256} copy(mut sum256, sum[..sha512.size256]) return sum256 } -fn block(mut dig Digest, p []byte) { +fn block(mut dig Digest, p []u8) { // For now just use block_generic until we have specific // architecture optimized versions block_generic(mut dig, p) diff --git a/vlib/crypto/sha512/sha512block_generic.v b/vlib/crypto/sha512/sha512block_generic.v index 777d266da2..c6ab3518f5 100644 --- a/vlib/crypto/sha512/sha512block_generic.v +++ b/vlib/crypto/sha512/sha512block_generic.v @@ -32,7 +32,7 @@ const ( u64(0x4cc5d4becb3e42b6), u64(0x597f299cfc657e2a), u64(0x5fcb6fab3ad6faec), u64(0x6c44198c4a475817)] ) -fn block_generic(mut dig Digest, p_ []byte) { +fn block_generic(mut dig Digest, p_ []u8) { unsafe { mut p := p_ mut w := []u64{len: (80)} diff --git a/vlib/encoding/base58/alphabet.v b/vlib/encoding/base58/alphabet.v index 60e469e083..1cc00f8a0e 100644 --- a/vlib/encoding/base58/alphabet.v +++ b/vlib/encoding/base58/alphabet.v @@ -25,13 +25,13 @@ fn init_alphabets() map[string]Alphabet { struct Alphabet { mut: decode []i8 = []i8{len: 128, init: -1} - encode []byte = []byte{len: 58} + encode []u8 = []u8{len: 58} } // str returns an Alphabet encode table byte array as a string pub fn (alphabet Alphabet) str() string { // i guess i had a brain fart here. Why would I actually use this code?! - // mut str := []byte{} + // mut str := []u8{} // for entry in alphabet.encode { // str << entry // } diff --git a/vlib/encoding/base58/base58.v b/vlib/encoding/base58/base58.v index d1a7bfd715..30f6f58a51 100644 --- a/vlib/encoding/base58/base58.v +++ b/vlib/encoding/base58/base58.v @@ -15,7 +15,7 @@ pub fn encode_int_walpha(input int, alphabet Alphabet) ?string { return error(@MOD + '.' + @FN + ': input must be greater than zero') } - mut buffer := []byte{} + mut buffer := []u8{} mut i := input for i > 0 { @@ -55,7 +55,7 @@ pub fn encode_walpha(input string, alphabet Alphabet) string { // integer simplification of // ceil(log(256)/log(58)) - mut out := []byte{len: sz} + mut out := []u8{len: sz} mut i := 0 mut high := 0 mut carry := u32(0) @@ -131,7 +131,7 @@ pub fn decode_walpha(str string, alphabet Alphabet) ?string { mut c := u64(0) // the 32-bit algorithm stretches the result up to 2x - mut binu := []byte{len: 2 * ((b58sz * 406 / 555) + 1)} + mut binu := []u8{len: 2 * ((b58sz * 406 / 555) + 1)} mut outi := []u32{len: (b58sz + 3) / 4} for _, r in str { diff --git a/vlib/encoding/base64/base64.c.v b/vlib/encoding/base64/base64.c.v index 3fc97aac0e..08bd68f73b 100644 --- a/vlib/encoding/base64/base64.c.v +++ b/vlib/encoding/base64/base64.c.v @@ -215,7 +215,7 @@ pub fn decode_str(data string) string { } } -// encode encodes the `[]byte` value passed in `data` to base64. +// encode encodes the `[]u8` value passed in `data` to base64. // Please note: base64 encoding returns a `string` that is ~ 4/3 larger than the input. // Please note: If you need to encode many strings repeatedly, take a look at `encode_in_buffer`. // Example: assert base64.encode('V in base 64') == 'ViBpbiBiYXNlIDY0' diff --git a/vlib/encoding/base64/base64.v b/vlib/encoding/base64/base64.v index 87dd0b405f..0f45ed2a06 100644 --- a/vlib/encoding/base64/base64.v +++ b/vlib/encoding/base64/base64.v @@ -17,7 +17,7 @@ const ( // url_decode returns a decoded URL `string` version of // the a base64 url encoded `string` passed in `data`. -pub fn url_decode(data string) []byte { +pub fn url_decode(data string) []u8 { mut result := data.replace_each(['-', '+', '_', '/']) match result.len % 4 { // Pad with trailing '='s @@ -42,7 +42,7 @@ pub fn url_decode_str(data string) string { // url_encode returns a base64 URL encoded `string` version // of the value passed in `data`. -pub fn url_encode(data []byte) string { +pub fn url_encode(data []u8) string { return encode(data).replace_each(['+', '-', '/', '_', '=', '']) } diff --git a/vlib/encoding/base64/base64_memory_test.v b/vlib/encoding/base64/base64_memory_test.v index be543af486..a6058706a2 100644 --- a/vlib/encoding/base64/base64_memory_test.v +++ b/vlib/encoding/base64/base64_memory_test.v @@ -4,7 +4,7 @@ fn test_long_encoding() { repeats := 1000 input_size := 3000 - s_original := []byte{len: input_size, init: `a`} + s_original := []u8{len: input_size, init: `a`} s_encoded := base64.encode(s_original) s_encoded_bytes := s_encoded.bytes() s_decoded := base64.decode(s_encoded) @@ -20,7 +20,7 @@ fn test_long_encoding() { } // encoded_size := base64.encode_in_buffer(s_original, ebuffer) - mut encoded_in_buf := []byte{len: encoded_size} + mut encoded_in_buf := []u8{len: encoded_size} unsafe { C.memcpy(encoded_in_buf.data, ebuffer, encoded_size) } assert input_size * 4 / 3 == encoded_size assert encoded_in_buf[0] == `Y` @@ -37,7 +37,7 @@ fn test_long_encoding() { decoded_size := base64.decode_in_buffer(s_encoded, dbuffer) assert decoded_size == input_size - mut decoded_in_buf := []byte{len: decoded_size} + mut decoded_in_buf := []u8{len: decoded_size} unsafe { C.memcpy(decoded_in_buf.data, dbuffer, decoded_size) } assert decoded_in_buf == s_original diff --git a/vlib/encoding/base64/base64_test.v b/vlib/encoding/base64/base64_test.v index 95e557cf94..bb0bbd2705 100644 --- a/vlib/encoding/base64/base64_test.v +++ b/vlib/encoding/base64/base64_test.v @@ -137,9 +137,9 @@ fn test_decode_in_buffer_bytes() { TestPair{'fooba', 'Zm9vYmE='}, TestPair{'foobar', 'Zm9vYmFy'}, ] - mut src_dec_buf := []byte{len: 8} - mut src_enc_buf := []byte{len: 8} - mut out_buf := []byte{len: 8} + mut src_dec_buf := []u8{len: 8} + mut src_enc_buf := []u8{len: 8} + mut out_buf := []u8{len: 8} for p in rfc4648_pairs { src_dec_buf = p.decoded.bytes() diff --git a/vlib/encoding/binary/binary.v b/vlib/encoding/binary/binary.v index 3a6753f9b5..1aa8c2eef4 100644 --- a/vlib/encoding/binary/binary.v +++ b/vlib/encoding/binary/binary.v @@ -5,26 +5,26 @@ module binary // Little Endian [inline] -pub fn little_endian_u16(b []byte) u16 { +pub fn little_endian_u16(b []u8) u16 { _ = b[1] // bounds check return u16(b[0]) | (u16(b[1]) << u16(8)) } [inline] -pub fn little_endian_put_u16(mut b []byte, v u16) { +pub fn little_endian_put_u16(mut b []u8, v u16) { _ = b[1] // bounds check b[0] = u8(v) b[1] = u8(v >> u16(8)) } [inline] -pub fn little_endian_u32(b []byte) u32 { +pub fn little_endian_u32(b []u8) u32 { _ = b[3] // bounds check return u32(b[0]) | (u32(b[1]) << u32(8)) | (u32(b[2]) << u32(16)) | (u32(b[3]) << u32(24)) } [inline] -pub fn little_endian_put_u32(mut b []byte, v u32) { +pub fn little_endian_put_u32(mut b []u8, v u32) { _ = b[3] // bounds check b[0] = u8(v) b[1] = u8(v >> u32(8)) @@ -33,13 +33,13 @@ pub fn little_endian_put_u32(mut b []byte, v u32) { } [inline] -pub fn little_endian_u64(b []byte) u64 { +pub fn little_endian_u64(b []u8) u64 { _ = b[7] // bounds check return u64(b[0]) | (u64(b[1]) << u64(8)) | (u64(b[2]) << u64(16)) | (u64(b[3]) << u64(24)) | (u64(b[4]) << u64(32)) | (u64(b[5]) << u64(40)) | (u64(b[6]) << u64(48)) | (u64(b[7]) << u64(56)) } [inline] -pub fn little_endian_put_u64(mut b []byte, v u64) { +pub fn little_endian_put_u64(mut b []u8, v u64) { _ = b[7] // bounds check b[0] = u8(v) b[1] = u8(v >> u64(8)) @@ -53,26 +53,26 @@ pub fn little_endian_put_u64(mut b []byte, v u64) { // Big Endian [inline] -pub fn big_endian_u16(b []byte) u16 { +pub fn big_endian_u16(b []u8) u16 { _ = b[1] // bounds check return u16(b[1]) | (u16(b[0]) << u16(8)) } [inline] -pub fn big_endian_put_u16(mut b []byte, v u16) { +pub fn big_endian_put_u16(mut b []u8, v u16) { _ = b[1] // bounds check b[0] = u8(v >> u16(8)) b[1] = u8(v) } [inline] -pub fn big_endian_u32(b []byte) u32 { +pub fn big_endian_u32(b []u8) u32 { _ = b[3] // bounds check return u32(b[3]) | (u32(b[2]) << u32(8)) | (u32(b[1]) << u32(16)) | (u32(b[0]) << u32(24)) } [inline] -pub fn big_endian_put_u32(mut b []byte, v u32) { +pub fn big_endian_put_u32(mut b []u8, v u32) { _ = b[3] // bounds check b[0] = u8(v >> u32(24)) b[1] = u8(v >> u32(16)) @@ -81,13 +81,13 @@ pub fn big_endian_put_u32(mut b []byte, v u32) { } [inline] -pub fn big_endian_u64(b []byte) u64 { +pub fn big_endian_u64(b []u8) u64 { _ = b[7] // bounds check return u64(b[7]) | (u64(b[6]) << u64(8)) | (u64(b[5]) << u64(16)) | (u64(b[4]) << u64(24)) | (u64(b[3]) << u64(32)) | (u64(b[2]) << u64(40)) | (u64(b[1]) << u64(48)) | (u64(b[0]) << u64(56)) } [inline] -pub fn big_endian_put_u64(mut b []byte, v u64) { +pub fn big_endian_put_u64(mut b []u8, v u64) { _ = b[7] // bounds check b[0] = u8(v >> u64(56)) b[1] = u8(v >> u64(48)) diff --git a/vlib/encoding/hex/hex.v b/vlib/encoding/hex/hex.v index 4dcc8a3fc2..d709f01e85 100644 --- a/vlib/encoding/hex/hex.v +++ b/vlib/encoding/hex/hex.v @@ -5,7 +5,7 @@ import strings // decode converts a hex string into an array of bytes. The expected // input format is 2 ASCII characters for each output byte. If the provided // string length is not a multiple of 2, an implicit `0` is prepended to it. -pub fn decode(s string) ?[]byte { +pub fn decode(s string) ?[]u8 { mut hex_str := s if hex_str.len >= 2 { if s[0] == `0` && (s[1] == `x` || s[1] == `X`) { @@ -13,7 +13,7 @@ pub fn decode(s string) ?[]byte { } } if hex_str.len == 0 { - return []byte{} + return []u8{} } else if hex_str.len == 1 { return [char2nibble(hex_str[0]) ?] } else if hex_str.len == 2 { @@ -27,7 +27,7 @@ pub fn decode(s string) ?[]byte { val = (val << 4) | char2nibble(hex_str[1]) ? } // set cap to hex_str.len/2 rounded up - mut bytes := []byte{len: 1, cap: (hex_str.len + 1) >> 1, init: val} + mut bytes := []u8{len: 1, cap: (hex_str.len + 1) >> 1, init: val} // iterate over every 2 bytes // the start index depends on if hex_str.len is odd for i := 2 - (hex_str.len & 1); i < hex_str.len; i += 2 { @@ -41,7 +41,7 @@ pub fn decode(s string) ?[]byte { // encode converts an array of bytes into a string of ASCII hex bytes. The // output will always be a string with length a multiple of 2. [manualfree] -pub fn encode(bytes []byte) string { +pub fn encode(bytes []u8) string { mut sb := strings.new_builder(bytes.len * 2) for b in bytes { sb.write_string(b.hex()) diff --git a/vlib/fontstash/fontstash.c.v b/vlib/fontstash/fontstash.c.v index cdc19c881a..1253d9da88 100644 --- a/vlib/fontstash/fontstash.c.v +++ b/vlib/fontstash/fontstash.c.v @@ -92,7 +92,7 @@ pub fn (s &Context) add_fallback_font(base int, fallback int) int { // `free_data` indicates if `data` should be freed after the font is added. // The function returns the id of the font on success, `fontstash.invalid` otherwise. [inline] -pub fn (s &Context) add_font_mem(name string, data []byte, free_data bool) int { +pub fn (s &Context) add_font_mem(name string, data []u8, free_data bool) int { return C.fonsAddFontMem(s, &char(name.str), data.data, data.len, int(free_data)) } diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index e19ea24b29..cc38d50a34 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -92,10 +92,10 @@ pub: custom_bold_font_path string ui_mode bool // refreshes only on events to save CPU usage // font bytes for embedding - font_bytes_normal []byte - font_bytes_bold []byte - font_bytes_mono []byte - font_bytes_italic []byte + font_bytes_normal []u8 + font_bytes_bold []u8 + font_bytes_mono []u8 + font_bytes_italic []u8 native_rendering bool // Cocoa on macOS/iOS, GDI+ on Windows // drag&drop enable_dragndrop bool // enable file dropping (drag'n'drop), default is false diff --git a/vlib/gg/gg.js.v b/vlib/gg/gg.js.v index e71b7bc30a..b5eccbb3d5 100644 --- a/vlib/gg/gg.js.v +++ b/vlib/gg/gg.js.v @@ -243,10 +243,10 @@ pub: custom_bold_font_path string ui_mode bool // refreshes only on events to save CPU usage // font bytes for embedding - font_bytes_normal []byte - font_bytes_bold []byte - font_bytes_mono []byte - font_bytes_italic []byte + font_bytes_normal []u8 + font_bytes_bold []u8 + font_bytes_mono []u8 + font_bytes_italic []u8 native_rendering bool // Cocoa on macOS/iOS, GDI+ on Windows // drag&drop enable_dragndrop bool // enable file dropping (drag'n'drop), default is false diff --git a/vlib/gg/image.c.v b/vlib/gg/image.c.v index a2cf3e01cf..7da0a74042 100644 --- a/vlib/gg/image.c.v +++ b/vlib/gg/image.c.v @@ -237,7 +237,7 @@ pub fn (mut ctx Context) create_image_from_memory(buf &byte, bufsize int) Image // byte array `b`. // // See also: create_image_from_memory -pub fn (mut ctx Context) create_image_from_byte_array(b []byte) Image { +pub fn (mut ctx Context) create_image_from_byte_array(b []u8) Image { return ctx.create_image_from_memory(b.data, b.len) } diff --git a/vlib/gg/text_rendering.c.v b/vlib/gg/text_rendering.c.v index 04dd5d5edc..3b724a89f8 100644 --- a/vlib/gg/text_rendering.c.v +++ b/vlib/gg/text_rendering.c.v @@ -64,10 +64,10 @@ fn new_ft(c FTConfig) ?&FT { } mut normal_path := c.font_path - mut bytes := []byte{} + mut bytes := []u8{} $if android { // First try any filesystem paths - bytes = os.read_bytes(c.font_path) or { []byte{} } + bytes = os.read_bytes(c.font_path) or { []u8{} } if bytes.len == 0 { // ... then try the APK asset path bytes = os.read_apk_asset(c.font_path) or { diff --git a/vlib/gg/text_rendering.v b/vlib/gg/text_rendering.v index f148d9e3d4..be2ef0882f 100644 --- a/vlib/gg/text_rendering.v +++ b/vlib/gg/text_rendering.v @@ -9,10 +9,10 @@ struct FTConfig { custom_bold_font_path string scale f32 = 1.0 font_size int - bytes_normal []byte - bytes_bold []byte - bytes_mono []byte - bytes_italic []byte + bytes_normal []u8 + bytes_bold []u8 + bytes_mono []u8 + bytes_italic []u8 } struct StringToRender { diff --git a/vlib/hash/crc32/crc32.v b/vlib/hash/crc32/crc32.v index f7202829bc..38c54719a7 100644 --- a/vlib/hash/crc32/crc32.v +++ b/vlib/hash/crc32/crc32.v @@ -37,7 +37,7 @@ fn (mut c Crc32) generate_table(poly int) { } } -fn (c &Crc32) sum32(b []byte) u32 { +fn (c &Crc32) sum32(b []u8) u32 { mut crc := ~u32(0) for i in 0 .. b.len { crc = c.table[u8(crc) ^ b[i]] ^ (crc >> 8) @@ -45,7 +45,7 @@ fn (c &Crc32) sum32(b []byte) u32 { return ~crc } -pub fn (c &Crc32) checksum(b []byte) u32 { +pub fn (c &Crc32) checksum(b []u8) u32 { return c.sum32(b) } @@ -57,7 +57,7 @@ pub fn new(poly int) &Crc32 { } // calculate crc32 using ieee -pub fn sum(b []byte) u32 { +pub fn sum(b []u8) u32 { c := new(int(crc32.ieee)) return c.sum32(b) } diff --git a/vlib/hash/fnv1a/fnv1a.v b/vlib/hash/fnv1a/fnv1a.v index f4e6f08d44..8d32c5d066 100644 --- a/vlib/hash/fnv1a/fnv1a.v +++ b/vlib/hash/fnv1a/fnv1a.v @@ -23,7 +23,7 @@ pub fn sum32_string(data string) u32 { // sum32 returns a fnv1a hash of the memory block, described by the dynamic // byte array `data`. [direct_array_access; inline] -pub fn sum32(data []byte) u32 { +pub fn sum32(data []u8) u32 { mut hash := fnv1a.fnv32_offset_basis for i in 0 .. data.len { hash = (hash ^ u32(data[i])) * fnv1a.fnv32_prime @@ -67,7 +67,7 @@ pub fn sum64_string(data string) u64 { // sum64 returns a fnv1a hash of the memory block, described by the dynamic // byte array `data`. [direct_array_access; inline] -pub fn sum64(data []byte) u64 { +pub fn sum64(data []u8) u64 { mut hash := fnv1a.fnv64_offset_basis for i in 0 .. data.len { hash = (hash ^ u64(data[i])) * fnv1a.fnv64_prime diff --git a/vlib/hash/hash.v b/vlib/hash/hash.v index bd51a376b0..e7bea39594 100644 --- a/vlib/hash/hash.v +++ b/vlib/hash/hash.v @@ -6,7 +6,7 @@ module hash interface Hasher { // Sum appends the current hash to b and returns the resulting array. // It does not change the underlying hash state. - sum(b []byte) []byte + sum(b []u8) []u8 size() int block_size() int } diff --git a/vlib/hash/wyhash.c.v b/vlib/hash/wyhash.c.v index 98cad20206..71dd11d369 100644 --- a/vlib/hash/wyhash.c.v +++ b/vlib/hash/wyhash.c.v @@ -22,6 +22,6 @@ pub fn sum64_string(key string, seed u64) u64 { } [inline] -pub fn sum64(key []byte, seed u64) u64 { +pub fn sum64(key []u8, seed u64) u64 { return wyhash_c(&u8(key.data), u64(key.len), seed) } diff --git a/vlib/io/buffered_reader.v b/vlib/io/buffered_reader.v index 3df4128464..a78e941dbd 100644 --- a/vlib/io/buffered_reader.v +++ b/vlib/io/buffered_reader.v @@ -4,7 +4,7 @@ module io struct BufferedReader { mut: reader Reader - buf []byte + buf []u8 offset int // current offset in the buffer len int fails int // how many times fill_buffer has read 0 bytes in a row @@ -28,7 +28,7 @@ pub fn new_buffered_reader(o BufferedReaderConfig) &BufferedReader { // create r := &BufferedReader{ reader: o.reader - buf: []byte{len: o.cap, cap: o.cap} + buf: []u8{len: o.cap, cap: o.cap} offset: 0 mfails: o.retries } @@ -36,7 +36,7 @@ pub fn new_buffered_reader(o BufferedReaderConfig) &BufferedReader { } // read fufills the Reader interface -pub fn (mut r BufferedReader) read(mut buf []byte) ?int { +pub fn (mut r BufferedReader) read(mut buf []u8) ?int { if r.end_of_stream { return none } @@ -108,7 +108,7 @@ pub fn (mut r BufferedReader) read_line() ?string { if r.end_of_stream { return none } - mut line := []byte{} + mut line := []u8{} for { if r.needs_fill() { // go fetch some new data diff --git a/vlib/io/custom_string_reading_test.v b/vlib/io/custom_string_reading_test.v index 008ecc0c61..87db85f1e4 100644 --- a/vlib/io/custom_string_reading_test.v +++ b/vlib/io/custom_string_reading_test.v @@ -10,7 +10,7 @@ fn imin(a int, b int) int { return if a < b { a } else { b } } -fn (mut s StringReader) read(mut buf []byte) ?int { +fn (mut s StringReader) read(mut buf []u8) ?int { $if debug { eprintln('>>>> StringReader.read output buf.len: $buf.len') } @@ -24,14 +24,14 @@ fn (mut s StringReader) read(mut buf []byte) ?int { return read } -fn read_from_string(text string, capacity int) []byte { +fn read_from_string(text string, capacity int) []u8 { mut str := StringReader{ text: text } mut stream := io.new_buffered_reader(reader: str, cap: capacity) // - mut buf := []byte{len: 1} - mut res := []byte{} + mut buf := []u8{len: 1} + mut res := []u8{} mut i := 0 for { z := stream.read(mut buf) or { break } @@ -50,7 +50,7 @@ pub fn test_reading_from_a_string() { assert read_from_string('ab', capacity) == [u8(`a`), `b`] assert read_from_string('abc', capacity) == [u8(`a`), `b`, `c`] assert read_from_string('abcde', capacity) == [u8(`a`), `b`, `c`, `d`, `e`] - large_string_bytes := []byte{len: 1000, init: `x`} + large_string_bytes := []u8{len: 1000, init: `x`} large_string := large_string_bytes.bytestr() assert read_from_string(large_string, capacity) == large_string_bytes } diff --git a/vlib/io/io.v b/vlib/io/io.v index 7164bd7c36..cb644093a2 100644 --- a/vlib/io/io.v +++ b/vlib/io/io.v @@ -5,7 +5,7 @@ const ( ) pub fn cp(mut src Reader, mut dst Writer) ? { - mut buf := []byte{len: io.buf_max_len} + mut buf := []u8{len: io.buf_max_len} for { len := src.read(mut buf) or { break } dst.write(buf[..len]) or { return err } diff --git a/vlib/io/io_test.v b/vlib/io/io_test.v index 682a47a861..194e61d82e 100644 --- a/vlib/io/io_test.v +++ b/vlib/io/io_test.v @@ -2,17 +2,17 @@ import io struct Buf { pub: - bytes []byte + bytes []u8 mut: i int } struct Writ { pub mut: - bytes []byte + bytes []u8 } -fn (mut b Buf) read(mut buf []byte) ?int { +fn (mut b Buf) read(mut buf []u8) ?int { if !(b.i < b.bytes.len) { return none } @@ -21,7 +21,7 @@ fn (mut b Buf) read(mut buf []byte) ?int { return n } -fn (mut w Writ) write(buf []byte) ?int { +fn (mut w Writ) write(buf []u8) ?int { if buf.len <= 0 { return none } @@ -34,7 +34,7 @@ fn test_copy() { bytes: 'abcdefghij'.repeat(10).bytes() } mut dst := Writ{ - bytes: []byte{} + bytes: []u8{} } io.cp(mut src, mut dst) or { assert false } assert dst.bytes == src.bytes diff --git a/vlib/io/multi_writer.v b/vlib/io/multi_writer.v index 837ea30608..165911131e 100644 --- a/vlib/io/multi_writer.v +++ b/vlib/io/multi_writer.v @@ -22,7 +22,7 @@ pub mut: // written. If any writer fails to write the full length an error is returned // and writing to other writers stops. If any writer returns an error the error // is returned immediately and writing to other writers stops. -pub fn (mut m MultiWriter) write(buf []byte) ?int { +pub fn (mut m MultiWriter) write(buf []u8) ?int { for mut w in m.writers { n := w.write(buf) ? if n != buf.len { diff --git a/vlib/io/multi_writer_test.v b/vlib/io/multi_writer_test.v index 2e317e8900..e62b81e40b 100644 --- a/vlib/io/multi_writer_test.v +++ b/vlib/io/multi_writer_test.v @@ -40,20 +40,20 @@ fn test_multi_writer_write_error() { struct TestWriter { pub mut: - bytes []byte + bytes []u8 } -fn (mut w TestWriter) write(buf []byte) ?int { +fn (mut w TestWriter) write(buf []u8) ?int { w.bytes << buf return buf.len } struct TestIncompleteWriter { pub mut: - bytes []byte + bytes []u8 } -fn (mut w TestIncompleteWriter) write(buf []byte) ?int { +fn (mut w TestIncompleteWriter) write(buf []u8) ?int { b := buf[..buf.len - 1] w.bytes << b return b.len @@ -61,6 +61,6 @@ fn (mut w TestIncompleteWriter) write(buf []byte) ?int { struct TestErrorWriter {} -fn (mut w TestErrorWriter) write(buf []byte) ?int { +fn (mut w TestErrorWriter) write(buf []u8) ?int { return error('error writer errored') } diff --git a/vlib/io/reader.v b/vlib/io/reader.v index e2ba17a6d5..fc729b832e 100644 --- a/vlib/io/reader.v +++ b/vlib/io/reader.v @@ -7,7 +7,7 @@ pub interface Reader { // A type that implements this should return // `none` on end of stream (EOF) instead of just returning 0 mut: - read(mut buf []byte) ?int + read(mut buf []u8) ?int } const ( @@ -25,11 +25,11 @@ mut: // read_all reads all bytes from a reader until either a 0 length read // or if read_to_end_of_stream is true then the end of the stream (`none`) -pub fn read_all(config ReadAllConfig) ?[]byte { +pub fn read_all(config ReadAllConfig) ?[]u8 { mut r := config.reader read_till_eof := config.read_to_end_of_stream - mut b := []byte{len: io.read_all_len} + mut b := []u8{len: io.read_all_len} mut read := 0 for { new_read := r.read(mut b[read..]) or { break } @@ -46,8 +46,8 @@ pub fn read_all(config ReadAllConfig) ?[]byte { // read_any reads any available bytes from a reader // (until the reader returns a read of 0 length) -pub fn read_any(mut r Reader) ?[]byte { - mut b := []byte{len: io.read_all_len} +pub fn read_any(mut r Reader) ?[]u8 { + mut b := []u8{len: io.read_all_len} mut read := 0 for { new_read := r.read(mut b[read..]) or { break } @@ -64,5 +64,5 @@ pub fn read_any(mut r Reader) ?[]byte { // RandomReader represents a stream of data that can be read from at a random location pub interface RandomReader { - read_from(pos u64, mut buf []byte) ?int + read_from(pos u64, mut buf []u8) ?int } diff --git a/vlib/io/reader_test.v b/vlib/io/reader_test.v index 7918744228..9cc7b35c24 100644 --- a/vlib/io/reader_test.v +++ b/vlib/io/reader_test.v @@ -2,12 +2,12 @@ module io struct Buf { pub: - bytes []byte + bytes []u8 mut: i int } -fn (mut b Buf) read(mut buf []byte) ?int { +fn (mut b Buf) read(mut buf []u8) ?int { if !(b.i < b.bytes.len) { return none } @@ -44,7 +44,7 @@ mut: place int } -fn (mut s StringReader) read(mut buf []byte) ?int { +fn (mut s StringReader) read(mut buf []u8) ?int { if s.place >= s.text.len { return none } diff --git a/vlib/io/readerwriter.v b/vlib/io/readerwriter.v index e6925a6ad6..1aa79b7aa2 100644 --- a/vlib/io/readerwriter.v +++ b/vlib/io/readerwriter.v @@ -14,11 +14,11 @@ mut: w Writer } -pub fn (mut r ReaderWriterImpl) read(mut buf []byte) ?int { +pub fn (mut r ReaderWriterImpl) read(mut buf []u8) ?int { return r.r.read(mut buf) } -pub fn (mut r ReaderWriterImpl) write(buf []byte) ?int { +pub fn (mut r ReaderWriterImpl) write(buf []u8) ?int { return r.w.write(buf) } diff --git a/vlib/io/writer.v b/vlib/io/writer.v index 7f70b244dc..3cda29cc53 100644 --- a/vlib/io/writer.v +++ b/vlib/io/writer.v @@ -3,11 +3,11 @@ module io // Writer represents a stream of data that can be wrote to pub interface Writer { mut: - write(buf []byte) ?int + write(buf []u8) ?int } // RandomWriter represents a stream of data that can be wrote to // at a random pos pub interface RandomWriter { - write_to(pos u64, buf []byte) ?int + write_to(pos u64, buf []u8) ?int } diff --git a/vlib/math/big/big_test.v b/vlib/math/big/big_test.v index 7edc4589dc..d60fca4d55 100644 --- a/vlib/math/big/big_test.v +++ b/vlib/math/big/big_test.v @@ -31,7 +31,7 @@ fn test_integer_from_bytes() { assert big.integer_from_bytes([u8(0x13), 0x37, 0xca, 0xfe, 0xba]).hex() == '1337cafeba' assert big.integer_from_bytes([u8(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe]).hex() == '1337cafebabe' - mut bytes := []byte{cap: 1024} + mut bytes := []u8{cap: 1024} mut expected := '' for i := 0; i < bytes.cap; i++ { bytes << u8(i) @@ -45,7 +45,7 @@ fn test_bytes() { assert result1 == [u8(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe] assert sign1 == 1 - mut bytes := []byte{cap: 1024} + mut bytes := []u8{cap: 1024} mut expected := '' for i := 0; i < bytes.cap; i++ { bytes << u8(i | 1) diff --git a/vlib/math/big/integer.v b/vlib/math/big/integer.v index e26fef1341..3602118677 100644 --- a/vlib/math/big/integer.v +++ b/vlib/math/big/integer.v @@ -108,13 +108,13 @@ pub struct IntegerConfig { // integer_from_bytes creates a new `big.Integer` from the given byte array. By default, positive integers are assumed. If you want a negative integer, use in the following manner: // `value := big.integer_from_bytes(bytes, signum: -1)` -pub fn integer_from_bytes(input []byte, config IntegerConfig) Integer { +pub fn integer_from_bytes(input []u8, config IntegerConfig) Integer { // Thank you to Miccah (@mcastorina) for this implementation and relevant unit tests. if input.len == 0 { return integer_from_int(0) } // pad input - mut padded_input := []byte{len: ((input.len + 3) & ~0x3) - input.len, cap: (input.len + 3) & ~0x3, init: 0x0} + mut padded_input := []u8{len: ((input.len + 3) & ~0x3) - input.len, cap: (input.len + 3) & ~0x3, init: 0x0} padded_input << input mut digits := []u32{len: padded_input.len / 4} // combine every 4 bytes into a u32 and insert into n.digits @@ -778,11 +778,11 @@ pub fn (a Integer) int() int { // bytes returns the a byte representation of the integer a, along with the signum int. // NOTE: The byte array returned is in big endian order. -pub fn (a Integer) bytes() ([]byte, int) { +pub fn (a Integer) bytes() ([]u8, int) { if a.signum == 0 { - return []byte{len: 0}, 0 + return []u8{len: 0}, 0 } - mut result := []byte{cap: a.digits.len * 4} + mut result := []u8{cap: a.digits.len * 4} mut mask := u32(0xff000000) mut offset := 24 mut non_zero_found := false diff --git a/vlib/math/unsigned/uint128.v b/vlib/math/unsigned/uint128.v index 7e36235229..9c2884adda 100644 --- a/vlib/math/unsigned/uint128.v +++ b/vlib/math/unsigned/uint128.v @@ -403,7 +403,7 @@ pub fn (u_ Uint128) str() string { } // put_bytes stores u in b in little-endian order -pub fn (u Uint128) put_bytes(mut b []byte) { +pub fn (u Uint128) put_bytes(mut b []u8) { binary.little_endian_put_u64(mut b, u.lo) binary.little_endian_put_u64(mut b, u.hi) } diff --git a/vlib/net/ftp/ftp.v b/vlib/net/ftp/ftp.v index 41b2cde70c..adb8a0daf8 100644 --- a/vlib/net/ftp/ftp.v +++ b/vlib/net/ftp/ftp.v @@ -42,9 +42,9 @@ mut: port int } -fn (mut dtp DTP) read() ?[]byte { - mut data := []byte{} - mut buf := []byte{len: 1024} +fn (mut dtp DTP) read() ?[]u8 { + mut data := []u8{} + mut buf := []u8{len: 1024} for { len := dtp.reader.read(mut buf) or { break } if len == 0 { @@ -227,7 +227,7 @@ pub fn (mut zftp FTP) dir() ?[]string { return dir } -pub fn (mut zftp FTP) get(file string) ?[]byte { +pub fn (mut zftp FTP) get(file string) ?[]u8 { mut dtp := zftp.pasv() or { return error('Cannot stablish data connection') } zftp.write('RETR $file') ? code, _ := zftp.read() ? diff --git a/vlib/net/http/request.v b/vlib/net/http/request.v index 8d3ced009c..064ab662df 100644 --- a/vlib/net/http/request.v +++ b/vlib/net/http/request.v @@ -182,11 +182,11 @@ pub fn parse_request(mut reader io.BufferedReader) ?Request { mut request := parse_request_head(mut reader) ? // body - mut body := []byte{} + mut body := []u8{} if length := request.header.get(.content_length) { n := length.int() if n > 0 { - body = []byte{len: n} + body = []u8{len: n} mut count := 0 for count < body.len { count += reader.read(mut body[count..]) or { break } diff --git a/vlib/net/http/request_test.v b/vlib/net/http/request_test.v index ce7b92a63e..a2838b03e5 100644 --- a/vlib/net/http/request_test.v +++ b/vlib/net/http/request_test.v @@ -8,7 +8,7 @@ mut: place int } -fn (mut s StringReader) read(mut buf []byte) ?int { +fn (mut s StringReader) read(mut buf []u8) ?int { if s.place >= s.text.len { return none } diff --git a/vlib/net/http/response.v b/vlib/net/http/response.v index e1fbfd76c3..8abd8e7b44 100644 --- a/vlib/net/http/response.v +++ b/vlib/net/http/response.v @@ -21,8 +21,8 @@ fn (mut resp Response) free() { } // Formats resp to bytes suitable for HTTP response transmission -pub fn (resp Response) bytes() []byte { - // TODO: build []byte directly; this uses two allocations +pub fn (resp Response) bytes() []u8 { + // TODO: build []u8 directly; this uses two allocations return resp.bytestr().bytes() } diff --git a/vlib/net/openssl/ssl_connection.v b/vlib/net/openssl/ssl_connection.v index f5c821a301..5582747391 100644 --- a/vlib/net/openssl/ssl_connection.v +++ b/vlib/net/openssl/ssl_connection.v @@ -179,13 +179,13 @@ pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr &byte, len int) ?int { return res } -pub fn (mut s SSLConn) read(mut buffer []byte) ?int { +pub fn (mut s SSLConn) read(mut buffer []u8) ?int { res := s.socket_read_into_ptr(&u8(buffer.data), buffer.len) ? return res } // write number of bytes to SSL connection -pub fn (mut s SSLConn) write(bytes []byte) ?int { +pub fn (mut s SSLConn) write(bytes []u8) ?int { unsafe { mut ptr_base := &u8(bytes.data) mut total_sent := 0 diff --git a/vlib/net/tcp.v b/vlib/net/tcp.v index 3f36641d05..bb21b650fa 100644 --- a/vlib/net/tcp.v +++ b/vlib/net/tcp.v @@ -84,7 +84,7 @@ pub fn (c TcpConn) read_ptr(buf_ptr &byte, len int) ?int { return none } -pub fn (c TcpConn) read(mut buf []byte) ?int { +pub fn (c TcpConn) read(mut buf []u8) ?int { return c.read_ptr(buf.data, buf.len) } @@ -132,7 +132,7 @@ pub fn (mut c TcpConn) write_ptr(b &byte, len int) ?int { } // write blocks and attempts to write all data -pub fn (mut c TcpConn) write(bytes []byte) ?int { +pub fn (mut c TcpConn) write(bytes []u8) ?int { return c.write_ptr(bytes.data, bytes.len) } diff --git a/vlib/net/tcp_simple_client_server_test.v b/vlib/net/tcp_simple_client_server_test.v index 21fa46b3b8..947b2c3359 100644 --- a/vlib/net/tcp_simple_client_server_test.v +++ b/vlib/net/tcp_simple_client_server_test.v @@ -49,7 +49,7 @@ fn test_socket() { $if debug { println('send socket: $socket.sock.handle') } - mut buf := []byte{len: 1024} + mut buf := []u8{len: 1024} nbytes := client.read(mut buf) or { assert false return @@ -71,7 +71,7 @@ fn test_socket_write_and_read() { } message1 := 'a message 1' socket.write_string(message1) or { assert false } - mut rbuf := []byte{len: message1.len} + mut rbuf := []u8{len: message1.len} client.read(mut rbuf) or { assert false return diff --git a/vlib/net/tcp_test.v b/vlib/net/tcp_test.v index c549a3c93c..12e6f2b67b 100644 --- a/vlib/net/tcp_test.v +++ b/vlib/net/tcp_test.v @@ -8,7 +8,7 @@ const ( fn handle_conn(mut c net.TcpConn) { for { - mut buf := []byte{len: 100, init: 0} + mut buf := []u8{len: 100, init: 0} read := c.read(mut buf) or { println('Server: connection dropped') return @@ -40,7 +40,7 @@ fn echo(address string) ? { data := 'Hello from vlib/net!' c.write_string(data) ? - mut buf := []byte{len: 4096} + mut buf := []u8{len: 4096} read := c.read(mut buf) ? assert read == data.len for i := 0; i < read; i++ { diff --git a/vlib/net/udp.v b/vlib/net/udp.v index 5c10444354..d5435ca982 100644 --- a/vlib/net/udp.v +++ b/vlib/net/udp.v @@ -63,7 +63,7 @@ pub fn (mut c UdpConn) write_ptr(b &byte, len int) ?int { return c.write_to_ptr(remote, b, len) } -pub fn (mut c UdpConn) write(buf []byte) ?int { +pub fn (mut c UdpConn) write(buf []u8) ?int { return c.write_ptr(buf.data, buf.len) } @@ -87,7 +87,7 @@ pub fn (mut c UdpConn) write_to_ptr(addr Addr, b &byte, len int) ?int { } // write_to blocks and writes the buf to the remote addr specified -pub fn (mut c UdpConn) write_to(addr Addr, buf []byte) ?int { +pub fn (mut c UdpConn) write_to(addr Addr, buf []u8) ?int { return c.write_to_ptr(addr, buf.data, buf.len) } @@ -97,7 +97,7 @@ pub fn (mut c UdpConn) write_to_string(addr Addr, s string) ?int { } // read reads from the socket into buf up to buf.len returning the number of bytes read -pub fn (mut c UdpConn) read(mut buf []byte) ?(int, Addr) { +pub fn (mut c UdpConn) read(mut buf []u8) ?(int, Addr) { mut addr := Addr{ addr: AddrData{ Ip6: Ip6{} diff --git a/vlib/net/udp_test.v b/vlib/net/udp_test.v index fc1a193a0d..4ca82d5c8a 100644 --- a/vlib/net/udp_test.v +++ b/vlib/net/udp_test.v @@ -5,7 +5,7 @@ fn echo_server(mut c net.UdpConn) { mut count := 0 for { eprintln('> echo_server loop count: $count') - mut buf := []byte{len: 100} + mut buf := []u8{len: 100} read, addr := c.read(mut buf) or { continue } eprintln('Server got addr $addr, read: $read | buf: $buf') c.write_to(addr, buf[..read]) or { @@ -33,7 +33,7 @@ fn echo() ? { c.write_string(data) or { panic('could not write_string: $err') } - mut buf := []byte{len: 100, init: 0} + mut buf := []u8{len: 100, init: 0} read, addr := c.read(mut buf) or { panic('could not read: $err') } assert read == data.len diff --git a/vlib/net/unix/stream_nix.v b/vlib/net/unix/stream_nix.v index 5ceddcefcb..6448843b68 100644 --- a/vlib/net/unix/stream_nix.v +++ b/vlib/net/unix/stream_nix.v @@ -199,7 +199,7 @@ pub fn (mut c StreamConn) write_ptr(b &byte, len int) ?int { } // write blocks and attempts to write all data -pub fn (mut c StreamConn) write(bytes []byte) ?int { +pub fn (mut c StreamConn) write(bytes []u8) ?int { return c.write_ptr(bytes.data, bytes.len) } @@ -230,7 +230,7 @@ pub fn (mut c StreamConn) read_ptr(buf_ptr &byte, len int) ?int { return net.socket_error(code) } -pub fn (mut c StreamConn) read(mut buf []byte) ?int { +pub fn (mut c StreamConn) read(mut buf []u8) ?int { return c.read_ptr(buf.data, buf.len) } diff --git a/vlib/net/unix/unix_test.v b/vlib/net/unix/unix_test.v index cabcd521d3..4d1cfd018e 100644 --- a/vlib/net/unix/unix_test.v +++ b/vlib/net/unix/unix_test.v @@ -5,7 +5,7 @@ const test_port = os.join_path(os.temp_dir(), 'unix_domain_socket') fn handle_conn(mut c unix.StreamConn) { for { - mut buf := []byte{len: 100, init: 0} + mut buf := []u8{len: 100, init: 0} read := c.read(mut buf) or { println('Server: connection dropped') return @@ -31,7 +31,7 @@ fn echo() ? { } data := 'Hello from vlib/net!' c.write_string(data) ? - mut buf := []byte{len: 4096} + mut buf := []u8{len: 4096} read := c.read(mut buf) ? assert read == data.len for i := 0; i < read; i++ { diff --git a/vlib/net/unix/use_net_and_net_unix_together_test.v b/vlib/net/unix/use_net_and_net_unix_together_test.v index 32458f7870..6f288966a8 100644 --- a/vlib/net/unix/use_net_and_net_unix_together_test.v +++ b/vlib/net/unix/use_net_and_net_unix_together_test.v @@ -21,7 +21,7 @@ fn test_that_net_and_net_unix_can_be_imported_together_without_conflicts() ? { // data := 'Hello from vlib/net!' c.write_string(data) ? - mut buf := []byte{len: 100} + mut buf := []u8{len: 100} assert c.read(mut buf) ? == data.len eprintln('< client read back buf: |${buf[0..data.len].bytestr()}|') assert buf[0..data.len] == data.bytes() @@ -33,7 +33,7 @@ fn perror(s string) ? { fn handle_conn(mut c unix.StreamConn) ? { for { - mut buf := []byte{len: 100, init: 0} + mut buf := []u8{len: 100, init: 0} read := c.read(mut buf) or { return perror('Server: connection dropped') } eprintln('> server read ${read:3}, buf: |$buf.bytestr()|') c.write(buf[..read]) or { return perror('Server: connection dropped') } diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index 7b8adb5cbe..bd91e4f3da 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -272,7 +272,7 @@ fn escape(s string, mode EncodingMode) string { return s } required := s.len + 2 * hex_count - mut t := []byte{len: required} + mut t := []u8{len: required} if hex_count == 0 { copy(mut t, s.bytes()) for i in 0 .. s.len { diff --git a/vlib/net/websocket/io.v b/vlib/net/websocket/io.v index 3d0f5fc832..cd9b8dcff0 100644 --- a/vlib/net/websocket/io.v +++ b/vlib/net/websocket/io.v @@ -4,7 +4,7 @@ import net import time // socket_read reads from socket into the provided buffer -fn (mut ws Client) socket_read(mut buffer []byte) ?int { +fn (mut ws Client) socket_read(mut buffer []u8) ?int { lock { if ws.state in [.closed, .closing] || ws.conn.sock.handle <= 1 { return error('socket_read: trying to read a closed socket') @@ -52,7 +52,7 @@ fn (mut ws Client) socket_read_ptr(buf_ptr &byte, len int) ?int { } // socket_write writes the provided byte array to the socket -fn (mut ws Client) socket_write(bytes []byte) ?int { +fn (mut ws Client) socket_write(bytes []u8) ?int { lock { if ws.state == .closed || ws.conn.sock.handle <= 1 { ws.debug_log('socket_write: Socket allready closed') diff --git a/vlib/net/websocket/message.v b/vlib/net/websocket/message.v index 1e45d04e47..f19ea06fa5 100644 --- a/vlib/net/websocket/message.v +++ b/vlib/net/websocket/message.v @@ -11,7 +11,7 @@ const ( // Fragment represents a websocket data fragment struct Fragment { - data []byte // included data payload data in a fragment + data []u8 // included data payload data in a fragment opcode OPCode // interpretation of the payload data } @@ -81,11 +81,11 @@ fn is_data_frame(opcode OPCode) bool { } // read_payload reads the message payload from the socket -fn (mut ws Client) read_payload(frame &Frame) ?[]byte { +fn (mut ws Client) read_payload(frame &Frame) ?[]u8 { if frame.payload_len == 0 { - return []byte{} + return []u8{} } - mut buffer := []byte{cap: frame.payload_len} + mut buffer := []u8{cap: frame.payload_len} mut read_buf := [1]byte{} mut bytes_read := 0 for bytes_read < frame.payload_len { @@ -109,7 +109,7 @@ fn (mut ws Client) read_payload(frame &Frame) ?[]byte { // validate_utf_8 validates payload for valid utf8 encoding // - Future implementation needs to support fail fast utf errors for strict autobahn conformance -fn (mut ws Client) validate_utf_8(opcode OPCode, payload []byte) ? { +fn (mut ws Client) validate_utf_8(opcode OPCode, payload []u8) ? { if opcode in [.text_frame, .close] && !utf8.validate(payload.data, payload.len) { ws.logger.error('malformed utf8 payload, payload len: ($payload.len)') ws.send_error_event('Recieved malformed utf8.') @@ -181,7 +181,7 @@ pub fn (mut ws Client) read_next_message() ?Message { } // payload_from_fragments returs the whole paylaod from fragmented message -fn (ws Client) payload_from_fragments(fin_payload []byte) ?[]byte { +fn (ws Client) payload_from_fragments(fin_payload []u8) ?[]u8 { mut total_size := 0 for f in ws.fragments { if f.data.len > 0 { @@ -190,9 +190,9 @@ fn (ws Client) payload_from_fragments(fin_payload []byte) ?[]byte { } total_size += fin_payload.len if total_size == 0 { - return []byte{} + return []u8{} } - mut total_buffer := []byte{cap: total_size} + mut total_buffer := []u8{cap: total_size} for f in ws.fragments { if f.data.len > 0 { total_buffer << f.data @@ -288,7 +288,7 @@ pub fn (mut ws Client) parse_frame_header() ?Frame { } // unmask_sequence unmask any given sequence -fn (f Frame) unmask_sequence(mut buffer []byte) { +fn (f Frame) unmask_sequence(mut buffer []u8) { for i in 0 .. buffer.len { buffer[i] ^= f.masking_key[i % 4] & 0xff } diff --git a/vlib/net/websocket/utils.v b/vlib/net/websocket/utils.v index a7edaa148d..1149a34b73 100644 --- a/vlib/net/websocket/utils.v +++ b/vlib/net/websocket/utils.v @@ -5,8 +5,8 @@ import crypto.sha1 import encoding.base64 // htonl64 converts payload length to header bits -fn htonl64(payload_len u64) []byte { - mut ret := []byte{len: 8} +fn htonl64(payload_len u64) []u8 { + mut ret := []u8{len: 8} ret[0] = u8(((payload_len & (u64(0xff) << 56)) >> 56) & 0xff) ret[1] = u8(((payload_len & (u64(0xff) << 48)) >> 48) & 0xff) ret[2] = u8(((payload_len & (u64(0xff) << 40)) >> 40) & 0xff) @@ -19,9 +19,9 @@ fn htonl64(payload_len u64) []byte { } // create_masking_key returs a new masking key to use when masking websocket messages -fn create_masking_key() []byte { +fn create_masking_key() []u8 { mask_bit := rand.u8() - buf := []byte{len: 4, init: `0`} + buf := []u8{len: 4, init: `0`} unsafe { C.memcpy(buf.data, &mask_bit, 4) } return buf } @@ -45,7 +45,7 @@ fn create_key_challenge_response(seckey string) ?string { // get_nonce creates a randomized array used in handshake process fn get_nonce(nonce_size int) string { - mut nonce := []byte{len: nonce_size, cap: nonce_size} + mut nonce := []u8{len: nonce_size, cap: nonce_size} alphanum := '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz' for i in 0 .. nonce_size { nonce[i] = alphanum[rand.intn(alphanum.len) or { 0 }] diff --git a/vlib/net/websocket/websocket_client.v b/vlib/net/websocket/websocket_client.v index ceee88b01d..747020a4f2 100644 --- a/vlib/net/websocket/websocket_client.v +++ b/vlib/net/websocket/websocket_client.v @@ -12,7 +12,7 @@ import log import rand const ( - empty_bytearr = []byte{} // used as empty response to avoid allocation + empty_bytearr = []u8{} // used as empty response to avoid allocation ) // Client represents websocket client @@ -60,7 +60,7 @@ pub enum State { pub struct Message { pub: opcode OPCode // websocket frame type of this message - payload []byte // payload of the message + payload []u8 // payload of the message } // OPCode represents the supported websocket frame types @@ -182,7 +182,7 @@ pub fn (mut ws Client) listen() ? { ws.close(1002, 'invalid close code: $code') ? return error('invalid close code: $code') } - reason := if msg.payload.len > 2 { msg.payload[2..] } else { []byte{} } + reason := if msg.payload.len > 2 { msg.payload[2..] } else { []u8{} } if reason.len > 0 { ws.validate_utf_8(.close, reason) ? } @@ -240,7 +240,7 @@ pub fn (mut ws Client) write_ptr(bytes &byte, payload_len int, code OPCode) ?int if !ws.is_server { header_len += 4 } - mut header := []byte{len: header_len, init: `0`} // [`0`].repeat(header_len) + mut header := []u8{len: header_len, init: `0`} // [`0`].repeat(header_len) header[0] = u8(int(code)) | 0x80 masking_key := create_masking_key() if ws.is_server { @@ -284,7 +284,7 @@ pub fn (mut ws Client) write_ptr(bytes &byte, payload_len int, code OPCode) ?int } } len := header.len + payload_len - mut frame_buf := []byte{len: len} + mut frame_buf := []u8{len: len} unsafe { C.memcpy(&frame_buf[0], &u8(header.data), header.len) if payload_len > 0 { @@ -306,7 +306,7 @@ pub fn (mut ws Client) write_ptr(bytes &byte, payload_len int, code OPCode) ?int } // write writes a byte array with a websocket messagetype to socket -pub fn (mut ws Client) write(bytes []byte, code OPCode) ?int { +pub fn (mut ws Client) write(bytes []u8, code OPCode) ?int { return ws.write_ptr(&u8(bytes.data), bytes.len, code) } @@ -332,7 +332,7 @@ pub fn (mut ws Client) close(code int, message string) ? { if code > 0 { code_ := C.htons(code) message_len := message.len + 2 - mut close_frame := []byte{len: message_len} + mut close_frame := []u8{len: message_len} close_frame[0] = u8(code_ & 0xFF) close_frame[1] = u8(code_ >> 8) // code32 = (close_frame[0] << 8) + close_frame[1] @@ -348,14 +348,14 @@ pub fn (mut ws Client) close(code int, message string) ? { } // send_control_frame sends a control frame to the server -fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []byte) ? { +fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []u8) ? { ws.debug_log('send control frame $code, frame_type: $frame_typ') if ws.state !in [.open, .closing] && ws.conn.sock.handle > 1 { return error('socket is not connected') } header_len := if ws.is_server { 2 } else { 6 } frame_len := header_len + payload.len - mut control_frame := []byte{len: frame_len} + mut control_frame := []u8{len: frame_len} mut masking_key := if !ws.is_server { create_masking_key() } else { websocket.empty_bytearr } defer { unsafe { @@ -378,7 +378,7 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b if code == .close { if payload.len >= 2 { if !ws.is_server { - mut parsed_payload := []byte{len: payload.len + 1} + mut parsed_payload := []u8{len: payload.len + 1} unsafe { C.memcpy(parsed_payload.data, &payload[0], payload.len) } parsed_payload[payload.len] = `\0` for i in 0 .. payload.len { diff --git a/vlib/os/file.c.v b/vlib/os/file.c.v index 8c06503a1a..45eedc7d40 100644 --- a/vlib/os/file.c.v +++ b/vlib/os/file.c.v @@ -161,7 +161,7 @@ pub fn stderr() File { } // read implements the Reader interface. -pub fn (f &File) read(mut buf []byte) ?int { +pub fn (f &File) read(mut buf []u8) ?int { if buf.len == 0 { return 0 } @@ -172,7 +172,7 @@ pub fn (f &File) read(mut buf []byte) ?int { // **************************** Write ops *************************** // write implements the Writer interface. // It returns how many bytes were actually written. -pub fn (mut f File) write(buf []byte) ?int { +pub fn (mut f File) write(buf []u8) ?int { if !f.is_opened { return error_file_not_opened() } @@ -228,7 +228,7 @@ pub fn (mut f File) write_string(s string) ?int { // write_to implements the RandomWriter interface. // It returns how many bytes were actually written. // It resets the seek position to the end of the file. -pub fn (mut f File) write_to(pos u64, buf []byte) ?int { +pub fn (mut f File) write_to(pos u64, buf []u8) ?int { if !f.is_opened { return error_file_not_opened() } @@ -351,13 +351,13 @@ fn fread(ptr voidptr, item_size int, items int, stream &C.FILE) ?int { // read_bytes reads bytes from the beginning of the file. // Utility method, same as .read_bytes_at(size, 0). -pub fn (f &File) read_bytes(size int) []byte { +pub fn (f &File) read_bytes(size int) []u8 { return f.read_bytes_at(size, 0) } // read_bytes_at reads `size` bytes at the given position in the file. -pub fn (f &File) read_bytes_at(size int, pos u64) []byte { - mut arr := []byte{len: size} +pub fn (f &File) read_bytes_at(size int, pos u64) []u8 { + mut arr := []u8{len: size} nreadbytes := f.read_bytes_into(pos, mut arr) or { // return err return [] @@ -368,7 +368,7 @@ pub fn (f &File) read_bytes_at(size int, pos u64) []byte { // read_bytes_into_newline reads from the beginning of the file into the provided buffer. // Each consecutive call on the same file continues reading where it previously ended. // A read call is either stopped, if the buffer is full, a newline was read or EOF. -pub fn (f &File) read_bytes_into_newline(mut buf []byte) ?int { +pub fn (f &File) read_bytes_into_newline(mut buf []u8) ?int { if buf.len == 0 { return error(@FN + ': `buf.len` == 0') } @@ -407,7 +407,7 @@ pub fn (f &File) read_bytes_into_newline(mut buf []byte) ?int { // read_bytes_into fills `buf` with bytes at the given position in the file. // `buf` *must* have length greater than zero. // Returns the number of read bytes, or an error. -pub fn (f &File) read_bytes_into(pos u64, mut buf []byte) ?int { +pub fn (f &File) read_bytes_into(pos u64, mut buf []u8) ?int { if buf.len == 0 { return error(@FN + ': `buf.len` == 0') } @@ -441,7 +441,7 @@ pub fn (f &File) read_bytes_into(pos u64, mut buf []byte) ?int { } // read_from implements the RandomReader interface. -pub fn (f &File) read_from(pos u64, mut buf []byte) ?int { +pub fn (f &File) read_from(pos u64, mut buf []u8) ?int { if buf.len == 0 { return 0 } diff --git a/vlib/os/file.js.v b/vlib/os/file.js.v index 273727b51a..be9433c678 100644 --- a/vlib/os/file.js.v +++ b/vlib/os/file.js.v @@ -78,7 +78,7 @@ pub fn stderr() File { } } -pub fn (f &File) read(mut buf []byte) ?int { +pub fn (f &File) read(mut buf []u8) ?int { if buf.len == 0 { return 0 } @@ -93,7 +93,7 @@ pub fn (f &File) read(mut buf []byte) ?int { return nbytes } -pub fn (mut f File) write(buf []byte) ?int { +pub fn (mut f File) write(buf []u8) ?int { if !f.is_opened { return error('file is not opened') } @@ -113,7 +113,7 @@ pub fn (mut f File) writeln(s string) ?int { return nbytes } -pub fn (mut f File) write_to(pos u64, buf []byte) ?int { +pub fn (mut f File) write_to(pos u64, buf []u8) ?int { if !f.is_opened { return error('file is not opened') } diff --git a/vlib/os/file_test.v b/vlib/os/file_test.v index 9663778710..ccd529fe47 100644 --- a/vlib/os/file_test.v +++ b/vlib/os/file_test.v @@ -69,7 +69,7 @@ fn test_read_bytes_into_newline_text() ? { f.close() f = os.open_file(tfile, 'r') ? - mut buf := []byte{len: 8} + mut buf := []u8{len: 8} n0 := f.read_bytes_into_newline(mut buf) ? assert n0 == 8 @@ -91,7 +91,7 @@ fn test_read_bytes_into_newline_text() ? { // appears in that stream and an EOF occurs before the buffer is full. fn test_read_bytes_into_newline_binary() ? { os.rm(tfile) or {} // FIXME This is a workaround for macos, because the file isn't truncated when open with 'w' - mut bw := []byte{len: 15} + mut bw := []u8{len: 15} bw[9] = 0xff bw[12] = 10 // newline @@ -104,7 +104,7 @@ fn test_read_bytes_into_newline_binary() ? { f.close() f = os.open_file(tfile, 'r') ? - mut buf := []byte{len: 10} + mut buf := []u8{len: 10} n0 := f.read_bytes_into_newline(mut buf) ? assert n0 == 10 @@ -126,12 +126,12 @@ fn test_read_bytes_into_newline_binary() ? { // containing data. fn test_read_eof_last_read_partial_buffer_fill() ? { mut f := os.open_file(tfile, 'w') ? - bw := []byte{len: 199, init: 5} + bw := []u8{len: 199, init: 5} f.write(bw) ? f.close() f = os.open_file(tfile, 'r') ? - mut br := []byte{len: 100} + mut br := []u8{len: 100} // Read first 100 bytes of 199 byte file, should fill buffer with no error. n0 := f.read(mut br) ? assert n0 == 100 @@ -158,12 +158,12 @@ fn test_read_eof_last_read_partial_buffer_fill() ? { // fread that returns no data. fn test_read_eof_last_read_full_buffer_fill() ? { mut f := os.open_file(tfile, 'w') ? - bw := []byte{len: 200, init: 5} + bw := []u8{len: 200, init: 5} f.write(bw) ? f.close() f = os.open_file(tfile, 'r') ? - mut br := []byte{len: 100} + mut br := []u8{len: 100} // Read first 100 bytes of 200 byte file, should fill buffer with no error. n0 := f.read(mut br) ? assert n0 == 100 diff --git a/vlib/os/os_android.c.v b/vlib/os/os_android.c.v index 8a46d18ddd..d4588d2270 100644 --- a/vlib/os/os_android.c.v +++ b/vlib/os/os_android.c.v @@ -18,7 +18,7 @@ fn C.AAsset_read(&C.AAsset, voidptr, int) int fn C.AAsset_close(&C.AAsset) -pub fn read_apk_asset(file string) ?[]byte { +pub fn read_apk_asset(file string) ?[]u8 { $if apk { act := &C.ANativeActivity(C.sapp_android_get_native_activity()) if isnil(act) { @@ -29,7 +29,7 @@ pub fn read_apk_asset(file string) ?[]byte { return error('File `$file` not found') } len := C.AAsset_getLength(asset) - buf := []byte{len: len} + buf := []u8{len: len} for { if C.AAsset_read(asset, buf.data, len) > 0 { break diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index ff62ae1a9c..862cc4e45a 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -169,7 +169,7 @@ fn test_write_and_read_bytes() { // eprintln('payload: $payload') assert rbytes == payload // check that trying to read data from EOF doesn't error and returns 0 - mut a := []byte{len: 5} + mut a := []u8{len: 5} nread := file_read.read_bytes_into(5, mut a) or { n := if err is none { int(0) @@ -681,7 +681,7 @@ struct IntPoint { fn test_write_file_array_bytes() { fpath := './abytes.bin' - mut arr := []byte{len: maxn} + mut arr := []u8{len: maxn} for i in 0 .. maxn { arr[i] = 65 + u8(i) } diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index fb20968af7..5f3df7220a 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -74,7 +74,7 @@ mut: dw_flags u32 w_show_window u16 cb_reserved2 u16 - lp_reserved2 &byte + lp_reserved2 &u8 h_std_input voidptr h_std_output voidptr h_std_error voidptr @@ -94,7 +94,7 @@ struct C._utimbuf { fn C._utime(&char, voidptr) int -fn init_os_args_wide(argc int, argv &&byte) []string { +fn init_os_args_wide(argc int, argv &&u8) []string { mut args_ := []string{len: argc} for i in 0 .. argc { args_[i] = unsafe { string_from_wide(&u16(argv[i])) } @@ -352,7 +352,7 @@ pub fn execute(cmd string) Result { } C.CloseHandle(child_stdin) C.CloseHandle(child_stdout_write) - buf := [4096]byte{} + buf := [4096]u8{} mut bytes_read := u32(0) mut read_data := strings.new_builder(1024) for { diff --git a/vlib/pg/pg.v b/vlib/pg/pg.v index f0f016443e..0f09b644ca 100644 --- a/vlib/pg/pg.v +++ b/vlib/pg/pg.v @@ -230,7 +230,7 @@ pub fn (db DB) copy_expert(query string, mut file io.ReaderWriter) ?int { } if status == C.PGRES_COPY_IN { - mut buf := []byte{len: 4 * 1024} + mut buf := []u8{len: 4 * 1024} for { n := file.read(mut buf) or { msg := 'pg copy error: Failed to read from input' @@ -257,7 +257,7 @@ pub fn (db DB) copy_expert(query string, mut file io.ReaderWriter) ?int { address := &u8(0) n_bytes := C.PQgetCopyData(db.conn, &address, 0) if n_bytes > 0 { - mut local_buf := []byte{len: n_bytes} + mut local_buf := []u8{len: n_bytes} unsafe { C.memcpy(&u8(local_buf.data), address, n_bytes) } file.write(local_buf) or { C.PQfreemem(address) diff --git a/vlib/rand/rand.c.v b/vlib/rand/rand.c.v index 572ad90f89..0ca2c6c3d8 100644 --- a/vlib/rand/rand.c.v +++ b/vlib/rand/rand.c.v @@ -122,7 +122,7 @@ fn init() { C.atexit(deinit) } -fn read_32(mut rng PRNG, mut buf []byte) { +fn read_32(mut rng PRNG, mut buf []u8) { p32 := unsafe { &u32(buf.data) } u32s := buf.len / 4 for i in 0 .. u32s { @@ -135,7 +135,7 @@ fn read_32(mut rng PRNG, mut buf []byte) { } } -fn read_64(mut rng PRNG, mut buf []byte) { +fn read_64(mut rng PRNG, mut buf []u8) { p64 := unsafe { &u64(buf.data) } u64s := buf.len / 8 for i in 0 .. u64s { @@ -148,7 +148,7 @@ fn read_64(mut rng PRNG, mut buf []byte) { } } -fn read_internal(mut rng PRNG, mut buf []byte) { +fn read_internal(mut rng PRNG, mut buf []u8) { match rng.block_size() { 32 { read_32(mut rng, mut buf) diff --git a/vlib/rand/rand.js.v b/vlib/rand/rand.js.v index c54d3d02dc..7fe4533511 100644 --- a/vlib/rand/rand.js.v +++ b/vlib/rand/rand.js.v @@ -21,7 +21,7 @@ const ( ) fn internal_ulid_at_millisecond(mut rng PRNG, unix_time_milli u64) string { - mut buf := []byte{cap: 27} + mut buf := []u8{cap: 27} mut t := unix_time_milli mut i := 9 for i >= 0 { @@ -53,7 +53,7 @@ fn internal_ulid_at_millisecond(mut rng PRNG, unix_time_milli u64) string { return res } -fn read_internal(mut rng PRNG, mut buf []byte) { +fn read_internal(mut rng PRNG, mut buf []u8) { for i in 0 .. buf.len { buf[i] = rng.u8() } diff --git a/vlib/rand/rand.v b/vlib/rand/rand.v index 6fd36d17b1..0441815a2a 100644 --- a/vlib/rand/rand.v +++ b/vlib/rand/rand.v @@ -26,19 +26,19 @@ mut: // bytes returns a buffer of `bytes_needed` random bytes [inline] -pub fn (mut rng PRNG) bytes(bytes_needed int) ?[]byte { +pub fn (mut rng PRNG) bytes(bytes_needed int) ?[]u8 { if bytes_needed < 0 { return error('can not read < 0 random bytes') } - mut buffer := []byte{len: bytes_needed} + mut buffer := []u8{len: bytes_needed} read_internal(mut rng, mut buffer) return buffer } // read fills in `buf` with a maximum of `buf.len` random bytes -pub fn (mut rng PRNG) read(mut buf []byte) { +pub fn (mut rng PRNG) read(mut buf []u8) { read_internal(mut rng, mut buf) } @@ -490,12 +490,12 @@ pub fn f64_in_range(min f64, max f64) ?f64 { } // bytes returns a buffer of `bytes_needed` random bytes -pub fn bytes(bytes_needed int) ?[]byte { +pub fn bytes(bytes_needed int) ?[]u8 { return default_rng.bytes(bytes_needed) } // read fills in `buf` a maximum of `buf.len` random bytes -pub fn read(mut buf []byte) { +pub fn read(mut buf []u8) { read_internal(mut default_rng, mut buf) } diff --git a/vlib/rand/random_bytes_test.v b/vlib/rand/random_bytes_test.v index b9a9f6bbc4..80e7f52dfb 100644 --- a/vlib/rand/random_bytes_test.v +++ b/vlib/rand/random_bytes_test.v @@ -45,7 +45,7 @@ fn test_prng_rand_bytes() ? { fn test_rand_read() ? { max := 50 - mut a := []byte{len: max} + mut a := []u8{len: max} mut differences := 0 for j in 1 .. max { start := '00'.repeat(j) @@ -74,7 +74,7 @@ fn test_rand_read() ? { fn test_prng_rand_read() ? { max := 50 - mut a := []byte{len: max} + mut a := []u8{len: max} mut differences := 0 mut rng := rand.get_current_rng() for j in 1 .. max { diff --git a/vlib/rand/random_numbers_test.v b/vlib/rand/random_numbers_test.v index 3f0ce1d791..b823c47f33 100644 --- a/vlib/rand/random_numbers_test.v +++ b/vlib/rand/random_numbers_test.v @@ -180,7 +180,7 @@ fn test_rand_f64_in_range() { } fn test_rand_u8() { - mut all := []byte{} + mut all := []u8{} for _ in 0 .. 256 { x := rand.u8() assert x >= 0 diff --git a/vlib/regex/regex.v b/vlib/regex/regex.v index 4bc73fd3a9..ae5ff2fc18 100644 --- a/vlib/regex/regex.v +++ b/vlib/regex/regex.v @@ -474,7 +474,7 @@ enum CharClass_parse_state { } fn (re RE) get_char_class(pc int) string { - buf := []byte{len: (re.cc.len)} + buf := []u8{len: (re.cc.len)} mut buf_ptr := unsafe { &u8(&buf) } mut cc_i := re.prog[pc].cc_index diff --git a/vlib/strconv/f64_str.js.v b/vlib/strconv/f64_str.js.v index 538d9ba95c..b018cf2558 100644 --- a/vlib/strconv/f64_str.js.v +++ b/vlib/strconv/f64_str.js.v @@ -16,7 +16,7 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string { fw_zeros = pad_digit - out_len } - mut buf := []byte{len: (out_len + 6 + 1 + 1 + fw_zeros)} // sign + mant_len + . + e + e_sign + exp_len(2) + \0} + mut buf := []u8{len: (out_len + 6 + 1 + 1 + fw_zeros)} // sign + mant_len + . + e + e_sign + exp_len(2) + \0} mut i := 0 if neg { diff --git a/vlib/strconv/format_mem.c.v b/vlib/strconv/format_mem.c.v index e08b7f4ad5..ea09b02027 100644 --- a/vlib/strconv/format_mem.c.v +++ b/vlib/strconv/format_mem.c.v @@ -208,7 +208,7 @@ pub fn f64_to_str_lnd1(f f64, dec_digit int) string { } // allocate exp+32 chars for the return string - // mut res := []byte{len:exp+32,init:`0`} + // mut res := []u8{len:exp+32,init:`0`} mut res := []u8{len: exp + 32, init: 0} mut r_i := 0 // result string buffer index diff --git a/vlib/strings/builder.c.v b/vlib/strings/builder.c.v index 1224728c2e..aa5f3146c0 100644 --- a/vlib/strings/builder.c.v +++ b/vlib/strings/builder.c.v @@ -7,11 +7,11 @@ module strings // dynamically growing buffer, then use the resulting large string. Using // a string builder is much better for performance/memory usage than doing // constantly string concatenation. -pub type Builder = []byte +pub type Builder = []u8 // new_builder returns a new string builder, with an initial capacity of `initial_size` pub fn new_builder(initial_size int) Builder { - mut res := Builder([]byte{cap: initial_size}) + mut res := Builder([]u8{cap: initial_size}) unsafe { res.flags.set(.noslices) } return res } @@ -61,7 +61,7 @@ pub fn (mut b Builder) write_u8(data byte) { } // write implements the Writer interface -pub fn (mut b Builder) write(data []byte) ?int { +pub fn (mut b Builder) write(data []u8) ?int { if data.len == 0 { return 0 } diff --git a/vlib/strings/builder.js.v b/vlib/strings/builder.js.v index e1d48a4f97..bea3db6890 100644 --- a/vlib/strings/builder.js.v +++ b/vlib/strings/builder.js.v @@ -6,7 +6,7 @@ module strings /* pub struct Builder { mut: - buf []byte + buf []u8 pub mut: len int initial_size int = 1 diff --git a/vlib/szip/szip.v b/vlib/szip/szip.v index 39b556b5cf..9e52fbe147 100644 --- a/vlib/szip/szip.v +++ b/vlib/szip/szip.v @@ -172,7 +172,7 @@ pub fn (mut zentry Zip) crc32() u32 { } // write_entry compresses an input buffer for the current zip entry. -pub fn (mut zentry Zip) write_entry(data []byte) ? { +pub fn (mut zentry Zip) write_entry(data []u8) ? { if int(data[0] & 0xff) == -1 { return error('szip: cannot write entry') } diff --git a/vlib/term/ui/input.v b/vlib/term/ui/input.v index 27544b10c5..c5e7b7d636 100644 --- a/vlib/term/ui/input.v +++ b/vlib/term/ui/input.v @@ -172,7 +172,7 @@ pub struct Context { pub: cfg Config // adsasdas mut: - print_buf []byte + print_buf []u8 paused bool enable_su bool enable_rgb bool diff --git a/vlib/term/ui/input_nix.c.v b/vlib/term/ui/input_nix.c.v index 5628c202c8..1ce0460f29 100644 --- a/vlib/term/ui/input_nix.c.v +++ b/vlib/term/ui/input_nix.c.v @@ -5,7 +5,7 @@ module ui struct ExtraContext { mut: - read_buf []byte + read_buf []u8 // read_all_bytes causes all the raw bytes to be read as one event unit. // This is cruicial for UTF-8 support since Unicode codepoints can span several bytes. read_all_bytes bool = true @@ -17,7 +17,7 @@ pub fn init(cfg Config) &Context { mut ctx := &Context{ cfg: cfg } - ctx.read_buf = []byte{cap: cfg.buffer_size} + ctx.read_buf = []u8{cap: cfg.buffer_size} // lmao unsafe { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 4dbecd620f..f817de85d0 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2947,8 +2947,8 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { c.error('cannot cast type `$ft` to string, use `x.str()` instead.', node.pos) } else if final_from_sym.kind == .array { snexpr := node.expr.str() - if final_from_sym.name == '[]byte' { - c.error('cannot cast []byte to string, use `${snexpr}.bytestr()` or `${snexpr}.str()` instead.', + if final_from_sym.name == '[]u8' { + c.error('cannot cast []u8 to string, use `${snexpr}.bytestr()` or `${snexpr}.str()` instead.', node.pos) } else { first_elem_idx := '[0]' diff --git a/vlib/v/embed_file/decoder.v b/vlib/v/embed_file/decoder.v index 99b296e53d..f79c2a1f63 100644 --- a/vlib/v/embed_file/decoder.v +++ b/vlib/v/embed_file/decoder.v @@ -2,7 +2,7 @@ module embed_file interface Decoder { - decompress([]byte) ?[]byte + decompress([]u8) ?[]u8 } struct EmbedFileDecoders { diff --git a/vlib/v/embed_file/embed_file.v b/vlib/v/embed_file/embed_file.v index fb4401d3e9..2c8110d826 100644 --- a/vlib/v/embed_file/embed_file.v +++ b/vlib/v/embed_file/embed_file.v @@ -50,7 +50,7 @@ pub fn (original &EmbedFileData) to_string() string { } } -pub fn (original &EmbedFileData) to_bytes() []byte { +pub fn (original &EmbedFileData) to_bytes() []u8 { unsafe { mut ed := &EmbedFileData(original) the_copy := memdup(ed.data(), ed.len) diff --git a/vlib/v/gen/js/sourcemap/source_map.v b/vlib/v/gen/js/sourcemap/source_map.v index bf864e13ae..1556905b44 100644 --- a/vlib/v/gen/js/sourcemap/source_map.v +++ b/vlib/v/gen/js/sourcemap/source_map.v @@ -24,7 +24,7 @@ pub mut: struct StringWriter { pub mut: - bytes []byte + bytes []u8 } pub fn new_sourcemap(file string, source_root string, sources_content_inline bool) SourceMap { @@ -129,7 +129,7 @@ pub fn (mut sm SourceMap) to_json() SourceMapJson { return source_map_json } -fn (mut w StringWriter) write(buf []byte) ?int { +fn (mut w StringWriter) write(buf []u8) ?int { w.bytes << buf return buf.len } diff --git a/vlib/v/gen/js/sourcemap/vlq/vlq.v b/vlib/v/gen/js/sourcemap/vlq/vlq.v index 2d20e4a931..179f293392 100644 --- a/vlib/v/gen/js/sourcemap/vlq/vlq.v +++ b/vlib/v/gen/js/sourcemap/vlq/vlq.v @@ -51,7 +51,7 @@ fn decode64(input byte) byte { // Note that `i64::MIN = -(2^63)` cannot be represented in that form, and this // NOT IMPLEMENTED: function will return `Error::Overflowed` when attempting to decode it. pub fn decode(mut input io.Reader) ?i64 { - mut buf := []byte{len: 1} + mut buf := []u8{len: 1} mut accum := u64(0) mut shifter := 0 diff --git a/vlib/v/gen/js/sourcemap/vlq/vlq_decode_test.v b/vlib/v/gen/js/sourcemap/vlq/vlq_decode_test.v index 6d188e1220..85bc70bb77 100644 --- a/vlib/v/gen/js/sourcemap/vlq/vlq_decode_test.v +++ b/vlib/v/gen/js/sourcemap/vlq/vlq_decode_test.v @@ -4,7 +4,7 @@ import io struct TestReader { pub: - bytes []byte + bytes []u8 mut: i int } @@ -35,7 +35,7 @@ fn test_decode_a() ? { } } -fn (mut b TestReader) read(mut buf []byte) ?int { +fn (mut b TestReader) read(mut buf []u8) ?int { if !(b.i < b.bytes.len) { return none } diff --git a/vlib/v/gen/js/sourcemap/vlq/vlq_encode_test.v b/vlib/v/gen/js/sourcemap/vlq/vlq_encode_test.v index ad2db3b7a6..21f6587a8c 100644 --- a/vlib/v/gen/js/sourcemap/vlq/vlq_encode_test.v +++ b/vlib/v/gen/js/sourcemap/vlq/vlq_encode_test.v @@ -7,7 +7,7 @@ struct TestData { struct TestWriter { pub mut: - bytes []byte + bytes []u8 } fn test_encode_a() ? { @@ -29,7 +29,7 @@ fn test_encode_a() ? { } } -fn (mut w TestWriter) write(buf []byte) ?int { +fn (mut w TestWriter) write(buf []u8) ?int { w.bytes << buf return buf.len } diff --git a/vlib/v/gen/native/amd64.v b/vlib/v/gen/native/amd64.v index faab705151..44d025e41a 100644 --- a/vlib/v/gen/native/amd64.v +++ b/vlib/v/gen/native/amd64.v @@ -975,7 +975,7 @@ fn (mut g Gen) patch_calls() { } last := g.buf.len g.call(int(addr + last - c.pos)) - mut patch := []byte{} + mut patch := []u8{} for last < g.buf.len { patch << g.buf.pop() } diff --git a/vlib/v/gen/native/gen.v b/vlib/v/gen/native/gen.v index dcfa999219..4d9d2018fe 100644 --- a/vlib/v/gen/native/gen.v +++ b/vlib/v/gen/native/gen.v @@ -29,7 +29,7 @@ pub struct Gen { mut: code_gen CodeGen table &ast.Table - buf []byte + buf []u8 sect_header_name_pos int offset i64 stackframe_size int @@ -193,7 +193,7 @@ pub fn (g &Gen) pos() i64 { return g.buf.len } -fn (mut g Gen) write(bytes []byte) { +fn (mut g Gen) write(bytes []u8) { for _, b in bytes { g.buf << b } diff --git a/vlib/v/gen/native/pe.v b/vlib/v/gen/native/pe.v index 9488d8f7c3..23fee81c32 100644 --- a/vlib/v/gen/native/pe.v +++ b/vlib/v/gen/native/pe.v @@ -213,7 +213,7 @@ pub fn (mut g Gen) generate_pe_header() { g.main_fn_addr = g.buf.len } -fn pad_to(mut buf []byte, len int) { +fn pad_to(mut buf []u8, len int) { for buf.len < len { buf << u8(0) } diff --git a/vlib/v/preludes/embed_file/zlib/embed_file_zlib.v b/vlib/v/preludes/embed_file/zlib/embed_file_zlib.v index 243e042a2d..09f6644cc0 100644 --- a/vlib/v/preludes/embed_file/zlib/embed_file_zlib.v +++ b/vlib/v/preludes/embed_file/zlib/embed_file_zlib.v @@ -5,7 +5,7 @@ import v.embed_file struct ZLibDecoder {} -fn (_ ZLibDecoder) decompress(data []byte) ?[]byte { +fn (_ ZLibDecoder) decompress(data []u8) ?[]u8 { return zlib.decompress(data) } diff --git a/vlib/v/tests/bench/math_big_gcd/bench_euclid.v b/vlib/v/tests/bench/math_big_gcd/bench_euclid.v index 9be61138b2..ec5091b1c5 100644 --- a/vlib/v/tests/bench/math_big_gcd/bench_euclid.v +++ b/vlib/v/tests/bench/math_big_gcd/bench_euclid.v @@ -271,12 +271,12 @@ pub fn bi_from_decimal_string(s string) big.Integer { // need the bi.digits.len - during test only - to calculate // the size of big.Integers-buffer // -fn bi_buffer_len(input []byte) int { +fn bi_buffer_len(input []u8) int { if input.len == 0 { return 0 } // pad input - mut padded_input := []byte{len: ((input.len + 3) & ~0x3) - input.len, cap: (input.len + 3) & ~0x3, init: 0x0} + mut padded_input := []u8{len: ((input.len + 3) & ~0x3) - input.len, cap: (input.len + 3) & ~0x3, init: 0x0} padded_input << input mut digits := []u32{len: padded_input.len / 4} // combine every 4 bytes into a u32 and insert into n.digits diff --git a/vlib/v/tests/clash_var_name_of_array_and_map_test.v b/vlib/v/tests/clash_var_name_of_array_and_map_test.v index a70105b87a..39560f616e 100644 --- a/vlib/v/tests/clash_var_name_of_array_and_map_test.v +++ b/vlib/v/tests/clash_var_name_of_array_and_map_test.v @@ -15,7 +15,7 @@ fn test_clash_var_name_of_array() { a_f64 := []f64{} a_bool := []bool{} a_i8 := []i8{} - a_byte := []byte{} + a_byte := []u8{} a_i16 := []i16{} a_u16 := []u16{} a_int := []int{} diff --git a/vlib/v/tests/generics_struct_parent_has_str_to_string_test.v b/vlib/v/tests/generics_struct_parent_has_str_to_string_test.v index c815a769a5..dd571bc9e2 100644 --- a/vlib/v/tests/generics_struct_parent_has_str_to_string_test.v +++ b/vlib/v/tests/generics_struct_parent_has_str_to_string_test.v @@ -19,7 +19,7 @@ mut: } struct Pattern { - pattern []byte + pattern []u8 handler fn (mut m Vm) } diff --git a/vlib/v/tests/generics_with_complex_nested_generics_type_test.v b/vlib/v/tests/generics_with_complex_nested_generics_type_test.v index 5c8fde260f..6b1a65f52f 100644 --- a/vlib/v/tests/generics_with_complex_nested_generics_type_test.v +++ b/vlib/v/tests/generics_with_complex_nested_generics_type_test.v @@ -1,9 +1,9 @@ fn test_generics_with_complex_nested_generics_type() { - mut buf := []byte{} + mut buf := []u8{} initial(buf) } -fn initial(buf []byte) map[K]V { +fn initial(buf []u8) map[K]V { mut ret := map[K]V{} for _ in 0 .. 3 { k := get(buf) @@ -15,7 +15,7 @@ fn initial(buf []byte) map[K]V { return ret } -fn get(buf []byte) T { +fn get(buf []u8) T { $if T is string { return buf.bytestr() + 'get' } $else $if T is u64 { diff --git a/vlib/v/tests/generics_with_nested_generics_fn_inst_call_test.v b/vlib/v/tests/generics_with_nested_generics_fn_inst_call_test.v index 728987e44d..c15d64010f 100644 --- a/vlib/v/tests/generics_with_nested_generics_fn_inst_call_test.v +++ b/vlib/v/tests/generics_with_nested_generics_fn_inst_call_test.v @@ -9,7 +9,7 @@ fn test_generics_with_nested_generic_fn_inst_call() { assert decoded[3] == 'it works!!' } -fn decode_arr(buf []byte) []T { +fn decode_arr(buf []u8) []T { arr_size := decode(buf[0..4]) mut ret := []T{cap: int(arr_size)} @@ -19,7 +19,7 @@ fn decode_arr(buf []byte) []T { return ret } -fn decode(buf []byte) T { +fn decode(buf []u8) T { $if T is u32 { return u32(buf.len) } $else $if T is string { diff --git a/vlib/v/tests/interface_only_decl_with_optional_test.v b/vlib/v/tests/interface_only_decl_with_optional_test.v index 48dce1a521..ed385d8b64 100644 --- a/vlib/v/tests/interface_only_decl_with_optional_test.v +++ b/vlib/v/tests/interface_only_decl_with_optional_test.v @@ -1,5 +1,5 @@ interface Message { - serialize() ?[]byte + serialize() ?[]u8 } fn test_interface_only_decl_with_optional() { diff --git a/vlib/v/tests/match_compound_type_cond_test.v b/vlib/v/tests/match_compound_type_cond_test.v index 9f072b875d..90cd48c8d7 100644 --- a/vlib/v/tests/match_compound_type_cond_test.v +++ b/vlib/v/tests/match_compound_type_cond_test.v @@ -2,8 +2,8 @@ struct Foo {} fn test_match_array_or_map_cond() { // array - y1 := []byte{} - x1 := []byte{} + y1 := []u8{} + x1 := []u8{} ret1 := match x1 { y1 { true } else { false } diff --git a/vlib/v/tests/multiple_matchs_in_one_expr_test.v b/vlib/v/tests/multiple_matchs_in_one_expr_test.v index 8bd43fae0e..e1f58fb17b 100644 --- a/vlib/v/tests/multiple_matchs_in_one_expr_test.v +++ b/vlib/v/tests/multiple_matchs_in_one_expr_test.v @@ -1,5 +1,5 @@ -fn hex_to_bytes(s string) ?[]byte { - mut ret := []byte{cap: s.len} +fn hex_to_bytes(s string) ?[]u8 { + mut ret := []u8{cap: s.len} for read := 0; read < s.len; read += 2 { high := s[read] low := s[read + 1] diff --git a/vlib/v/tests/struct_fields_storing_functions_test.v b/vlib/v/tests/struct_fields_storing_functions_test.v index d4f03a52e9..29267051dc 100644 --- a/vlib/v/tests/struct_fields_storing_functions_test.v +++ b/vlib/v/tests/struct_fields_storing_functions_test.v @@ -1,6 +1,6 @@ -type Async_cb = fn (x []byte, mut y []byte) int +type Async_cb = fn (x []u8, mut y []u8) int -fn async_cb(b []byte, mut res []byte) int { +fn async_cb(b []u8, mut res []u8) int { if b.len > 0 { res << b } @@ -15,7 +15,7 @@ mut: fn test_struct_fn_field_can_be_used_directly() { buf := [u8(1), 2, 3] - mut res := []byte{} + mut res := []u8{} res << 0x88 async_cb(buf[0..2], mut res) data := Ep_arg{ diff --git a/vlib/v/tests/testdata/test_array_bound.v b/vlib/v/tests/testdata/test_array_bound.v index c51d590fb9..f9286ea3a0 100644 --- a/vlib/v/tests/testdata/test_array_bound.v +++ b/vlib/v/tests/testdata/test_array_bound.v @@ -11,44 +11,44 @@ fn access(b byte) bool { return false } -fn check_underscore(a []byte) { +fn check_underscore(a []u8) { _ = a[1] direct(a[0]) } -fn check_fn(a []byte) { +fn check_fn(a []u8) { access(a[2]) direct(a[2]) direct(a[1]) } -fn check_if_access(a []byte) { +fn check_if_access(a []u8) { access(a[3]) if a[3] == `0` { } } -fn check_if_fn_access(a []byte) { +fn check_if_fn_access(a []u8) { access(a[4]) if direct(a[4]) { direct(a[4]) } } -fn check_if_test_in_branch(a []byte) { +fn check_if_test_in_branch(a []u8) { if a[6] == `0` { direct(a[5]) access(a[7]) } } -fn check_if_fn_branch(a []byte) { +fn check_if_fn_branch(a []u8) { if access(a[8]) { direct(a[7]) } } -fn check_for_branch(a []byte) { +fn check_for_branch(a []u8) { access(a[9]) for _ in 0 .. 1 { access(a[10]) @@ -57,7 +57,7 @@ fn check_for_branch(a []byte) { access(a[10]) } -fn check_assert(a []byte) { +fn check_assert(a []u8) { assert a.len >= 19 direct(a[18]) @@ -65,7 +65,7 @@ fn check_assert(a []byte) { _ = a[20] } -fn check_range_access(a []byte) { +fn check_range_access(a []u8) { access(a[23]) range := a[20..25] direct(range[3]) @@ -73,7 +73,7 @@ fn check_range_access(a []byte) { direct(range[4]) } -fn check_for(a []byte) { +fn check_for(a []u8) { for access(a[30]) == false { direct(a[30]) access(a[31]) @@ -81,7 +81,7 @@ fn check_for(a []byte) { } } -fn check_for_c_init_0(a []byte) { +fn check_for_c_init_0(a []u8) { for a[32] == 0 { direct(a[32]) access(a[33]) @@ -89,7 +89,7 @@ fn check_for_c_init_0(a []byte) { } } -fn check_for_c_init_1(a []byte) { +fn check_for_c_init_1(a []u8) { for access_it := a[34]; a[34] == 0; { direct(a[34]) access(a[35]) @@ -99,7 +99,7 @@ fn check_for_c_init_1(a []byte) { } } -// fn check_for_c_init_2(a []byte) { +// fn check_for_c_init_2(a []u8) { // mut run := true // for x := a[36]; a[36] == 0 && run; x = a[38] { // direct(a[36]) @@ -109,25 +109,25 @@ fn check_for_c_init_1(a []byte) { // direct(a[38]) // } -// fn skip_clone(a []byte) { +// fn skip_clone(a []u8) { // access(a[30]) // fn_local := a.clone() // direct(fn_local[30]) // } -// fn skip_mut_self_assign(a []byte) { +// fn skip_mut_self_assign(a []u8) { // mut fn_local := a.clone() // fn_local[31] = fn_local[32] // direct(fn_local[31]) // } -// fn skip_enum (a []byte) { +// fn skip_enum (a []u8) { // access(a[33]) // direct(a[Index.two]) // } fn main() { - a := []byte{len: 50} + a := []u8{len: 50} direct(a[49]) check_underscore(a) diff --git a/vlib/v/tests/unsafe_test.v b/vlib/v/tests/unsafe_test.v index 75436b84ef..dc2a8a9435 100644 --- a/vlib/v/tests/unsafe_test.v +++ b/vlib/v/tests/unsafe_test.v @@ -80,7 +80,7 @@ fn test_unsafe_pointers() { fsize := fixedbytes.len src := &fixedbytes[0] // - b := []byte{} + b := []u8{} eprintln('b.data before: $b.data') eprintln('b.len before: $b.len') eprintln('b.cap before: $b.cap') diff --git a/vlib/v/tests/valgrind/base64.v b/vlib/v/tests/valgrind/base64.v index 14acce26a4..298b60fb3a 100644 --- a/vlib/v/tests/valgrind/base64.v +++ b/vlib/v/tests/valgrind/base64.v @@ -4,7 +4,7 @@ fn main() { repeats := 1000 input_size := 3000 - s_original := []byte{len: input_size, init: `a`} + s_original := []u8{len: input_size, init: `a`} s_encoded := base64.encode(s_original) s_encoded_bytes := s_encoded.bytes() s_decoded := base64.decode(s_encoded) @@ -20,7 +20,7 @@ fn main() { } // encoded_size := base64.encode_in_buffer(s_original, ebuffer) - mut encoded_in_buf := []byte{len: encoded_size} + mut encoded_in_buf := []u8{len: encoded_size} unsafe { C.memcpy(encoded_in_buf.data, ebuffer, encoded_size) } assert input_size * 4 / 3 == encoded_size assert encoded_in_buf[0] == `Y` @@ -37,7 +37,7 @@ fn main() { decoded_size := base64.decode_in_buffer(s_encoded, dbuffer) assert decoded_size == input_size - mut decoded_in_buf := []byte{len: decoded_size} + mut decoded_in_buf := []u8{len: decoded_size} unsafe { C.memcpy(decoded_in_buf.data, dbuffer, decoded_size) } assert decoded_in_buf == s_original diff --git a/vlib/v/tests/valgrind/struct_field.v b/vlib/v/tests/valgrind/struct_field.v index 6972818514..cb5e73d3a1 100644 --- a/vlib/v/tests/valgrind/struct_field.v +++ b/vlib/v/tests/valgrind/struct_field.v @@ -1,6 +1,6 @@ struct LeakStruct { mut: - some_bytes []byte + some_bytes []u8 } fn (mut l LeakStruct) free() { @@ -11,7 +11,7 @@ fn (mut l LeakStruct) free() { fn main() { z := &LeakStruct{ - some_bytes: []byte{len: 1000} + some_bytes: []u8{len: 1000} } println(z.some_bytes.len) } diff --git a/vlib/x/json2/scanner.v b/vlib/x/json2/scanner.v index 57d112db59..c219e01489 100644 --- a/vlib/x/json2/scanner.v +++ b/vlib/x/json2/scanner.v @@ -7,7 +7,7 @@ import strconv struct Scanner { mut: - text []byte + text []u8 pos int line int col int @@ -31,7 +31,7 @@ enum TokenKind { } pub struct Token { - lit []byte + lit []u8 kind TokenKind line int col int @@ -108,7 +108,7 @@ fn (s Scanner) error(description string) Token { } // tokenize returns a token based on the given lit and kind. -fn (s Scanner) tokenize(lit []byte, kind TokenKind) Token { +fn (s Scanner) tokenize(lit []u8, kind TokenKind) Token { return Token{ lit: lit kind: kind @@ -121,7 +121,7 @@ fn (s Scanner) tokenize(lit []byte, kind TokenKind) Token { [manualfree] fn (mut s Scanner) text_scan() Token { mut has_closed := false - mut chrs := []byte{} + mut chrs := []u8{} for { s.pos++ s.col++ @@ -148,7 +148,7 @@ fn (mut s Scanner) text_scan() Token { if s.pos + 5 < s.text.len { s.pos++ s.col++ - mut codepoint := []byte{} + mut codepoint := []u8{} codepoint_start := s.pos for s.pos < s.text.len && s.pos < codepoint_start + 4 { s.pos++ @@ -201,7 +201,7 @@ fn (mut s Scanner) num_scan() Token { // -[digit][?[dot][digit]][?[E/e][?-/+][digit]] mut is_fl := false mut dot_index := -1 - mut digits := []byte{} + mut digits := []u8{} if s.text[s.pos] == `-` { digits << `-` if !s.text[s.pos + 1].is_digit() { @@ -262,7 +262,7 @@ fn (mut s Scanner) scan() Token { s.move() } if s.pos >= s.text.len { - return s.tokenize([]byte{}, .eof) + return s.tokenize([]u8{}, .eof) } else if s.pos + 3 < s.text.len && (s.text[s.pos] == `t` || s.text[s.pos] == `n`) { ident := s.text[s.pos..s.pos + 4].bytestr() if ident == 'true' || ident == 'null' { @@ -298,7 +298,7 @@ fn (mut s Scanner) scan() Token { return s.invalid_token() } else if s.text[s.pos] in json2.char_list { chr := s.text[s.pos] - tok := s.tokenize([]byte{}, TokenKind(int(chr))) + tok := s.tokenize([]u8{}, TokenKind(int(chr))) s.move() return tok } else if s.text[s.pos] == `"` { diff --git a/vlib/x/ttf/common.v b/vlib/x/ttf/common.v index aa0a5b0ec1..0df34b2aca 100644 --- a/vlib/x/ttf/common.v +++ b/vlib/x/ttf/common.v @@ -114,8 +114,8 @@ pub fn (mut bmp BitMap) save_as_ppm(file_name string) { bmp.buf = tmp_buf } -pub fn (mut bmp BitMap) get_raw_bytes() []byte { - mut f_buf := []byte{len: bmp.buf_size / 4} +pub fn (mut bmp BitMap) get_raw_bytes() []u8 { + mut f_buf := []u8{len: bmp.buf_size / 4} mut i := 0 for i < bmp.buf_size { unsafe { diff --git a/vlib/x/ttf/ttf.v b/vlib/x/ttf/ttf.v index 4c6b69b77b..5acee31512 100644 --- a/vlib/x/ttf/ttf.v +++ b/vlib/x/ttf/ttf.v @@ -45,7 +45,7 @@ mut: ******************************************************************************/ pub struct TTF_File { pub mut: - buf []byte + buf []u8 pos u32 length u16 scalar_type u32 @@ -319,7 +319,7 @@ fn (mut tf TTF_File) read_simple_glyph(mut in_glyph Glyph) { num_points++ mut i := 0 - mut flags := []byte{} + mut flags := []u8{} for i < num_points { flag := tf.get_u8() flags << flag diff --git a/vlib/x/ttf/ttf_test.v b/vlib/x/ttf/ttf_test.v index dc6be65bd2..205e030b6d 100644 --- a/vlib/x/ttf/ttf_test.v +++ b/vlib/x/ttf/ttf_test.v @@ -151,7 +151,7 @@ ffbf ffff bf00 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ' -fn save_raw_data_as_array(buf_bin []byte, file_name string) { +fn save_raw_data_as_array(buf_bin []u8, file_name string) { mut buf := strings.new_builder(buf_bin.len * 5) for x in buf_bin { buf.write_string('0x${x:02x},') @@ -212,8 +212,8 @@ fn test_main() { } } -fn get_raw_data(data string) []byte { - mut buf := []byte{} +fn get_raw_data(data string) []u8 { + mut buf := []u8{} mut c := 0 mut b := u32(0) for ch in data {