Module: CyberplatPKI::Key::Helpers

Defined in:
lib/cyberplat_pki/key.rb

Class Method Summary collapse

Class Method Details

.find_record(list, record_class) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/cyberplat_pki/key.rb', line 22

def self.find_record(list, record_class)
  record = list.find { |record| record.kind_of? record_class }

  raise "CyberplatPKI: CRYPT_ERR_INVALID_PACKET_FORMAT (#{record_class.name} not found in the document)" if record.nil?

  record
end

.key_from_document_set(list, type, serial, password = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cyberplat_pki/key.rb', line 6

def self.key_from_document_set(list, type, serial, password = nil)
  document = list.find do |doc|
    doc.type == type && (serial == 0 || doc.subject.key_serial == serial)
  end

  raise "CyberplatPKI: CRYPT_ERR_PUB_KEY_NOT_FOUND (key with specified serial has not been found in the document)" if document.nil?

  key = Key.new
  key.serial    = document.subject.key_serial
  key.name      = document.subject.key_name
  key.packets   = Packet.load Document.decode64(document.body), password
  key.signature = Packet.load Document.decode64(document.signature), password

  [ key, document ]
end