Identifier: New functions to create from string and know if empty

This commit is contained in:
nemunaire 2022-10-05 22:33:03 +02:00
parent afac453e08
commit 6e6521c814

View File

@ -5,8 +5,18 @@ import (
"errors" "errors"
) )
const IDENTIFIER_LEN = 48
type Identifier []byte type Identifier []byte
func NewIdentifierFromString(src string) (id Identifier, err error) {
return base64.RawURLEncoding.DecodeString(src)
}
func (i *Identifier) IsEmpty() bool {
return len(*i) == 0
}
func (i *Identifier) ToString() string { func (i *Identifier) ToString() string {
return base64.RawURLEncoding.EncodeToString(*i) return base64.RawURLEncoding.EncodeToString(*i)
} }