github.com/lestrrat-go/jwx/v2@v2.0.21/jwk/usage.go (about)

     1  package jwk
     2  
     3  import "fmt"
     4  
     5  func (k KeyUsageType) String() string {
     6  	return string(k)
     7  }
     8  
     9  func (k *KeyUsageType) Accept(v interface{}) error {
    10  	switch v := v.(type) {
    11  	case KeyUsageType:
    12  		switch v {
    13  		case ForSignature, ForEncryption:
    14  			*k = v
    15  			return nil
    16  		default:
    17  			return fmt.Errorf("invalid key usage type %s", v)
    18  		}
    19  	case string:
    20  		switch v {
    21  		case ForSignature.String(), ForEncryption.String():
    22  			*k = KeyUsageType(v)
    23  			return nil
    24  		default:
    25  			return fmt.Errorf("invalid key usage type %s", v)
    26  		}
    27  	}
    28  
    29  	return fmt.Errorf("invalid value for key usage type %s", v)
    30  }