30 lines
851 B
Go
30 lines
851 B
Go
package wire
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestMaskChangesWithSequenceAndRoundTrips(t *testing.T) {
|
|
var sid SessionID
|
|
for i := range sid { sid[i] = byte(i+1) }
|
|
plain := bytes.Repeat([]byte("DragonTCP"), 100)
|
|
a := append([]byte(nil), plain...)
|
|
b := append([]byte(nil), plain...)
|
|
MaskInPlace(a, sid, ModeUpload, 1, false)
|
|
MaskInPlace(b, sid, ModeUpload, 2, false)
|
|
if bytes.Equal(a, b) { t.Fatal("different sequences produced identical wire bytes") }
|
|
MaskInPlace(a, sid, ModeUpload, 1, false)
|
|
if !bytes.Equal(a, plain) { t.Fatal("mask did not round-trip") }
|
|
}
|
|
|
|
func BenchmarkMask1MiB(b *testing.B) {
|
|
var sid SessionID
|
|
data := make([]byte, 1024*1024)
|
|
b.SetBytes(int64(len(data)))
|
|
b.ResetTimer()
|
|
for i:=0;i<b.N;i++ {
|
|
MaskInPlace(data,sid,ModeUpload,uint64(i),false)
|
|
}
|
|
}
|