Newer
Older
package issuerUtils
import (
"fmt"
"strings"
)
// GetIssuerWithAndWithoutSlash takes an issuer url that might or might not end with a slash and returns the variant with and without trailing slash
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
func GetIssuerWithAndWithoutSlash(iss string) (string, string) {
iss0 := iss
var iss1 string
if strings.HasSuffix(iss0, "/") {
iss1 = strings.TrimSuffix(iss0, "/")
return iss1, iss0
} else {
iss1 = fmt.Sprintf("%s%c", iss0, '/')
return iss0, iss1
}
}
// CompareIssuerURLs compares two issuer urls. Issuer urls are also accepted as
// equal if they only differ in a trailing slash.
func CompareIssuerURLs(a, b string) bool {
if a == b {
return true
}
aLen := len(a)
bLen := len(b)
if bLen == aLen-1 {
a, b = b, a
aLen, bLen = bLen, aLen
}
if aLen == bLen-1 && b[bLen-1] == '/' {
if a == b[:bLen-1] {
return true
}
}
return false
}
// CombineSubIss combines subject and issuer
func CombineSubIss(sub, iss string) string {
if sub == "" || iss == "" {
return ""
}
return fmt.Sprintf("%s@%s", sub, iss)
}