           response = { response_header }
           cb_wf new Error("SAML Response was not success!") unless check_status_success(saml_response)
           switch
-            when saml_response.getElementsByTagNameNS(xmlns.samlp, 'Response').length is 1
+            when saml_response.getElementsByTagNameNS(XMLNS.SAMLP, 'Response').length is 1
               response.type = 'authn_response'
               parse_authn_response saml_response, @private_key, identity_provider.certificate, cb_wf
-            when saml_response.getElementsByTagNameNS(xmlns.samlp, 'LogoutResponse').length is 1
+            when saml_response.getElementsByTagNameNS(XMLNS.SAMLP, 'LogoutResponse').length is 1
               response.type = 'logout_response'
               setImmediate cb_wf, null, {}
         (result, cb_wf) ->

  cb = _.wrap cb, (fn, err, args...) -> setTimeout (-> fn to_error(err), args...), 0

  try
    encrypted_assertion = dom.getElementsByTagNameNS(xmlns.saml, 'EncryptedAssertion')
    return cb new Error("Expected 1 EncryptedAssertion; found #{encrypted_assertion.length}.") unless encrypted_assertion.length is 1

    encrypted_data = encrypted_assertion[0].getElementsByTagNameNS(xmlns.xenc, 'EncryptedData')
    return cb new Error("Expected 1 EncryptedData inside EncryptedAssertion; found #{encrypted_data.length}.") unless encrypted_data.length is 1

    xmlenc.decrypt encrypted_data[0].toString(), (key: format_pem(private_key, 'PRIVATE KEY')), cb

xmlenc        = require 'xml-encryption'
zlib          = require 'zlib'

XMLNS =
  SAML: 'urn:oasis:names:tc:SAML:2.0:assertion'
  SAMLP: 'urn:oasis:names:tc:SAML:2.0:protocol'
  MD: 'urn:oasis:names:tc:SAML:2.0:metadata'
  DS: 'http://www.w3.org/2000/09/xmldsig#'
  XENC: 'http://www.w3.org/2001/04/xmlenc#'

# Creates an AuthnRequest and returns it as a string of xml along with the randomly generated ID for the created
# request.
