Class: Epics::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/epics/signer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, doc = nil) ⇒ Signer

Returns a new instance of Signer.



4
5
6
7
# File 'lib/epics/signer.rb', line 4

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



2
3
4
# File 'lib/epics/signer.rb', line 2

def client
  @client
end

#docObject

Returns the value of attribute doc.



2
3
4
# File 'lib/epics/signer.rb', line 2

def doc
  @doc
end

Instance Method Details

#digest!Object



9
10
11
12
13
14
15
16
17
# File 'lib/epics/signer.rb', line 9

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

#digest_nodeObject



29
30
31
# File 'lib/epics/signer.rb', line 29

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

#digesterObject



37
38
39
# File 'lib/epics/signer.rb', line 37

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

#sign!Object



19
20
21
22
23
24
25
26
27
# File 'lib/epics/signer.rb', line 19

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

#signature_nodeObject



33
34
35
# File 'lib/epics/signer.rb', line 33

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