class OAuth::Signature::RSA::SHA1
Public Instance Methods
==(other)
click to toggle source
# File lib/oauth/signature/rsa/sha1.rb 11 def ==(other) 12 decoded = Base64.decode64(other.is_a?(Array) ? other.first : other) 13 public_key.verify(OpenSSL::Digest.new("SHA1"), decoded, signature_base_string) 14 rescue OpenSSL::PKey::PKeyError 15 private_key = private_key_from_consumer_secret 16 raise unless private_key 17 18 private_key.sign(OpenSSL::Digest.new("SHA1"), signature_base_string) == decoded 19 end
body_hash()
click to toggle source
# File lib/oauth/signature/rsa/sha1.rb 34 def body_hash 35 # Use SHA1 body hash with compatibility across OpenSSL versions 36 data = request.body || "" 37 begin 38 digest_bytes = OpenSSL::Digest.digest("SHA1", data) 39 rescue 40 digest_bytes = ::Digest::SHA1.digest(data) 41 end 42 Base64.encode64(digest_bytes).chomp.delete("\n") 43 end
public_key()
click to toggle source
# File lib/oauth/signature/rsa/sha1.rb 21 def public_key 22 case consumer_secret 23 when String 24 decode_public_key 25 when OpenSSL::X509::Certificate 26 consumer_secret.public_key 27 when OpenSSL::PKey::RSA 28 consumer_secret.public_key 29 else 30 consumer_secret 31 end 32 end
Private Instance Methods
decode_public_key()
click to toggle source
# File lib/oauth/signature/rsa/sha1.rb 47 def decode_public_key 48 case consumer_secret 49 when /-----BEGIN CERTIFICATE-----/ 50 OpenSSL::X509::Certificate.new(consumer_secret).public_key 51 else 52 OpenSSL::PKey::RSA.new(consumer_secret).public_key 53 end 54 end
digest()
click to toggle source
# File lib/oauth/signature/rsa/sha1.rb 67 def digest 68 private_key = OpenSSL::PKey::RSA.new( 69 if options[:private_key_file] 70 File.read(options[:private_key_file]) 71 elsif options[:private_key] 72 options[:private_key] 73 else 74 consumer_secret 75 end 76 ) 77 78 private_key.sign(OpenSSL::Digest.new("SHA1"), signature_base_string) 79 end
private_key_from_consumer_secret()
click to toggle source
# File lib/oauth/signature/rsa/sha1.rb 56 def private_key_from_consumer_secret 57 case consumer_secret 58 when String 59 return nil if consumer_secret =~ /-----BEGIN CERTIFICATE-----/ 60 61 OpenSSL::PKey::RSA.new(consumer_secret) 62 when OpenSSL::PKey::RSA 63 consumer_secret 64 end 65 end