Sha256: f9699b966977660cdd42e36eee0ce4bce9d5fc1ddecb4d1645c768f7c80694fb

Contents?: true

Size: 575 Bytes

Versions: 6

Compression:

Stored size: 575 Bytes

Contents

require 'openssl'
require 'base64'

module Stream
    class Signer
        @key = nil

        def initialize(key)
            @key = key.to_s
            @sha1 = OpenSSL::Digest.new('sha1')
        end

        def urlSafeB64encode(value)
            value.gsub('+', '-').gsub('/', '_').gsub(/^=+/, '').gsub(/=+$/, '')
        end

        def signature(message)
            key = Digest::SHA1.digest @key.to_s
            signature = Base64.strict_encode64(OpenSSL::HMAC.digest(@sha1, key, message.to_s))
            self.urlSafeB64encode(signature)
        end
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stream-ruby-1.0.5 lib/stream/signer.rb
stream-ruby-1.0.4 lib/stream/signer.rb
stream-ruby-1.0.3 lib/stream/signer.rb
stream-ruby-1.0.2 lib/stream/signer.rb
stream-ruby-1.0.0 lib/stream/signer.rb
stream-ruby-0.8.2 lib/stream/signer.rb