Class: SetecAstronomy::KeePass::GroupField

Inherits:
Object
  • Object
show all
Defined in:
lib/setec_astronomy/kee_pass/group_field.rb

Constant Summary collapse

FIELD_TYPES =
[
  [0x0, 'ignored', :null],
  [0x1, 'groupid', :int],
  [0x2, 'group_name', :string],
  [0x3, 'creation_time', :date],
  [0x4, 'lastmod_time', :date],
  [0x5, 'lastacc_time', :date],
  [0x6, 'expire_time', :date],
  [0x7, 'imageid', :int],
  [0x8, 'level', :short],
  [0x9, 'flags', :int],
  [0xFFFF, 'terminator', :null]
]
FIELD_TERMINATOR =
0xFFFF
TYPE_CODE_FIELD_SIZE =

unsigned short integer

2
DATA_LENGTH_FIELD_SIZE =

unsigned integer

4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ GroupField

Returns a new instance of GroupField.



24
25
26
27
28
# File 'lib/setec_astronomy/kee_pass/group_field.rb', line 24

def initialize(payload)
  type_code, @data_length = payload.read(TYPE_CODE_FIELD_SIZE + DATA_LENGTH_FIELD_SIZE).unpack('SI')
  @name, @data_type = _parse_type_code(type_code)
  @data = payload.read(@data_length)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'lib/setec_astronomy/kee_pass/group_field.rb', line 22

def data
  @data
end

#data_typeObject (readonly)

Returns the value of attribute data_type.



22
23
24
# File 'lib/setec_astronomy/kee_pass/group_field.rb', line 22

def data_type
  @data_type
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/setec_astronomy/kee_pass/group_field.rb', line 22

def name
  @name
end

Instance Method Details

#_parse_type_code(type_code) ⇒ Object



38
39
40
41
42
43
# File 'lib/setec_astronomy/kee_pass/group_field.rb', line 38

def _parse_type_code(type_code)
  (_, name, data_type) = FIELD_TYPES.detect do |(code, *rest)|
    code == type_code
  end
  [name, data_type]
end

#lengthObject



34
35
36
# File 'lib/setec_astronomy/kee_pass/group_field.rb', line 34

def length
  TYPE_CODE_FIELD_SIZE + DATA_LENGTH_FIELD_SIZE + @data_length
end

#terminator?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/setec_astronomy/kee_pass/group_field.rb', line 30

def terminator?
  name == 'terminator'
end