From 8cfe77383f2fdd84c94cb6ce17e1a3e330626a08 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Mon, 30 Jul 2018 22:54:24 +0200 Subject: [PATCH] writeHash --- common/serial/hash.go | 12 ++++++++++++ proxy/vmess/encoding/client.go | 12 +++++------- 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 common/serial/hash.go diff --git a/common/serial/hash.go b/common/serial/hash.go new file mode 100644 index 000000000..627343d6c --- /dev/null +++ b/common/serial/hash.go @@ -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 + } +} diff --git a/proxy/vmess/encoding/client.go b/proxy/vmess/encoding/client.go index cf4475000..45f2c761c 100644 --- a/proxy/vmess/encoding/client.go +++ b/proxy/vmess/encoding/client.go @@ -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)))