good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 00b99174 authored by Anmol Sethi's avatar Anmol Sethi
Browse files

Add mask test

parent b9780288
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ module nhooyr.io/websocket
go 1.12
require (
github.com/google/go-cmp v0.2.0
github.com/kr/pretty v0.1.0 // indirect
go.coder.com/go-tools v0.0.0-20190317003359-0c6a35b74a16
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3
......
......@@ -6,7 +6,8 @@ package websocket
// See https://tools.ietf.org/html/rfc6455#section-5.3
//
// The returned value is the position of the next byte
// to be used for masking in the key.
// to be used for masking in the key. This is so that
// unmasking can be performed without the entire frame.
func mask(key [4]byte, pos int, p []byte) int {
for i := range p {
p[i] ^= key[pos&3]
......
package websocket
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func Test_mask(t *testing.T) {
t.Parallel()
key := [4]byte{0xa, 0xb, 0xc, 0xff}
p := []byte{0xa, 0xb, 0xc, 0xf2, 0xc}
pos := 0
pos = mask(key, pos, p)
if exp := []byte{0, 0, 0, 0x0d, 0x6}; !cmp.Equal(exp, p) {
t.Fatalf("unexpected mask: %v", cmp.Diff(exp, p))
}
if exp := 1; !cmp.Equal(exp, pos) {
t.Fatalf("unexpected mask pos: %v", cmp.Diff(exp, pos))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment