<commit_before>module Saml
  class Util
    class << self
      def parse_params(url)
        query = URI.parse(url).query
        return {} unless query

        params = {}
        query.split(/[&;]/).each do |pairs|
          key, value = pairs.split('=',2)
          params[key] = value
        end

        params
      end

      def post(location, message)
        request = HTTPI::Request.new

        request.url                     = location
        request.headers['Content-Type'] = 'text/xml'
        request.body                    = message
        request.auth.ssl.cert_file      = Saml::Config.ssl_certificate_file
        request.auth.ssl.cert_key_file  = Saml::Config.ssl_private_key_file

        HTTPI.post request
      end

      def sign_xml(message, format = :xml)
        message.add_signature

        document = Xmldsig::SignedDocument.new(message.send("to_#{format}"))
        document.sign do |data, signature_algorithm|
          message.provider.sign(signature_algorithm, data)
        end
      end

      def verify_xml(message, raw_body)
        document = Xmldsig::SignedDocument.new(raw_body)

        signature_valid = document.validate do |signature, data, signature_algorithm|
          message.provider.verify(signature_algorithm, signature, data)
        end

        raise Saml::Errors::SignatureInvalid.new unless signature_valid

        message.class.parse(document.signed_nodes.first.to_xml, single: true)
      end
    end
  end
end<commit_msg>When a block is given pass it through to the sign method, instead of using the default block.<commit_after>module Saml
  class Util
    class << self
      def parse_params(url)
        query = URI.parse(url).query
        return {} unless query

        params = {}
        query.split(/[&;]/).each do |pairs|
          key, value = pairs.split('=',2)
          params[key] = value
        end

        params
      end

      def post(location, message)
        request = HTTPI::Request.new

        request.url                     = location
        request.headers['Content-Type'] = 'text/xml'
        request.body                    = message
        request.auth.ssl.cert_file      = Saml::Config.ssl_certificate_file
        request.auth.ssl.cert_key_file  = Saml::Config.ssl_private_key_file

        HTTPI.post request
      end

      def sign_xml(message, format = :xml, &block)
        message.add_signature

        document = Xmldsig::SignedDocument.new(message.send("to_#{format}"))
        if block_given?
          document.sign(&block)
        else
          document.sign do |data, signature_algorithm|
            message.provider.sign(signature_algorithm, data)
          end
        end
      end

      def verify_xml(message, raw_body)
        document = Xmldsig::SignedDocument.new(raw_body)

        signature_valid = document.validate do |signature, data, signature_algorithm|
          message.provider.verify(signature_algorithm, signature, data)
        end

        raise Saml::Errors::SignatureInvalid.new unless signature_valid

        message.class.parse(document.signed_nodes.first.to_xml, single: true)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09211775878442545, 'fraction_numerical': 0.0006331117442228553, 'mean_word_length': 2.1411530815109345, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5853262', 'n_tokens_mistral': 896, 'n_tokens_neox': 870, 'n_words': 190}