cmd/jwt/main.go
func getAlgFromKeyData(pem pemutil.Store) (jwt.Algorithm, error) {
	for _, v := range pem {
		// loop over crypto primitives in pemstore, and do type assertion. if
		// ecdsa.{PublicKey,PrivateKey} found, then use corresponding ESXXX as
		// algo. if rsa, then use DefaultRSAAlgorithm. if []byte, then use
		// DefaultHMACAlgorithm.
		switch k := v.(type) {
		case []byte:
			return jwt.HS512, nil

		case *ecdsa.PrivateKey:
			return getSuitableAlgFromCurve(k.Curve)

		case *ecdsa.PublicKey:
			return getSuitableAlgFromCurve(k.Curve)

		case *rsa.PrivateKey:
			return jwt.PS512, nil

		case *rsa.PublicKey:
			return jwt.PS512, nil
		}
	}

	return jwt.NONE, errors.New("cannot determine key type")
}
func getAlgFromKeyData(pem pemutil.Store) (jwt.Algorithm, error) {
	for _, v := range pem {
		// loop over crypto primitives in pemstore, and do type assertion. if
		// ecdsa.{PublicKey,PrivateKey} found, then use corresponding ESXXX as
		// algo. if rsa, then use DefaultRSAAlgorithm. if []byte, then use
		// DefaultHMACAlgorithm.
		switch k := v.(type) {
		case []byte:
			return jwt.HS512, nil

		case *ecdsa.PrivateKey:
			return getSuitableAlgFromCurve(k.Curve)

		case *ecdsa.PublicKey:
			return getSuitableAlgFromCurve(k.Curve)

		case *rsa.PrivateKey:
			return jwt.PS512, nil

		case *rsa.PublicKey:
			return jwt.PS512, nil
		}
	}

	return jwt.NONE, errors.New("cannot determine key type")
}
func getAlgFromKeyData ( pem pemutil . Store ) ( jwt . Algorithm , error ) { for _ , v := range pem { // loop over crypto primitives in pemstore, and do type assertion. if // ecdsa.{PublicKey,PrivateKey} found, then use corresponding ESXXX as // algo. if rsa, then use DefaultRSAAlgorithm. if []byte, then use // DefaultHMACAlgorithm. switch k := v . ( type ) { case [ ] byte : return jwt . HS512 , nil case * ecdsa . PrivateKey : return getSuitableAlgFromCurve ( k . Curve ) case * ecdsa . PublicKey : return getSuitableAlgFromCurve ( k . Curve ) case * rsa . PrivateKey : return jwt . PS512 , nil case * rsa . PublicKey : return jwt . PS512 , nil } } return jwt . NONE , errors . New ( " " ) }
// getAlgFromKeyData determines the best jwt.Algorithm suitable based on the
// set of given crypto primitives in pem.
getAlgFromKeyData determines the best jwt . Algorithm suitable based on the set of given crypto primitives in pem .