Class: OAuth::Signature::RSA::SHA1

Inherits:
Base
  • Object
show all
Defined in:
lib/oauth/signature/rsa/sha1.rb

Instance Attribute Summary

Attributes inherited from Base

#consumer_secret, #options, #request, #token_secret

Instance Method Summary collapse

Methods inherited from Base

implements, #initialize, #signature, #signature_base_string, #verify

Methods included from Helper

_escape, escape, generate_key, generate_timestamp, normalize, normalize_nested_query, parse_header, stringify_keys, unescape

Constructor Details

This class inherits a constructor from OAuth::Signature::Base

Instance Method Details

#==(other) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/oauth/signature/rsa/sha1.rb', line 11

def ==(other)
  decoded = Base64.decode64(other.is_a?(Array) ? other.first : other)
  public_key.verify(OpenSSL::Digest.new("SHA1"), decoded, signature_base_string)
rescue OpenSSL::PKey::PKeyError
  private_key = private_key_from_consumer_secret
  raise unless private_key

  private_key.sign(OpenSSL::Digest.new("SHA1"), signature_base_string) == decoded
end

#body_hashObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/oauth/signature/rsa/sha1.rb', line 34

def body_hash
  # Use SHA1 body hash with compatibility across OpenSSL versions
  data = request.body || ""
  begin
    digest_bytes = OpenSSL::Digest.digest("SHA1", data)
  rescue
    digest_bytes = ::Digest::SHA1.digest(data)
  end
  Base64.encode64(digest_bytes).chomp.delete("\n")
end

#public_keyObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oauth/signature/rsa/sha1.rb', line 21

def public_key
  case consumer_secret
  when String
    decode_public_key
  when OpenSSL::X509::Certificate
    consumer_secret.public_key
  when OpenSSL::PKey::RSA
    consumer_secret.public_key
  else
    consumer_secret
  end
end