mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: make v test-cleancode
test everything by default (#10050)
This commit is contained in:
@ -50,25 +50,25 @@ mut:
|
||||
|
||||
fn (mut d Digest) reset() {
|
||||
d.h = []u32{len: (8)}
|
||||
d.x = []byte{len: (chunk)}
|
||||
d.x = []byte{len: sha256.chunk}
|
||||
if !d.is224 {
|
||||
d.h[0] = u32(init0)
|
||||
d.h[1] = u32(init1)
|
||||
d.h[2] = u32(init2)
|
||||
d.h[3] = u32(init3)
|
||||
d.h[4] = u32(init4)
|
||||
d.h[5] = u32(init5)
|
||||
d.h[6] = u32(init6)
|
||||
d.h[7] = u32(init7)
|
||||
d.h[0] = u32(sha256.init0)
|
||||
d.h[1] = u32(sha256.init1)
|
||||
d.h[2] = u32(sha256.init2)
|
||||
d.h[3] = u32(sha256.init3)
|
||||
d.h[4] = u32(sha256.init4)
|
||||
d.h[5] = u32(sha256.init5)
|
||||
d.h[6] = u32(sha256.init6)
|
||||
d.h[7] = u32(sha256.init7)
|
||||
} else {
|
||||
d.h[0] = u32(init0_224)
|
||||
d.h[1] = u32(init1_224)
|
||||
d.h[2] = u32(init2_224)
|
||||
d.h[3] = u32(init3_224)
|
||||
d.h[4] = u32(init4_224)
|
||||
d.h[5] = u32(init5_224)
|
||||
d.h[6] = u32(init6_224)
|
||||
d.h[7] = u32(init7_224)
|
||||
d.h[0] = u32(sha256.init0_224)
|
||||
d.h[1] = u32(sha256.init1_224)
|
||||
d.h[2] = u32(sha256.init2_224)
|
||||
d.h[3] = u32(sha256.init3_224)
|
||||
d.h[4] = u32(sha256.init4_224)
|
||||
d.h[5] = u32(sha256.init5_224)
|
||||
d.h[6] = u32(sha256.init6_224)
|
||||
d.h[7] = u32(sha256.init7_224)
|
||||
}
|
||||
d.nx = 0
|
||||
d.len = 0
|
||||
@ -98,7 +98,7 @@ fn (mut d Digest) write(p_ []byte) ?int {
|
||||
if d.nx > 0 {
|
||||
n := copy(d.x[d.nx..], p)
|
||||
d.nx += n
|
||||
if d.nx == chunk {
|
||||
if d.nx == sha256.chunk {
|
||||
block(mut d, d.x)
|
||||
d.nx = 0
|
||||
}
|
||||
@ -108,8 +108,8 @@ fn (mut d Digest) write(p_ []byte) ?int {
|
||||
p = p[n..]
|
||||
}
|
||||
}
|
||||
if p.len >= chunk {
|
||||
n := p.len & ~(chunk - 1)
|
||||
if p.len >= sha256.chunk {
|
||||
n := p.len & ~(sha256.chunk - 1)
|
||||
block(mut d, p[..n])
|
||||
if n >= p.len {
|
||||
p = []
|
||||
@ -130,7 +130,7 @@ pub fn (d &Digest) sum(b_in []byte) []byte {
|
||||
hash := d0.checksum()
|
||||
mut b_out := b_in.clone()
|
||||
if d0.is224 {
|
||||
for b in hash[..size224] {
|
||||
for b in hash[..sha256.size224] {
|
||||
b_out << b
|
||||
}
|
||||
} else {
|
||||
@ -158,7 +158,7 @@ fn (mut d Digest) checksum() []byte {
|
||||
if d.nx != 0 {
|
||||
panic('d.nx != 0')
|
||||
}
|
||||
mut digest := []byte{len: (size)}
|
||||
mut digest := []byte{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])
|
||||
@ -190,8 +190,8 @@ pub fn sum224(data []byte) []byte {
|
||||
mut d := new224()
|
||||
d.write(data) or { panic(err) }
|
||||
sum := d.checksum()
|
||||
sum224 := []byte{len: (size224)}
|
||||
copy(sum224, sum[..size224])
|
||||
sum224 := []byte{len: sha256.size224}
|
||||
copy(sum224, sum[..sha256.size224])
|
||||
return sum224
|
||||
}
|
||||
|
||||
@ -204,14 +204,14 @@ fn block(mut dig Digest, p []byte) {
|
||||
// size returns the size of the checksum in bytes.
|
||||
pub fn (d &Digest) size() int {
|
||||
if !d.is224 {
|
||||
return size
|
||||
return sha256.size
|
||||
}
|
||||
return size224
|
||||
return sha256.size224
|
||||
}
|
||||
|
||||
// block_size returns the block size of the checksum in bytes.
|
||||
pub fn (d &Digest) block_size() int {
|
||||
return block_size
|
||||
return sha256.block_size
|
||||
}
|
||||
|
||||
// hexhash returns a hexadecimal SHA256 hash sum `string` of `s`.
|
||||
|
@ -1,12 +1,10 @@
|
||||
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
import crypto.sha256
|
||||
|
||||
fn test_crypto_sha256() {
|
||||
assert sha256.sum('This is a sha256 checksum.'.bytes()).hex() ==
|
||||
'dc7163299659529eae29683eb1ffec50d6c8fc7275ecb10c145fde0e125b8727'
|
||||
assert sha256.sum('This is a sha256 checksum.'.bytes()).hex() == 'dc7163299659529eae29683eb1ffec50d6c8fc7275ecb10c145fde0e125b8727'
|
||||
}
|
||||
|
||||
fn test_crypto_sha256_writer() {
|
||||
|
@ -115,9 +115,9 @@ fn block_generic(mut dig Digest, p_ []byte) {
|
||||
for i in 0 .. 64 {
|
||||
t1 := h +
|
||||
((bits.rotate_left_32(e, -6)) ^ (bits.rotate_left_32(e, -11)) ^ (bits.rotate_left_32(e, -25))) +
|
||||
((e & f) ^ (~e & g)) + u32(_k[i]) + w[i]
|
||||
t2 := ((bits.rotate_left_32(a, -2)) ^
|
||||
(bits.rotate_left_32(a, -13)) ^ (bits.rotate_left_32(a, -22))) +
|
||||
((e & f) ^ (~e & g)) + u32(sha256._k[i]) + w[i]
|
||||
t2 :=
|
||||
((bits.rotate_left_32(a, -2)) ^ (bits.rotate_left_32(a, -13)) ^ (bits.rotate_left_32(a, -22))) +
|
||||
((a & b) ^ (a & c) ^ (b & c))
|
||||
h = g
|
||||
g = f
|
||||
|
Reference in New Issue
Block a user