github.com/lestrrat-go/jwx/v2@v2.0.21/jwk/key_ops.go (about) 1 package jwk 2 3 import "fmt" 4 5 func (ops *KeyOperationList) Get() KeyOperationList { 6 if ops == nil { 7 return nil 8 } 9 return *ops 10 } 11 12 func (ops *KeyOperationList) Accept(v interface{}) error { 13 switch x := v.(type) { 14 case string: 15 return ops.Accept([]string{x}) 16 case []interface{}: 17 l := make([]string, len(x)) 18 for i, e := range x { 19 if es, ok := e.(string); ok { 20 l[i] = es 21 } else { 22 return fmt.Errorf(`invalid list element type: expected string, got %T`, v) 23 } 24 } 25 return ops.Accept(l) 26 case []string: 27 list := make(KeyOperationList, len(x)) 28 for i, e := range x { 29 switch e := KeyOperation(e); e { 30 case KeyOpSign, KeyOpVerify, KeyOpEncrypt, KeyOpDecrypt, KeyOpWrapKey, KeyOpUnwrapKey, KeyOpDeriveKey, KeyOpDeriveBits: 31 list[i] = e 32 default: 33 return fmt.Errorf(`invalid keyoperation %v`, e) 34 } 35 } 36 37 *ops = list 38 return nil 39 case []KeyOperation: 40 list := make(KeyOperationList, len(x)) 41 for i, e := range x { 42 switch e { 43 case KeyOpSign, KeyOpVerify, KeyOpEncrypt, KeyOpDecrypt, KeyOpWrapKey, KeyOpUnwrapKey, KeyOpDeriveKey, KeyOpDeriveBits: 44 list[i] = e 45 default: 46 return fmt.Errorf(`invalid keyoperation %v`, e) 47 } 48 } 49 50 *ops = list 51 return nil 52 case KeyOperationList: 53 *ops = x 54 return nil 55 default: 56 return fmt.Errorf(`invalid value %T`, v) 57 } 58 }