Sha256: c8f418b97c393dd34b565e328da1e369a9afd6412909d1bcf059fd0f50e86a55

Contents?: true

Size: 851 Bytes

Versions: 29

Compression:

Stored size: 851 Bytes

Contents

class Epics::Signer
  attr_accessor :doc, :client

  def initialize(client, doc = nil)
    self.doc = Nokogiri::XML.parse(doc) if doc
    self.client = client
  end

  def digest!
    content_to_digest = Base64.encode64(digester.digest(doc.xpath("//*[@authenticate='true']").map(&:canonicalize).join)).strip

    if digest_node
      digest_node.content = content_to_digest
    end

    doc
  end

  def sign!
    signature_value_node = doc.xpath("//ds:SignatureValue").first

    if signature_node
      signature_value_node.content = Base64.encode64(client.x.key.sign(digester, signature_node.canonicalize)).gsub(/\n/,'')
    end

    doc
  end

  def digest_node
    @d ||= doc.xpath("//ds:DigestValue").first
  end

  def signature_node
    @s ||= doc.xpath("//ds:SignedInfo").first
  end

  def digester
    OpenSSL::Digest::SHA256.new
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
epics-2.6.0 lib/epics/signer.rb
epics-2.5.0 lib/epics/signer.rb
epics-2.4.0 lib/epics/signer.rb
epics-2.3.0 lib/epics/signer.rb
epics-2.2.0 lib/epics/signer.rb
epics-2.1.2 lib/epics/signer.rb
epics-2.1.1 lib/epics/signer.rb
epics-2.1.0 lib/epics/signer.rb
epics-2.0.0 lib/epics/signer.rb
epics-1.8.1 lib/epics/signer.rb
epics-1.8.0 lib/epics/signer.rb
epics-1.7.2 lib/epics/signer.rb
epics-1.7.1 lib/epics/signer.rb
epics-1.7.0 lib/epics/signer.rb
epics-1.6.0 lib/epics/signer.rb
epics-1.5.2 lib/epics/signer.rb
epics-1.5.1 lib/epics/signer.rb
epics-1.5.0 lib/epics/signer.rb
epics-1.4.1 lib/epics/signer.rb
epics-1.4.0 lib/epics/signer.rb