MCPcopy Create free account
hub / github.com/rilldata/rill / FromString

Function FromString

admin/pkg/authtoken/authtoken.go:65–102  ·  view source on GitHub ↗

FromString re-creates a token from it's string representation (acquired by calling String()). The things I do for pretty tokens.

(s string)

Source from the content-addressed store, hash-verified

63// FromString re-creates a token from it's string representation (acquired by calling String()).
64// The things I do for pretty tokens.
65func FromString(s string) (*Token, error) {
66 parts := strings.Split(s, "_")
67 if len(parts) != 3 {
68 return nil, ErrMalformed
69 }
70
71 if parts[0] != Prefix {
72 return nil, ErrMalformed
73 }
74
75 typ := Type(parts[1])
76 if !typ.Validate() {
77 return nil, ErrMalformed
78 }
79
80 payload, ok := unmarshalBase62(parts[2])
81 if !ok {
82 return nil, ErrMalformed
83 }
84
85 if len(payload) > 40 {
86 return nil, ErrMalformed
87 } else if len(payload) < 40 {
88 payload = padLeft(payload, 40)
89 }
90
91 var id [16]byte
92 copy(id[:], payload[0:16])
93
94 var secret [24]byte
95 copy(secret[:], payload[16:40])
96
97 return &Token{
98 Type: typ,
99 ID: uuid.UUID(id),
100 Secret: secret,
101 }, nil
102}
103
104func FromParts(typ Type, id uuid.UUID, secret []byte) (*Token, error) {
105 if !typ.Validate() {

Callers 8

RevokeAuthTokenMethod · 0.92
TestReciprocityFunction · 0.85
TestValidityFunction · 0.85
TestNullFunction · 0.85
TestPartiallyNullFunction · 0.85
TestManyFunction · 0.85

Calls 4

unmarshalBase62Function · 0.85
padLeftFunction · 0.85
TypeTypeAlias · 0.70
ValidateMethod · 0.65

Tested by 5

TestReciprocityFunction · 0.68
TestValidityFunction · 0.68
TestNullFunction · 0.68
TestPartiallyNullFunction · 0.68
TestManyFunction · 0.68