Sha256: 59126a79f4575fd259b6ef660af3166e83135f2f90ac1623affc0060934e7876

Contents?: true

Size: 1.12 KB

Versions: 19

Compression:

Stored size: 1.12 KB

Contents

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

module OAuth::Signature::RSA
  class SHA1 < OAuth::Signature::Base
    implements 'rsa-sha1'
    hash_class ::Digest::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

19 entries across 18 versions & 8 rubygems

Version Path
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/oauth-0.4.7/lib/oauth/signature/rsa/sha1.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/oauth-0.4.7/lib/oauth/signature/rsa/sha1.rb
oauth-ap-0.4.8 lib/oauth/signature/rsa/sha1.rb
oauth-instructure-0.4.10 lib/oauth/signature/rsa/sha1.rb
oauth_weshays-0.4.8.pre2 lib/oauth/signature/rsa/sha1.rb
oauth_weshays-0.4.8.pre lib/oauth/signature/rsa/sha1.rb
oauth-instructure-0.4.9 lib/oauth/signature/rsa/sha1.rb
oauth-instructure-0.4.8 lib/oauth/signature/rsa/sha1.rb
oauth-0.4.7 lib/oauth/signature/rsa/sha1.rb
motionbox-oauth-0.4.5 lib/oauth/signature/rsa/sha1.rb
oauth-0.4.6 lib/oauth/signature/rsa/sha1.rb
oauth-0.4.5 lib/oauth/signature/rsa/sha1.rb
sayso-oauth-0.4.4.001 lib/oauth/signature/rsa/sha1.rb
oauth-0.4.4 lib/oauth/signature/rsa/sha1.rb
oauth-0.4.3 lib/oauth/signature/rsa/sha1.rb
oauth-0.4.2 lib/oauth/signature/rsa/sha1.rb
apigee-oauth-0.4.0 lib/oauth/signature/rsa/sha1.rb
oauth-0.4.1 lib/oauth/signature/rsa/sha1.rb
oauth-0.4.0 lib/oauth/signature/rsa/sha1.rb