Module: Spid::Saml2::Utils

Included in:
SamlParser, QueryParamsSigner, Spid::Slo::IdpRequest, Spid::Slo::Response, Spid::Sso::Response
Defined in:
lib/spid/saml2/utils.rb,
lib/spid/saml2/utils/query_params_signer.rb

Overview

:nodoc:

Defined Under Namespace

Classes: QueryParamsSigner

Instance Method Summary collapse

Instance Method Details

#certificate_from_encoded_der(der_encoded) ⇒ Object



61
62
63
64
# File 'lib/spid/saml2/utils.rb', line 61

def certificate_from_encoded_der(der_encoded)
  der = Base64.decode64(der_encoded)
  OpenSSL::X509::Certificate.new(der)
end

#decode(message) ⇒ Object



11
12
13
# File 'lib/spid/saml2/utils.rb', line 11

def decode(message)
  Base64.decode64(message)
end

#decode_and_inflate(message) ⇒ Object



33
34
35
# File 'lib/spid/saml2/utils.rb', line 33

def decode_and_inflate(message)
  inflate(decode(message))
end

#deflate(message) ⇒ Object



19
20
21
# File 'lib/spid/saml2/utils.rb', line 19

def deflate(message)
  Zlib::Deflate.deflate(message, 9)[2..-5]
end

#deflate_and_encode(message) ⇒ Object



29
30
31
# File 'lib/spid/saml2/utils.rb', line 29

def deflate_and_encode(message)
  encode(deflate(message)).delete("\n")
end

#encode(message) ⇒ Object



15
16
17
# File 'lib/spid/saml2/utils.rb', line 15

def encode(message)
  Base64.encode64(message)
end

#escaped_params(params) ⇒ Object



37
38
39
40
41
# File 'lib/spid/saml2/utils.rb', line 37

def escaped_params(params)
  params.each_with_object({}) do |(key, value), acc|
    acc[key] = CGI.escape(value)
  end
end

#escaped_query_string(params) ⇒ Object



57
58
59
# File 'lib/spid/saml2/utils.rb', line 57

def escaped_query_string(params)
  query_string(escaped_params(params))
end

#inflate(message) ⇒ Object



23
24
25
26
27
# File 'lib/spid/saml2/utils.rb', line 23

def inflate(message)
  Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(message)
rescue Zlib::DataError => _e
  message
end

#query_param(key, value) ⇒ Object



43
44
45
# File 'lib/spid/saml2/utils.rb', line 43

def query_param(key, value)
  "#{key}=#{value}"
end

#query_params(params) ⇒ Object



47
48
49
50
51
# File 'lib/spid/saml2/utils.rb', line 47

def query_params(params)
  params.map do |key, value|
    query_param(key, value)
  end
end

#query_string(params) ⇒ Object



53
54
55
# File 'lib/spid/saml2/utils.rb', line 53

def query_string(params)
  query_params(params).join("&")
end