@@ -16,25 +16,30 @@ const (
1616var hmacSignaturePrefix = []byte (HMACSignaturePrefix )
1717
1818func VerifyHMACLoginAndPassword (mac hash.Hash , login , password []byte ) bool {
19- n , err := base64 .RawURLEncoding .Decode (password , password )
19+ buf := make ([]byte , base64 .RawURLEncoding .DecodedLen (len (password )))
20+ n , err := base64 .RawURLEncoding .Decode (buf , password )
2021 if err != nil {
2122 return false
2223 }
23- password = password [:n ]
24+ buf = buf [:n ]
2425
2526 var expire int64
26- if len (password ) < int (unsafe .Sizeof (expire )) {
27+ if len (buf ) < int (unsafe .Sizeof (expire )) {
2728 return false
2829 }
29- expire = int64 (binary .BigEndian .Uint64 (password [:unsafe .Sizeof (expire )]))
30- password = password [unsafe .Sizeof (expire ):]
30+ expire = int64 (binary .BigEndian .Uint64 (buf [:unsafe .Sizeof (expire )]))
31+ buf = buf [unsafe .Sizeof (expire ):]
3132
3233 if time .Unix (expire , 0 ).Before (time .Now ()) {
3334 return false
3435 }
3536
37+ if len (buf ) < mac .Size () {
38+ return false
39+ }
40+
3641 expectedMAC := CalculateHMACSignature (mac , login , expire )
37- return hmac .Equal (password , expectedMAC )
42+ return hmac .Equal (buf [: mac . Size ()] , expectedMAC )
3843}
3944
4045func CalculateHMACSignature (mac hash.Hash , username []byte , expire int64 ) []byte {
0 commit comments