File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -23,13 +23,19 @@ func NewHasher(secret []byte) hash.Hash {
2323type Verifier struct {
2424 mac hash.Hash
2525 buf []byte
26+ dec * base64.Encoding
2627 strict bool
2728}
2829
2930func NewVerifier (secret []byte , strict bool ) * Verifier {
31+ dec := base64 .RawURLEncoding
32+ if strict {
33+ dec = dec .Strict ()
34+ }
3035 return & Verifier {
3136 mac : hmac .New (sha256 .New , secret ),
3237 strict : strict ,
38+ dec : dec ,
3339 }
3440}
3541
@@ -40,13 +46,13 @@ func (v *Verifier) ensureBufferSize(size int) {
4046}
4147
4248func (v * Verifier ) VerifyLoginAndPassword (login , password []byte ) bool {
43- if v .strict && len (password ) != base64 . RawURLEncoding .EncodedLen (HMACExpireSize + v .mac .Size ()) {
49+ if v .strict && len (password ) != v . dec .EncodedLen (HMACExpireSize + v .mac .Size ()) {
4450 return false
4551 }
4652
47- v .ensureBufferSize (base64 . RawURLEncoding .DecodedLen (len (password )))
53+ v .ensureBufferSize (v . dec .DecodedLen (len (password )))
4854 buf := v .buf
49- n , _ := base64 . RawURLEncoding .Decode (buf , password )
55+ n , _ := v . dec .Decode (buf , password )
5056 buf = buf [:n ]
5157
5258 var expire int64
You can’t perform that action at this time.
0 commit comments