30 lines
434 B
Go
30 lines
434 B
Go
package ID
|
|
|
|
import "encoding/base64"
|
|
|
|
func Decode(input string) (t Type, lastError error) {
|
|
ret, err := base64.URLEncoding.DecodeString(input)
|
|
|
|
if err != nil {
|
|
lastError = err
|
|
return
|
|
}
|
|
|
|
for i := 2; i >= 0; i-- {
|
|
t <<= 8
|
|
t |= Type(ret[i])
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (t Type) Encode() string {
|
|
var buffer [3]byte
|
|
for i := 0; i < 3; i++ {
|
|
buffer[i] = byte(t)
|
|
t >>= 8
|
|
}
|
|
|
|
return base64.URLEncoding.EncodeToString(buffer[:])
|
|
}
|