Class: CyberplatPKI::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberplat_pki/packet.rb

Direct Known Subclasses

KeyPacket, SignaturePacket, TrustPacket, UserIdPacket

Class Method Summary collapse

Class Method Details

.load(source, password = nil) ⇒ Object



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

def self.load(source, password = nil)
  io = StringIO.new source, "rb"
  io.extend PacketIORoutines

  packets = []

  until io.eof?
    begin
      packets << io.read_packet(password)
    rescue EOFError => e
      raise "CyberplatPKI: CRYPT_ERR_INVALID_PACKET_FORMAT (unexpected end of packet)"
    end
  end

  packets
end

.save(packets, password = nil) ⇒ Object



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

def self.save(packets, password = nil)
  io = StringIO.new '', "wb"
  io.extend PacketIORoutines

  packets.each { |packet| io.write_packet packet, password }

  io.string
end