mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
682 B
35 lines
682 B
package io
|
|
|
|
import (
|
|
"hash/fnv"
|
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
|
v2io "github.com/v2ray/v2ray-core/common/io"
|
|
"github.com/v2ray/v2ray-core/common/serial"
|
|
)
|
|
|
|
type AuthChunkWriter struct {
|
|
writer v2io.Writer
|
|
}
|
|
|
|
func NewAuthChunkWriter(writer v2io.Writer) *AuthChunkWriter {
|
|
return &AuthChunkWriter{
|
|
writer: writer,
|
|
}
|
|
}
|
|
|
|
func (this *AuthChunkWriter) Write(buffer *alloc.Buffer) error {
|
|
Authenticate(buffer)
|
|
return this.writer.Write(buffer)
|
|
}
|
|
|
|
func Authenticate(buffer *alloc.Buffer) {
|
|
fnvHash := fnv.New32a()
|
|
fnvHash.Write(buffer.Value)
|
|
|
|
buffer.SliceBack(4)
|
|
fnvHash.Sum(buffer.Value[:0])
|
|
|
|
buffer.Prepend(serial.Uint16Literal(uint16(buffer.Len())).Bytes())
|
|
}
|