Class: CyberplatPKI::SignaturePacket

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Packet

save

Constructor Details

#initializeSignaturePacket

Returns a new instance of SignaturePacket.



5
6
7
8
9
# File 'lib/cyberplat_pki/signature_packet.rb', line 5

def initialize
  @metadata = nil
  @signature = nil
  @hash_msw = nil
end

Instance Attribute Details

#hash_mswObject

Returns the value of attribute hash_msw.



3
4
5
# File 'lib/cyberplat_pki/signature_packet.rb', line 3

def hash_msw
  @hash_msw
end

#metadataObject

Returns the value of attribute metadata.



3
4
5
# File 'lib/cyberplat_pki/signature_packet.rb', line 3

def 
  @metadata
end

#signatureObject

Returns the value of attribute signature.



3
4
5
# File 'lib/cyberplat_pki/signature_packet.rb', line 3

def signature
  @signature
end

Class Method Details

.load(io, context) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cyberplat_pki/signature_packet.rb', line 11

def self.load(io, context)
  version = io.readbyte
  raise "CyberplatPKI: CRYPT_ERR_INVALID_PACKET_FORMAT (unsupported signature length: #{version})" if version != 3

   = io.readbyte
  raise "CyberplatPKI: CRYPT_ERR_INVALID_PACKET_FORMAT (invalid metadata length: #{})" if  > 32

  signature = new

  signature. = io.read 

  key_algorithm, hash_algorithm = io.read(2).unpack("CC")
  raise "CyberplatPKI: CRYPT_ERR_INVALID_PACKET_FORMAT (invalid public key algorithm: #{key_algorithm})" if key_algorithm != 0x01
  raise "CyberplatPKI: CRYPT_ERR_INVALID_PACKET_FORMAT (invalid hash key algorithm: #{key_algorithm})" if hash_algorithm != 0x01

  signature.hash_msw = io.read(2)
  signature_bits, = io.read(2).unpack("n")
  signature.signature = io.read (signature_bits + 7) / 8

  signature
end

Instance Method Details

#save(io, context) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/cyberplat_pki/signature_packet.rb', line 33

def save(io, context)
  io.write [ 3, .length ].pack "CC"
  io.write 
  io.write [ 1, 1 ].pack "CC"
  io.write hash_msw

  bn = OpenSSL::BN.new signature, 2
  io.write_mpi bn
end