// Deduces jose signature algoritm from provided key type
Deduces jose signature algoritm from provided key type
// Deduces jose signature algoritm from provided key type
func algFromKeyType(pub crypto.PublicKey) (jose.SignatureAlgorithm, error) {
	switch key := pub.(type) {
	case *rsa.PublicKey:
		switch key.Size() {
		case 256:
			return jose.RS256, nil
		case 512:
			return jose.RS512, nil
		default:
			return jose.RS256, fmt.Errorf("Failed to determine algorithm from key type: unknown RSA key size: %v", key.Size())
		}
	case *ecdsa.PublicKey:
		switch key.Curve {
		case elliptic.P224(), elliptic.P256():
			return jose.ES256, nil
		case elliptic.P384():
			return jose.ES384, nil
		case elliptic.P521():
			return jose.ES512, nil
		default:
			return jose.RS256, errors.New("Failed to determine algorithm from key type: unknown elliptic curve")
		}
	default:
		return jose.RS256, errors.New("Failed to determine algorithm from key type: unknown key type")
	}
}
func algFromKeyType ( pub crypto . PublicKey ) ( jose . SignatureAlgorithm , error ) { switch key := pub . ( type ) { case * rsa . PublicKey : switch key . Size ( ) { case 256 : return jose . RS256 , nil case 512 : return jose . RS512 , nil default : return jose . RS256 , fmt . Errorf ( " " , key . Size ( ) ) } case * ecdsa . PublicKey : switch key . Curve { case elliptic . P224 ( ) , elliptic . P256 ( ) : return jose . ES256 , nil case elliptic . P384 ( ) : return jose . ES384 , nil case elliptic . P521 ( ) : return jose . ES512 , nil default : return jose . RS256 , errors . New ( " " ) } default : return jose . RS256 , errors . New ( " " ) } }
Deduces jose signature algoritm from provided key type
Deduces jose signature algoritm from provided key type
// FUTURE: use RSA PSS: PS256 // FUTURE: use RSA PSS: PS512