Sha256: e9d67f70cf1324969d4df2a660c1db1c0236c536dbf131cd56874bba400b97c7

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

module Saml
  module Kit
    class Signatures
      attr_reader :configuration

      def initialize(configuration:)
        @configuration = configuration
      end

      def build(reference_id)
        return nil unless configuration.sign?
        Saml::Kit::Builders::XmlSignature.new(reference_id, configuration: configuration)
      end

      def complete(raw_xml)
        return raw_xml unless configuration.sign?
        private_key = configuration.private_keys(use: :signing).last
        Xmldsig::SignedDocument.new(raw_xml).sign(private_key)
      end

      def self.sign(xml: ::Builder::XmlMarkup.new, configuration: Saml::Kit.configuration)
        signatures = Saml::Kit::Signatures.new(configuration: configuration)
        yield xml, XmlSignatureTemplate.new(xml, signatures)
        signatures.complete(xml.target!)
      end

      class XmlSignatureTemplate
        attr_reader :signatures, :xml

        def initialize(xml, signatures)
          @signatures = signatures
          @xml = xml
        end

        def template(reference_id)
          Template.new(signatures.build(reference_id)).to_xml(xml: xml)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
saml-kit-0.2.11 lib/saml/kit/signatures.rb
saml-kit-0.2.10 lib/saml/kit/signatures.rb
saml-kit-0.2.9 lib/saml/kit/signatures.rb
saml-kit-0.2.8 lib/saml/kit/signatures.rb
saml-kit-0.2.7 lib/saml/kit/signatures.rb
saml-kit-0.2.6 lib/saml/kit/signatures.rb
saml-kit-0.2.5 lib/saml/kit/signatures.rb