Class: Keepassx::GroupField

Inherits:
Object
  • Object
show all
Defined in:
lib/keepassx/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.



23
24
25
26
27
# File 'lib/keepassx/group_field.rb', line 23

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.



21
22
23
# File 'lib/keepassx/group_field.rb', line 21

def data
  @data
end

#data_typeObject (readonly)

Returns the value of attribute data_type.



21
22
23
# File 'lib/keepassx/group_field.rb', line 21

def data_type
  @data_type
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/keepassx/group_field.rb', line 21

def name
  @name
end

Instance Method Details

#_parse_type_code(type_code) ⇒ Object



37
38
39
40
41
42
# File 'lib/keepassx/group_field.rb', line 37

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

#lengthObject



33
34
35
# File 'lib/keepassx/group_field.rb', line 33

def length
  TYPE_CODE_FIELD_SIZE + DATA_LENGTH_FIELD_SIZE + @data_length
end

#terminator?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/keepassx/group_field.rb', line 29

def terminator?
  name == 'terminator'
end