Detect nonstandard hash algo and stop folder (ref #2314)

This commit is contained in:
Jakob Borg
2016-01-01 20:11:12 +01:00
parent 7c47eff112
commit 0db80710aa
4 changed files with 133 additions and 6 deletions

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2016 The Protocol Authors.
package protocol
import "testing"
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Hash |D|P|R|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
func TestHashAlgorithmFromFlagBits(t *testing.T) {
// SHA256 is algorithm zero, shifted three bits to the left (for clarity,
// I know it doesn't actually do anything).
sha256 := uint32(0 << 3)
h, err := HashAlgorithmFromFlagBits(sha256)
if err != nil {
t.Error(err)
}
if h != SHA256 {
t.Error("Zero should have unmarshalled as SHA256")
}
// Any other algorithm is unknown
unknown := uint32(1 << 3)
_, err = HashAlgorithmFromFlagBits(unknown)
if err == nil {
t.Error("Unknown algo should not have unmarshalled")
}
}