Class: OnePass::Opdata

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

Defined Under Namespace

Classes: InvalidException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buf, key, mac) ⇒ Opdata

Returns a new instance of Opdata.



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

def initialize(buf, key, mac)
  if buf[0..7] != "opdata01"
    raise OnePass::Opdata::InvalidException.new("Header was incorrect")
  end
  @length = buf[8..15].unpack("Q<")[0]
  @mac = buf[-32..-1]
  if OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, mac, buf[0..-33]) != @mac
    raise OnePass::VerifyException.new("MAC doesn't match; verify failed. Check your encryption/mac keys.")
  end
  @data = decrypt(buf[16..-33], key)[-1*@length..-1]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/OnePass.rb', line 13

def data
  @data
end