Class: XMLSecurity::BaseDocument

Inherits:
REXML::Document
  • Object
show all
Defined in:
lib/xml_security.rb

Direct Known Subclasses

Document, SignedDocument

Constant Summary collapse

C14N =
"http://www.w3.org/2001/10/xml-exc-c14n#"
DSIG =
"http://www.w3.org/2000/09/xmldsig#"
NOKOGIRI_OPTIONS =
Nokogiri::XML::ParseOptions::STRICT |
Nokogiri::XML::ParseOptions::NONET

Instance Method Summary collapse

Instance Method Details

#algorithm(element) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/xml_security.rb', line 63

def algorithm(element)
  algorithm = element
  if algorithm.is_a?(REXML::Element)
    algorithm = element.attribute("Algorithm").value
  end

  algorithm = algorithm && algorithm =~ /(rsa-)?sha(.*?)$/i && $2.to_i

  case algorithm
  when 256 then OpenSSL::Digest::SHA256
  when 384 then OpenSSL::Digest::SHA384
  when 512 then OpenSSL::Digest::SHA512
  else
    OpenSSL::Digest::SHA1
  end
end

#canon_algorithm(element) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/xml_security.rb', line 45

def canon_algorithm(element)
  algorithm = element
  if algorithm.is_a?(REXML::Element)
    algorithm = element.attribute('Algorithm').value
  end

  case algorithm
    when "http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
      Nokogiri::XML::XML_C14N_1_0
    when "http://www.w3.org/2006/12/xml-c14n11",
         "http://www.w3.org/2006/12/xml-c14n11#WithComments"
      Nokogiri::XML::XML_C14N_1_1
    else
      Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0
  end
end