Class: Keepassx::EntryField
- Inherits:
-
Object
- Object
- Keepassx::EntryField
- Defined in:
- lib/keepassx/entry_field.rb
Constant Summary collapse
- FIELD_TYPES =
[ [0x0, 'ignored', :null], [0x1, 'uuid', :ascii], [0x2, 'groupid', :int], [0x3, 'imageid', :int], [0x4, 'title', :string], [0x5, 'url', :string], [0x6, 'username', :string], [0x7, 'password', :string], [0x8, 'notes', :string], [0x9, 'creation_time', :date], [0xa, 'last_mod_time', :date], [0xb, 'last_acc_time', :date], [0xc, 'expiration_time', :date], [0xd, 'binary_desc', :string], [0xe, 'binary_data', :shunt], [0xFFFF, 'terminator', :nil] ]
- FIELD_TERMINATOR =
0xFFFF
- TYPE_CODE_FIELD_SIZE =
unsigned short integer
2
- DATA_LENGTH_FIELD_SIZE =
unsigned integer
4
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #_parse_type_code(type_code) ⇒ Object
-
#initialize(payload) ⇒ EntryField
constructor
A new instance of EntryField.
- #length ⇒ Object
- #terminator? ⇒ Boolean
Constructor Details
#initialize(payload) ⇒ EntryField
Returns a new instance of EntryField.
28 29 30 31 32 |
# File 'lib/keepassx/entry_field.rb', line 28 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
#data ⇒ Object (readonly)
Returns the value of attribute data.
26 27 28 |
# File 'lib/keepassx/entry_field.rb', line 26 def data @data end |
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
26 27 28 |
# File 'lib/keepassx/entry_field.rb', line 26 def data_type @data_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/keepassx/entry_field.rb', line 26 def name @name end |
Instance Method Details
#_parse_type_code(type_code) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/keepassx/entry_field.rb', line 42 def _parse_type_code(type_code) (_, name, data_type) = FIELD_TYPES.detect do |(code, *rest)| code == type_code end [name, data_type] end |
#length ⇒ Object
38 39 40 |
# File 'lib/keepassx/entry_field.rb', line 38 def length TYPE_CODE_FIELD_SIZE + DATA_LENGTH_FIELD_SIZE + @data_length end |
#terminator? ⇒ Boolean
34 35 36 |
# File 'lib/keepassx/entry_field.rb', line 34 def terminator? name == 'terminator' end |