Class: MooTool::Models::IMG4::KeyValueProperty

Inherits:
Object
  • Object
show all
Includes:
Helpers::IMG4
Defined in:
lib/mootool/models/img4/key_value_property.rb

Overview

Key/Value Properties are those with an ASN 4CC tag, and contain exactly two elements in a sequence, the first is a simple repeat of the key name as a string the second is the value of the property.

Constant Summary collapse

SPLAT_SENINEL =
:ALLOW_ANY_VALUE

Constants included from Helpers::IMG4

Helpers::IMG4::DECODE_TAGS, Helpers::IMG4::FIRMWARE_TAGS, Helpers::IMG4::HASH_LENGTHS, Helpers::IMG4::KEY_INSTANCE_TAGS, Helpers::IMG4::KVP_TAGS, Helpers::IMG4::OCTET_TAGS, Helpers::IMG4::SEQUENCE_TAGS, Helpers::IMG4::SIGNATURE_TAGS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::IMG4

#construct, #construct_object, #decode_construct, parse_4cc

Constructor Details

#initialize(input) ⇒ KeyValueProperty

Returns a new instance of KeyValueProperty.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mootool/models/img4/key_value_property.rb', line 15

def initialize(input)
  unless input.tag_class == :PRIVATE && input.is_a?(OpenSSL::ASN1::ASN1Data)
    raise 'Input must be a private instance of ASN1Data'
  end
  @key = input.tag.to_4cc

  @object = input

  unless input.value.size == 1 &&
         input.value[0].value.size == 2
    raise MooTool::Error,
          "The sequence must have two values #{input.value[0].value.size}"
  end

  construction = construct(input.value.first)

  @key = construction.first.to_sym
  @value = construction.last

  @value = @value.first if @value.is_a?(Array)

  # @value = SPLAT_SENINEL if @value.nil?
  # @value = nil if @value.is_a?(OpenSSL::ASN1::ASN1Data) && @value.value.nil?
  @value = SPLAT_SENINEL if @value.is_a?(OpenSSL::ASN1::ASN1Data) && @value.value.nil?

  return if @value == SPLAT_SENINEL

  if KEY_INSTANCE_TAGS.include?(input.tag) && !@value.nil?
    @value = MooTool::Models::Certificate.parse_sik(@value)
  end

  @value = decode_construct(@value) if DECODE_TAGS.include?(input.tag)

  if OCTET_TAGS.include?(input.tag) && !@value.is_a?(MooTool::Models::Digest)
    @value = MooTool::Models::Digest.create(@value)
  end

  return unless SIGNATURE_TAGS.include?(input.tag)

  @value = decode_construct(input.value[0].value[1].value)
rescue StandardError
  raise MooTool::Error,
        "Failure to parse KeyValueProperty: #{@key} with value #{@value} of type #{@value.class}"
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/mootool/models/img4/key_value_property.rb', line 11

def key
  @key
end

#objectObject (readonly)

Returns the value of attribute object.



11
12
13
# File 'lib/mootool/models/img4/key_value_property.rb', line 11

def object
  @object
end

#valueObject (readonly)

Returns the value of attribute value.



11
12
13
# File 'lib/mootool/models/img4/key_value_property.rb', line 11

def value
  @value
end

Instance Method Details

#inspectObject



64
65
66
# File 'lib/mootool/models/img4/key_value_property.rb', line 64

def inspect
  to_h.inspect
end

#to_hObject



60
61
62
# File 'lib/mootool/models/img4/key_value_property.rb', line 60

def to_h
  { @key => @value }
end