@@ -137,7 +137,7 @@ def parse_ec_key(key)
137137 end
138138
139139 if ::JWT . openssl_3?
140- def create_ec_key ( jwk_crv , jwk_x , jwk_y , jwk_d ) # rubocop:disable Metrics/MethodLength
140+ def create_ec_key ( jwk_crv , jwk_x , jwk_y , jwk_d )
141141 curve = EC . to_openssl_curve ( jwk_crv )
142142 x_octets = decode_octets ( jwk_x )
143143 y_octets = decode_octets ( jwk_y )
@@ -147,29 +147,25 @@ def create_ec_key(jwk_crv, jwk_x, jwk_y, jwk_d) # rubocop:disable Metrics/Method
147147 OpenSSL ::BN . new ( [ 0x04 , x_octets , y_octets ] . pack ( 'Ca*a*' ) , 2 )
148148 )
149149
150- sequence = if jwk_d
151- # https://datatracker.ietf.org/doc/html/rfc5915.html
152- # ECPrivateKey ::= SEQUENCE {
153- # version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
154- # privateKey OCTET STRING,
155- # parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
156- # publicKey [1] BIT STRING OPTIONAL
157- # }
150+ if jwk_d
151+ # https://datatracker.ietf.org/doc/html/rfc5915.html
152+ # ECPrivateKey ::= SEQUENCE {
153+ # version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
154+ # privateKey OCTET STRING,
155+ # parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
156+ # publicKey [1] BIT STRING OPTIONAL
157+ # }
158158
159- OpenSSL ::ASN1 ::Sequence ( [
159+ sequence = OpenSSL ::ASN1 ::Sequence ( [
160160 OpenSSL ::ASN1 ::Integer ( 1 ) ,
161161 OpenSSL ::ASN1 ::OctetString ( OpenSSL ::BN . new ( decode_octets ( jwk_d ) , 2 ) . to_s ( 2 ) ) ,
162162 OpenSSL ::ASN1 ::ObjectId ( curve , 0 , :EXPLICIT ) ,
163163 OpenSSL ::ASN1 ::BitString ( point . to_octet_string ( :uncompressed ) , 1 , :EXPLICIT )
164164 ] )
165- else
166- OpenSSL ::ASN1 ::Sequence ( [
167- OpenSSL ::ASN1 ::Sequence ( [ OpenSSL ::ASN1 ::ObjectId ( 'id-ecPublicKey' ) , OpenSSL ::ASN1 ::ObjectId ( curve ) ] ) ,
168- OpenSSL ::ASN1 ::BitString ( point . to_octet_string ( :uncompressed ) )
169- ] )
170- end
171-
172- OpenSSL ::PKey ::EC . new ( sequence . to_der )
165+ OpenSSL ::PKey ::EC . new ( sequence . to_der )
166+ else
167+ ::JWT ::JWA ::Ecdsa . create_public_key_from_point ( point )
168+ end
173169 end
174170 else
175171 def create_ec_key ( jwk_crv , jwk_x , jwk_y , jwk_d )
0 commit comments