...
1 package token
2
3 import (
4 "encoding/base64"
5 "errors"
6 "strings"
7 )
8
9
10
11
12
13 func joseBase64UrlEncode(b []byte) string {
14 return strings.TrimRight(base64.URLEncoding.EncodeToString(b), "=")
15 }
16
17
18
19
20
21 func joseBase64UrlDecode(s string) ([]byte, error) {
22 switch len(s) % 4 {
23 case 0:
24 case 2:
25 s += "=="
26 case 3:
27 s += "="
28 default:
29 return nil, errors.New("illegal base64url string")
30 }
31 return base64.URLEncoding.DecodeString(s)
32 }
33
34
35 type actionSet struct {
36 stringSet
37 }
38
39 func newActionSet(actions ...string) actionSet {
40 return actionSet{newStringSet(actions...)}
41 }
42
43
44
45 func (s actionSet) contains(action string) bool {
46 return s.stringSet.contains("*") || s.stringSet.contains(action)
47 }
48
49
50 func contains(ss []string, q string) bool {
51 for _, s := range ss {
52 if s == q {
53 return true
54 }
55 }
56
57 return false
58 }
59
View as plain text