Sha256: 3a5a9a40e03bdb615c38dd033fb58d00350fbc3e62e1ab6eebeebc6642d3da2b

Contents?: true

Size: 1.09 KB

Versions: 40

Compression:

Stored size: 1.09 KB

Contents

require 'oauth/signature/base'
require 'openssl'

module OAuth::Signature::RSA
  class SHA1 < OAuth::Signature::Base
    implements 'rsa-sha1'

    def ==(cmp_signature)
      public_key.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(cmp_signature.is_a?(Array) ? cmp_signature.first : cmp_signature), signature_base_string)
    end

    def public_key
      if consumer_secret.is_a?(String)
        decode_public_key
      elsif consumer_secret.is_a?(OpenSSL::X509::Certificate)
        consumer_secret.public_key
      else
        consumer_secret
      end
    end

  private

    def decode_public_key
      case consumer_secret
      when /-----BEGIN CERTIFICATE-----/
        OpenSSL::X509::Certificate.new( consumer_secret).public_key
      else
        OpenSSL::PKey::RSA.new( consumer_secret)
      end
    end

    def digest
      private_key = OpenSSL::PKey::RSA.new(
        if options[:private_key_file]
          IO.read(options[:private_key_file])
        else
          consumer_secret
        end
      )

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

Version data entries

40 entries across 40 versions & 17 rubygems

Version Path
greut-oauth-0.3.6 lib/oauth/signature/rsa/sha1.rb
jwhitmire-oauth-0.3.6.1 lib/oauth/signature/rsa/sha1.rb
metavida-oauth-0.3.2.1 lib/oauth/signature/rsa/sha1.rb
metavida-oauth-0.3.2 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.1.1 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.1.2 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.1.3 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.1.4 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.1.5 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.1.6 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.1.7 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.1.8 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.2.1 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.2.2 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.2 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.3 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.4.1 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.4 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.5 lib/oauth/signature/rsa/sha1.rb
mojodna-oauth-0.3.6 lib/oauth/signature/rsa/sha1.rb