go-sample-webpage/vendor/github.com/lestrrat-go/jwx/jwk/usage.go
2021-11-04 02:14:51 +01:00

30 lines
607 B
Go

package jwk
import "github.com/pkg/errors"
func (k KeyUsageType) String() string {
return string(k)
}
func (k *KeyUsageType) Accept(v interface{}) error {
switch v := v.(type) {
case KeyUsageType:
switch v {
case ForSignature, ForEncryption:
*k = v
return nil
default:
return errors.Errorf("invalid key usage type %s", v)
}
case string:
switch v {
case ForSignature.String(), ForEncryption.String():
*k = KeyUsageType(v)
return nil
default:
return errors.Errorf("invalid key usage type %s", v)
}
}
return errors.Errorf("invalid value for key usage type %s", v)
}