1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-25 21:36:13 -04:00

writeHash

This commit is contained in:
Darien Raymond 2018-07-30 22:54:24 +02:00
parent 206f52affc
commit 8cfe77383f
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 17 additions and 7 deletions

12
common/serial/hash.go Normal file
View File

@ -0,0 +1,12 @@
package serial
import (
"hash"
)
func WriteHash(h hash.Hash) func(b []byte) (int, error) {
return func(b []byte) (int, error) {
h.Sum(b[:0])
return h.Size(), nil
}
}

View File

@ -88,13 +88,11 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
common.Must(buffer.AppendSupplier(buf.ReadFullFrom(rand.Reader, int32(padingLen))))
}
fnv1a := fnv.New32a()
common.Must2(fnv1a.Write(buffer.Bytes()))
common.Must(buffer.AppendSupplier(func(b []byte) (int, error) {
fnv1a.Sum(b[:0])
return fnv1a.Size(), nil
}))
{
fnv1a := fnv.New32a()
common.Must2(fnv1a.Write(buffer.Bytes()))
common.Must(buffer.AppendSupplier(serial.WriteHash(fnv1a)))
}
timestampHash := md5.New()
common.Must2(timestampHash.Write(hashTimestamp(timestamp)))