Sha256: 307dedc31402845b591701482b8b969343030037a752a648bc1a17f7c06f6658

Contents?: true

Size: 567 Bytes

Versions: 21

Compression:

Stored size: 567 Bytes

Contents

module AmazonAuth
  class Converter

    def initialize(salt)
      @salt = salt
    end

    def encode(str)
      raise "Empty string" if str.to_s.size == 0
      Base64.strict_encode64("#{salt}#{str}")
    end

    def salt
      @salt || self.class.salt
    end

    def self.decode(code)
      raise "Empty string" if code.to_s.size == 0
      Base64.strict_decode64(code).gsub(/\A#{salt}/, '')
    end

    def self.salt
      ENV['AMAZON_CODE_SALT'].presence || raise('salt is missing')
    end

    def self.default_salt
      "iloveamazon"
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
amazon_auth-0.7.0 lib/amazon_auth/converter.rb
amazon_auth-0.6.0 lib/amazon_auth/converter.rb
amazon_auth-0.5.0 lib/amazon_auth/converter.rb
amazon_auth-0.4.6 lib/amazon_auth/converter.rb
amazon_auth-0.4.5 lib/amazon_auth/converter.rb
amazon_auth-0.4.4 lib/amazon_auth/converter.rb
amazon_auth-0.4.3 lib/amazon_auth/converter.rb
amazon_auth-0.4.2 lib/amazon_auth/converter.rb
amazon_auth-0.4.1 lib/amazon_auth/converter.rb
amazon_auth-0.4.0 lib/amazon_auth/converter.rb
amazon_auth-0.3.3 lib/amazon_auth/converter.rb
amazon_auth-0.3.2 lib/amazon_auth/converter.rb
amazon_auth-0.3.1 lib/amazon_auth/converter.rb
amazon_auth-0.3.0 lib/amazon_auth/converter.rb
amazon_auth-0.2.1 lib/amazon_auth/converter.rb
amazon_auth-0.2.0 lib/amazon_auth/converter.rb
amazon_auth-0.1.5 lib/amazon_auth/converter.rb
amazon_auth-0.1.4 lib/amazon_auth/converter.rb
amazon_auth-0.1.3 lib/amazon_auth/converter.rb
amazon_auth-0.1.2 lib/amazon_auth/converter.rb