cmd/jwt/main.go
func getSuitableAlgFromCurve(curve elliptic.Curve) (jwt.Algorithm, error) {
	curveBitSize := curve.Params().BitSize

	// compute curve key len
	keyLen := curveBitSize / 8
	if curveBitSize%8 > 0 {
		keyLen++
	}

	// determine alg
	var alg jwt.Algorithm
	switch 2 * keyLen {
	case 64:
		alg = jwt.ES256
	case 96:
		alg = jwt.ES384
	case 132:
		alg = jwt.ES512

	default:
		return jwt.NONE, fmt.Errorf("invalid key length %d", keyLen)
	}

	return alg, nil
}
func getSuitableAlgFromCurve(curve elliptic.Curve) (jwt.Algorithm, error) {
	curveBitSize := curve.Params().BitSize

	// compute curve key len
	keyLen := curveBitSize / 8
	if curveBitSize%8 > 0 {
		keyLen++
	}

	// determine alg
	var alg jwt.Algorithm
	switch 2 * keyLen {
	case 64:
		alg = jwt.ES256
	case 96:
		alg = jwt.ES384
	case 132:
		alg = jwt.ES512

	default:
		return jwt.NONE, fmt.Errorf("invalid key length %d", keyLen)
	}

	return alg, nil
}
func getSuitableAlgFromCurve ( curve elliptic . Curve ) ( jwt . Algorithm , error ) { curveBitSize := curve . Params ( ) . BitSize // compute curve key len keyLen := curveBitSize / 8 if curveBitSize % 8 > 0 { keyLen ++ } // determine alg var alg jwt . Algorithm switch 2 * keyLen { case 64 : alg = jwt . ES256 case 96 : alg = jwt . ES384 case 132 : alg = jwt . ES512 default : return jwt . NONE , fmt . Errorf ( " " , keyLen ) } return alg , nil }
// getSuitableAlgFromCurve inspects the key length in curve, and determines the
// corresponding jwt.Algorithm.
getSuitableAlgFromCurve inspects the key length in curve and determines the corresponding jwt . Algorithm .