Sha256: 6944450c488a992612f153c39b6f222bac8f6eeb0397681f15a3e94fe20786ed

Contents?: true

Size: 1011 Bytes

Versions: 28

Compression:

Stored size: 1011 Bytes

Contents

module Scrivito

module BinaryParamVerifier
  InvalidSignature = Class.new(StandardError)

  class << self
    def verify(params)
      params = message_verifier.verify(params)
      expires = DateConversion.deserialize_from_backend(params['expires'])
      raise InvalidSignature if expires && expires < Time.zone.now
      Binary.new(params['binary_id'], expires.nil?,
          transformation_definition: params['transformation_definition'])
    rescue ActiveSupport::MessageVerifier::InvalidSignature
      raise InvalidSignature
    end

    def generate(binary)
      params = {binary_id: binary.id, transformation_definition: binary.transformation_definition}
      if binary.private?
        params[:expires] = DateConversion.serialize_for_backend(Time.zone.now + 1.hour)
      end
      message_verifier.generate(params)
    end

    private

    def message_verifier
      ActiveSupport::MessageVerifier.new(
        Rails.application.secrets.secret_key_base, serializer: JSON)
    end
  end
end

end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
scrivito_sdk-1.5.5 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.5.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.4.3 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.4 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.4.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.3 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.3.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.6.0.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.2 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.2.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.1.rc2 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.1.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.0 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.0.rc2 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.5.0.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.4.2 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.4.1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.4.1.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.4.0 lib/scrivito/binary_param_verifier.rb