1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vlib.crypto+other: fix mut args

This commit is contained in:
joe-conigliaro
2019-08-07 21:37:07 +10:00
committed by Alexander Medvednikov
parent 818c4a14e5
commit 511a3d3901
15 changed files with 53 additions and 43 deletions

View File

@@ -47,7 +47,8 @@ pub fn new_cbc(b AesCipher, iv []byte) AesCbc {
pub fn (x &AesCbc) block_size() int { return x.block_size }
pub fn (x &AesCbc) encrypt_blocks(dst, src []byte) {
pub fn (x mut AesCbc) encrypt_blocks(dst mut []byte, src_ []byte) {
mut src := src_
if src.len%x.block_size != 0 {
panic('crypto.cipher: input not full blocks')
}
@@ -72,14 +73,14 @@ pub fn (x &AesCbc) encrypt_blocks(dst, src []byte) {
} else {
src = src.right(x.block_size)
}
dst = dst.right(x.block_size)
*dst = dst.right(x.block_size)
}
// Save the iv for the next crypt_blocks call.
copy(x.iv, iv)
}
pub fn (x &AesCbc) decrypt_blocks(dst mut []byte, src []byte) {
pub fn (x mut AesCbc) decrypt_blocks(dst mut []byte, src []byte) {
if src.len%x.block_size != 0 {
panic('crypto.cipher: input not full blocks')
}
@@ -105,7 +106,7 @@ pub fn (x &AesCbc) decrypt_blocks(dst mut []byte, src []byte) {
// Loop over all but the first block.
for start > 0 {
x.b.decrypt(dst.slice(start, end), src.slice(start, end))
cipher.xor_bytes(dst.slice(start, end), dst.slice(start, end), src.slice(prev, start))
cipher.xor_bytes(mut dst.slice(start, end), dst.slice(start, end), src.slice(prev, start))
end = start
start = prev
@@ -122,7 +123,7 @@ pub fn (x &AesCbc) decrypt_blocks(dst mut []byte, src []byte) {
x.tmp = x.iv
}
fn (x &AesCbc) set_iv(iv []byte) {
fn (x mut AesCbc) set_iv(iv []byte) {
if iv.len != x.iv.len {
panic('cipher: incorrect length IV')
}