Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make JWT::JWK::EC compatible with Ruby 2.3 #386

Merged
merged 2 commits into from Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/jwt/jwk/ec.rb
Expand Up @@ -4,7 +4,7 @@ module JWT
module JWK
class EC < KeyBase
extend Forwardable
def_delegators :@keypair, :private?, :public_key
def_delegators :@keypair, :public_key

KTY = 'EC'.freeze
KTYS = [KTY, OpenSSL::PKey::EC].freeze
Expand All @@ -17,6 +17,10 @@ def initialize(keypair, kid = nil)
super(keypair, kid)
end

def private?
@keypair.private_key?
end

def export(options = {})
crv, x_octets, y_octets = keypair_components(keypair)
exported_hash = {
Expand Down
4 changes: 2 additions & 2 deletions spec/jwk/ec_spec.rb
Expand Up @@ -4,7 +4,7 @@
require 'jwt'

describe JWT::JWK::EC do
let(:ec_key) { OpenSSL::PKey::EC.new("secp384r1").generate_key! }
let(:ec_key) { OpenSSL::PKey::EC.new("secp384r1").generate_key }

describe '.new' do
subject { described_class.new(keypair) }
Expand Down Expand Up @@ -82,7 +82,7 @@
['P-256', 'P-384', 'P-521'].each do |crv|
context "when crv=#{crv}" do
let(:openssl_curve) { JWT::JWK::EC.to_openssl_curve(crv) }
let(:ec_key) { OpenSSL::PKey::EC.new(openssl_curve).generate_key! }
let(:ec_key) { OpenSSL::PKey::EC.new(openssl_curve).generate_key }

context 'when keypair is private' do
let(:include_private) { true }
Expand Down
2 changes: 1 addition & 1 deletion spec/jwk_spec.rb
Expand Up @@ -5,7 +5,7 @@

describe JWT::JWK do
let(:rsa_key) { OpenSSL::PKey::RSA.new(2048) }
let(:ec_key) { OpenSSL::PKey::EC.new("secp384r1").generate_key! }
let(:ec_key) { OpenSSL::PKey::EC.new("secp384r1").generate_key }

describe '.import' do
let(:keypair) { rsa_key.public_key }
Expand Down