Debian Codegraph @

compact/compact.go

raw symbols SCIP
1 // package compact provides function to work with json compact serialization format
2 package compact
3
4 import (
5 "github.com/dvsekhvalnov/jose2go/base64url"
6 "strings"
7 )
8
9 // Parse splitting & decoding compact serialized json web token, returns slice of byte arrays, each representing part of token
10 func Parse(token string) (result [][]byte, e error) {
11 parts := strings.Split(token, ".")
12
13 result = make([][]byte, len(parts))
14
15 for i, part := range parts {
16 if result[i], e = base64url.Decode(part); e != nil {
17 return nil, e
18 }
19 }
20
21 return result, nil
22 }
23
24 // Serialize converts given parts into compact serialization format
25 func Serialize(parts ...[]byte) string {
26 result := make([]string, len(parts))
27
28 for i, part := range parts {
29 result[i] = base64url.Encode(part)
30 }
31
32 return strings.Join(result, ".")
33 }