Skip to content

Commit 7db735f

Browse files
committed
hmac: get rid of unsafe pkg
1 parent 1309adb commit 7db735f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

hmac/hmac.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
"encoding/binary"
88
"hash"
99
"time"
10-
"unsafe"
1110
)
1211

1312
const (
1413
HMACSignaturePrefix = "dumbproxy grant token v1"
14+
HMACExpireSize = 8
1515
)
1616

1717
var hmacSignaturePrefix = []byte(HMACSignaturePrefix)
@@ -29,11 +29,11 @@ func VerifyHMACLoginAndPassword(mac hash.Hash, login, password []byte) bool {
2929
buf = buf[:n]
3030

3131
var expire int64
32-
if len(buf) < int(unsafe.Sizeof(expire)) {
32+
if len(buf) < HMACExpireSize {
3333
return false
3434
}
35-
expire = int64(binary.BigEndian.Uint64(buf[:unsafe.Sizeof(expire)]))
36-
buf = buf[unsafe.Sizeof(expire):]
35+
expire = int64(binary.BigEndian.Uint64(buf[:HMACExpireSize]))
36+
buf = buf[HMACExpireSize:]
3737

3838
if time.Unix(expire, 0).Before(time.Now()) {
3939
return false
@@ -48,7 +48,7 @@ func VerifyHMACLoginAndPassword(mac hash.Hash, login, password []byte) bool {
4848
}
4949

5050
func CalculateHMACSignature(mac hash.Hash, username []byte, expire int64) []byte {
51-
var buf [unsafe.Sizeof(expire)]byte
51+
var buf [HMACExpireSize]byte
5252
binary.BigEndian.PutUint64(buf[:], uint64(expire))
5353

5454
mac.Reset()

0 commit comments

Comments
 (0)