Skip to content

Commit b978028

Browse files
committed
Implement masking
Closes #33
1 parent 4ec1090 commit b978028

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

mask.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package websocket
22

3-
// Mask applies the WebSocket masking algorithm to p
3+
// mask applies the WebSocket masking algorithm to p
44
// with the given key where the first 3 bits of pos
55
// are the starting position in the key.
66
// See https://tools.ietf.org/html/rfc6455#section-5.3
77
//
8-
// It is highly optimized to mask per word with the usage
9-
// of unsafe.
10-
//
11-
// For targets that do not support unsafe, please report an issue.
12-
// There is a mask by byte function below that will be used for such targets.
8+
// The returned value is the position of the next byte
9+
// to be used for masking in the key.
1310
func mask(key [4]byte, pos int, p []byte) int {
14-
panic("TODO")
11+
for i := range p {
12+
p[i] ^= key[pos&3]
13+
pos++
14+
}
15+
return pos & 3
1516
}

0 commit comments

Comments
 (0)