class NemID::Authentication::Response

Constants

PID_REGEX
RID_REGEX

Public Class Methods

new(string) click to toggle source
# File lib/nemid/authentication/response.rb, line 7
def initialize(string)
  if string.match?(/\A[A-Za-z0-9+\/\r\n]+={0,2}\z/)
    decoded_string = Base64.decode64(string)
    if decoded_string.start_with? '<?xml'
      @doc = NemID::XMLDSig::Document.new(decoded_string)
    else
      raise error(decoded_string)
    end
  elsif string.start_with? '<?xml'
    @doc = NemID::XMLDSig::Document.new(string)
  else
    raise NemID::Errors::ResponseError
  end
end

Public Instance Methods

extract_pid() click to toggle source
# File lib/nemid/authentication/response.rb, line 22
def extract_pid
  if has_pid?
    serial_number.match(PID_REGEX)[1]
  end
end
extract_pid_or_rid() click to toggle source
# File lib/nemid/authentication/response.rb, line 34
def extract_pid_or_rid
  serial_number
end
extract_rid() click to toggle source
# File lib/nemid/authentication/response.rb, line 28
def extract_rid
  if has_rid?
    serial_number.match(RID_REGEX)[1]
  end
end
has_pid?() click to toggle source
# File lib/nemid/authentication/response.rb, line 38
def has_pid?
  serial_number.match?(PID_REGEX)
end
has_rid?() click to toggle source
# File lib/nemid/authentication/response.rb, line 42
def has_rid?
  serial_number.match?(RID_REGEX)
end
user_certificate_expired?() click to toggle source
# File lib/nemid/authentication/response.rb, line 46
def user_certificate_expired?
  @doc.user_certificate_expired?
end
user_certificate_revoked?() click to toggle source
# File lib/nemid/authentication/response.rb, line 50
def user_certificate_revoked?
  @doc.user_certificate_revoked?
end
valid_certificate_chain?() click to toggle source
# File lib/nemid/authentication/response.rb, line 54
def valid_certificate_chain?
  @doc.validate_certificate_chain
end
valid_signature?() click to toggle source
# File lib/nemid/authentication/response.rb, line 67
def valid_signature?
  @doc.validate_signature
end
validate_response() click to toggle source
# File lib/nemid/authentication/response.rb, line 58
def validate_response
  raise NemID::Errors::InvalidSignature if not valid_signature?
  raise NemID::Errors::InvalidCertificateChain if not valid_certificate_chain?
  raise NemID::Errors::UserCertificateExpired if user_certificate_expired?
  raise NemID::Errors::UserCertificateRevoked if user_certificate_revoked?

  true
end

Private Instance Methods

class_exists?(class_name) click to toggle source
# File lib/nemid/authentication/response.rb, line 72
def class_exists?(class_name)
  klass = Module.const_get(class_name)
  return klass.is_a?(Class)
rescue NameError
  return false
end
error(str) click to toggle source
# File lib/nemid/authentication/response.rb, line 79
def error(str)
  klass = "NemID::Errors::#{str}Error"
  if class_exists?(klass)
    return eval(klass) 
  else
    return NemID::Errors::ResponseError
  end
end
serial_number() click to toggle source
# File lib/nemid/authentication/response.rb, line 88
def serial_number
  @serial_number ||= @doc.extract_pid_or_rid
end