Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Don't use key.set_key on Ruby 2.3, it is not always available on this…
Browse files Browse the repository at this point in the history
… version. (#3)

Compatibility with Ruby 2.3 was broken in commit
0963223 (a fix for 2.4).

See mastodon/mastodon#2029 .
  • Loading branch information
progval authored and Gargron committed Apr 25, 2017
1 parent d4519b6 commit e4ed441
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/ostatus2/magic_key.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
module OStatus2
module MagicKey
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4.0')
def set_key(key, modulus, exponent)
key.n = modulus
key.e = exponent
end
else
def set_key(key, modulus, exponent)
key.set_key(modulus, exponent, nil)
end
end

def magic_key_to_pem(magic_key)
_, modulus, exponent = magic_key.split('.')
modulus, exponent = [modulus, exponent].map { |n| decode_base64(n).bytes.inject(0) { |a, e| (a << 8) | e } }

key = OpenSSL::PKey::RSA.new
key.set_key(modulus, exponent, nil)
set_key(key, modulus, exponent)
key.to_pem
end

Expand Down

0 comments on commit e4ed441

Please sign in to comment.