Skip to content

Commit

Permalink
Support JWKs for pre 2.3 rubies
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Dec 21, 2020
1 parent 9376087 commit b94ad68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Expand Up @@ -24,10 +24,12 @@ jobs:
- gemfiles/rbnacl.gemfile
experimental: [false]
include:
# - ruby: 2.1
# experimental: true
# - ruby: 2.2
# experimental: true
- ruby: 2.1
gemfile: 'gemfiles/rbnacl.gemfile'
experimental: false
- ruby: 2.2
gemfile: 'gemfiles/rbnacl.gemfile'
experimental: false
- ruby: 2.7
coverage: "true"
gemfile: 'gemfiles/rbnacl.gemfile'
Expand Down
8 changes: 4 additions & 4 deletions lib/jwt/jwk/ec.rb
Expand Up @@ -70,11 +70,11 @@ def keypair_components(ec_keypair)
end

def encode_octets(octets)
::Base64.urlsafe_encode64(octets, padding: false)
::JWT::Base64.url_encode(octets)
end

def encode_open_ssl_bn(key_part)
::Base64.urlsafe_encode64(key_part.to_s(BINARY), padding: false)
::JWT::Base64.url_encode(key_part.to_s(BINARY))
end

class << self
Expand Down Expand Up @@ -136,11 +136,11 @@ def ec_pkey(jwk_crv, jwk_x, jwk_y, jwk_d)
end

def decode_octets(jwk_data)
::Base64.urlsafe_decode64(jwk_data)
::JWT::Base64.url_decode(jwk_data)
end

def decode_open_ssl_bn(jwk_data)
OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data), BINARY)
OpenSSL::BN.new(::JWT::Base64.url_decode(jwk_data), BINARY)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/jwt/jwk/rsa.rb
Expand Up @@ -54,7 +54,7 @@ def append_private_parts(the_hash)
end

def encode_open_ssl_bn(key_part)
::Base64.urlsafe_encode64(key_part.to_s(BINARY), padding: false)
::JWT::Base64.url_encode(key_part.to_s(BINARY))
end

class << self
Expand Down Expand Up @@ -107,7 +107,7 @@ def populate_key(rsa_key, rsa_parameters) # rubocop:disable Metrics/CyclomaticCo
def decode_open_ssl_bn(jwk_data)
return nil unless jwk_data

OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data), BINARY)
OpenSSL::BN.new(::JWT::Base64.url_decode(jwk_data), BINARY)
end
end
end
Expand Down

0 comments on commit b94ad68

Please sign in to comment.