Skip to content

Commit

Permalink
feat: support fuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
ypli0629 committed Jul 14, 2022
1 parent 5dc1ace commit ad89b14
Show file tree
Hide file tree
Showing 3 changed files with 890 additions and 6 deletions.
9 changes: 3 additions & 6 deletions auth_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type GinJWTMiddleware struct {
// CookieSameSite allow use http.SameSite cookie param
CookieSameSite http.SameSite

Whitelist map[string]interface{}
Whitelist node
}

var (
Expand Down Expand Up @@ -404,15 +404,12 @@ func (mw *GinJWTMiddleware) MiddlewareInit() error {
return ErrMissingSecretKey
}

if mw.Whitelist == nil {
mw.Whitelist = make(map[string]interface{})
}
return nil
}

func (mw *GinJWTMiddleware) AddIgnore(urls ...string) {
for _, url := range urls {
mw.Whitelist[url] = nil
mw.Whitelist.addRoute(url, func() {})
}
}

Expand All @@ -424,7 +421,7 @@ func (mw *GinJWTMiddleware) MiddlewareFunc() gin.HandlerFunc {
}

func (mw *GinJWTMiddleware) middlewareImpl(c *gin.Context) {
if _, ok := mw.Whitelist[c.Request.URL.Path]; ok {
if _, ok := mw.Whitelist.findCaseInsensitivePath(c.Request.URL.Path, true); ok {
c.Next()
return
}
Expand Down
20 changes: 20 additions & 0 deletions bytesconv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package jwt

import (
"unsafe"
)

// StringToBytes converts string to byte slice without a memory allocation.
func StringToBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}

// BytesToString converts byte slice to string without a memory allocation.
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
Loading

0 comments on commit ad89b14

Please sign in to comment.