Class: Nem::ApostilleAudit

Inherits:
Object
  • Object
show all
Defined in:
lib/nem/apostille_audit.rb

Constant Summary collapse

CHECKSUM =
'fe4e5459'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(file, apostille_hash, signer = nil) ⇒ ApostilleAudit

Returns a new instance of ApostilleAudit.

Parameters:

  • file (File)
  • Apostille (apostille_hash)

    formatted hash



11
12
13
14
15
16
# File 'lib/nem/apostille_audit.rb', line 11

def initialize(file, apostille_hash, signer = nil)
  @signer = signer
  @file = file
  @apostille_hash = apostille_hash
  @checksum, @version, @algo, @hash = split_apostille_hash
end

Instance Method Details

#signed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/nem/apostille_audit.rb', line 31

def signed?
  @version == 0x80
end

#split_apostille_hashObject



35
36
37
38
39
40
# File 'lib/nem/apostille_audit.rb', line 35

def split_apostille_hash
  [ @apostille_hash[0, 8],
    @apostille_hash[8, 1].to_i,
    @apostille_hash[9, 1].to_i,
    @apostille_hash[10, @apostille_hash.size] ]
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nem/apostille_audit.rb', line 18

def valid?
  raise "Invalid checksum: #{@checksum}" unless @checksum == CHECKSUM
  if signed? && @signer
    KeyPair.verify_signature(
      @signer,
      @hash,
      @apostille_hash
    )
  else
    @hash == calc_hash
  end
end