Add test for stream package

This commit is contained in:
Eric Yan
2017-07-06 21:23:20 +08:00
parent 0d2118a821
commit b88eaf49f2

27
stream/stream_test.go Normal file
View File

@@ -0,0 +1,27 @@
package stream
import "testing"
type fakePRNG struct{}
func (*fakePRNG) Uint64() uint64 {
return uint64(0XDEADBEEF)
}
func TestStreamCipher(t *testing.T) {
plaintext := []byte("hello, world")
ciphertext := make([]byte, len(plaintext))
c1 := NewCipher(new(fakePRNG))
c1.XORKeyStream(ciphertext, plaintext)
plaintext2 := make([]byte, len(plaintext))
c2 := NewCipher(new(fakePRNG))
c2.XORKeyStream(plaintext2, ciphertext)
for i, v := range plaintext2 {
if v != plaintext[i] {
t.Fatalf("mismatch at byte %d:\nhave: % x\nwant: % x", i, plaintext2, plaintext)
}
}
}