Sha256: c556c14ccb40035393a6e18d708bd9870588798b3a1c9f21e861d34d95463fd1

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module Xmldsig
  class Canonicalizer
    class UnsupportedException < Xmldsig::Error
    end
    attr_accessor :node, :method, :inclusive_namespaces, :with_comments

    def initialize(node, method = nil, inclusive_namespaces = [], with_comments = false)
      @node                 = node
      @method               = method
      @inclusive_namespaces = inclusive_namespaces
      @with_comments        = with_comments
    end

    def canonicalize
      node.canonicalize(mode(method), inclusive_namespaces, with_comments)
    end

    private

    def mode(method)
      if RUBY_PLATFORM == "java"
        case method
          when "http://www.w3.org/2001/10/xml-exc-c14n#",
              "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
            Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0
          else
            raise UnsupportedException.new("Canonicalizer method #{method} unsupported in JRuby")
        end
      else
        case method
          when "http://www.w3.org/2001/10/xml-exc-c14n#",
              "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
            Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0
          when "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
            Nokogiri::XML::XML_C14N_1_0
          when "http://www.w3.org/2006/12/xml-c14n11"
            Nokogiri::XML::XML_C14N_1_1
          else
            Nokogiri::XML::XML_C14N_1_0
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xmldsig-0.5.0 lib/xmldsig/canonicalizer.rb