test: Rename some variables.
parent
bdf20db1f3
commit
a0d95be4fb
|
@ -12,48 +12,48 @@ var tests = []struct {
|
||||||
f func() hash.Hash
|
f func() hash.Hash
|
||||||
name string
|
name string
|
||||||
text string
|
text string
|
||||||
vector string
|
hash string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
f: newKeccak256,
|
f: newKeccak256,
|
||||||
name: "Keccak-256",
|
name: "Keccak-256",
|
||||||
vector: "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
|
hash: "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: newKeccak512,
|
f: newKeccak512,
|
||||||
name: "Keccak-512",
|
name: "Keccak-512",
|
||||||
vector: "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e",
|
hash: "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: New256,
|
f: New256,
|
||||||
name: "SHA3-256",
|
name: "SHA3-256",
|
||||||
vector: "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a",
|
hash: "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: New512,
|
f: New512,
|
||||||
name: "SHA3-512",
|
name: "SHA3-512",
|
||||||
vector: "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26",
|
hash: "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: New256,
|
f: New256,
|
||||||
name: "SHA3-256",
|
name: "SHA3-256",
|
||||||
text: "The quick brown fox jumps over the lazy dog",
|
text: "The quick brown fox jumps over the lazy dog",
|
||||||
vector: "69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04",
|
hash: "69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHash(t *testing.T) {
|
func TestHash(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
vector, err := hex.DecodeString(tt.vector)
|
want, err := hex.DecodeString(tt.hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s(%q): %s", tt.name, tt.text, err)
|
t.Errorf("%s(%q): %s", tt.name, tt.text, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
h := tt.f()
|
h := tt.f()
|
||||||
io.WriteString(h, tt.text)
|
io.WriteString(h, tt.text)
|
||||||
sum := h.Sum(nil)
|
got := h.Sum(nil)
|
||||||
if !bytes.Equal(sum, vector) {
|
if !bytes.Equal(got, want) {
|
||||||
t.Errorf("%s(%q): want %x, got %x", tt.name, tt.text, vector, sum)
|
t.Errorf("%s(%q) = %x, want %x", tt.name, tt.text, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue