Sha256: 3896c093ad8c19f3328f88ddd757c61c7744f3637052558a5a39105af5a64bbd

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module SmartId::Api
  class ConfirmationResponse
    RUNNING_STATE = "RUNNING"
    COMPLETED_STATE = "COMPLETE"

    attr_reader :body
    
    def initialize(response_body, hashed_data)
      @body = response_body
      validate!(hashed_data)
    end

    def confirmation_running?
      state == RUNNING_STATE
    end

    def state
      @body["state"]
    end

    def end_result
      @body.dig("result", "endResult")
    end

    def document_number
      @body.dig("result", "documentNumber")
    end

    def certificate_level
      @body.dig("cert", "certificateLevel")
    end

    def certificate
      @certificate ||= SmartId::AuthenticationCertificate::Certificate.new(@body.dig("cert", "value"))
    end

    def signature_algorithm
      @body.dig("signature", "algorithm")
    end

    def signature
      @body.dig("signature", "value")
    end

    def ignored_properties
      @body["ignoredProperties"]
    end

    private
    
    def validate!(hashed_data)
      SmartId::Utils::CertificateValidator.validate!(hashed_data, signature, certificate)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smart_id-0.1.0 lib/smart_id/api/confirmation_response.rb