github.com/greenpau/go-authcrunch@v1.1.4/pkg/kms/methods.go (about) 1 // Copyright 2022 Paul Greenberg greenpau@outlook.com 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package kms 16 17 import ( 18 "strings" 19 ) 20 21 var ( 22 // signingMethods are supported JWT token signing methods. 23 signingMethods = map[string]string{ 24 "HS256": "hmac", 25 "HS384": "hmac", 26 "HS512": "hmac", 27 "RS256": "rsa", 28 "RS384": "rsa", 29 "RS512": "rsa", 30 "ES256": "ecdsa", 31 "ES384": "ecdsa", 32 "ES512": "ecdsa", 33 } 34 35 algoMethodMap = map[string][]string{ 36 "hmac": []string{"HS512", "HS384", "HS256"}, 37 "rsa": []string{"RS512", "RS384", "RS256"}, 38 "ecdsa": []string{"ES512", "ES384", "ES256"}, 39 } 40 ) 41 42 // getSigningMethodAlias returns alias for the provided signing method. 43 func getSigningMethodAlias(s string) string { 44 s = strings.ToUpper(s) 45 if v, exists := signingMethods[s]; exists { 46 arr := strings.SplitN(v, ",", 2) 47 return strings.TrimSpace(arr[0]) 48 } 49 return "unknown" 50 } 51 52 func getMethodsPerAlgo(s string) []string { 53 return algoMethodMap[s] 54 }