Sha256: fa4755935ff8c0cd0ec6dee93e384f4d22a1e82ee570dc6bfb74d5c740f1cc7c

Contents?: true

Size: 1009 Bytes

Versions: 19

Compression:

Stored size: 1009 Bytes

Contents

module Scrivito

module BinaryParamVerifier
  InvalidSignature = Class.new(StandardError)

  class << self
    def verify(params)
      params = message_verifier.verify(params)
      expires = DateAttribute.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] = DateAttribute.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

19 entries across 19 versions & 1 rubygems

Version Path
scrivito_sdk-1.2.0 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.2.0.rc3 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.2.0.rc2 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.2.0.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.1.1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.1.0 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.1.0.rc3 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.1.0.rc2 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.1.0.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.0.0 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.0.0.rc4 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.0.0.rc3 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.0.0.rc2 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-1.0.0.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-0.90.0 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-0.90.0.rc3 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-0.90.0.rc2 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-0.90.0.rc1 lib/scrivito/binary_param_verifier.rb
scrivito_sdk-0.71.2 lib/scrivito/binary_param_verifier.rb