Sha256: b80717a8608dec7dd3e5af43a78bcd56346c20a17edb5591e763fea9ead1a148

Contents?: true

Size: 747 Bytes

Versions: 2

Compression:

Stored size: 747 Bytes

Contents

require 'openssl'
require_relative 'config.rb'

module DocJuan
  class NoSecretGivenError < StandardError; end

  class Token
    def initialize url_generator
      @url_generator = url_generator

      raise NoSecretGivenError if secret == ''
    end

    def key
      sha1 = OpenSSL::Digest::Digest.new 'sha1'
      OpenSSL::HMAC.hexdigest sha1, secret, seed
    end

    def secret
      DocJuan.config.secret.to_s.strip
    end

    def seed
      seed = []
      seed << "filename:#{@url_generator.filename}"
      seed << "format:#{@url_generator.format}"
      Hash[(@url_generator.options).sort].each do |k,v|
        seed << "options_#{k}:#{v}"
      end
      seed << "url:#{@url_generator.url}"

      seed.join '-'
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doc_juan-1.2.1 lib/doc_juan/token.rb
doc_juan-1.2.0 lib/doc_juan/token.rb