Class: MooTool::Models::IMG4::IMG4Payload
- Inherits:
-
Object
- Object
- MooTool::Models::IMG4::IMG4Payload
- Includes:
- Helpers::IMG4
- Defined in:
- lib/mootool/models/img4/img4_payload.rb
Constant Summary collapse
- KEYBAG_TYPES =
{ 1 => :PROD, 2 => :DEV }.freeze
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
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #hashes ⇒ Object
-
#initialize(input) ⇒ IMG4Payload
constructor
A new instance of IMG4Payload.
- #inspect ⇒ Object
- #parse_keybag(input) ⇒ Object
- #to_bytes ⇒ Object
- #to_h ⇒ Object
Methods included from Helpers::IMG4
#construct, #construct_object, #decode_construct, parse_4cc
Constructor Details
#initialize(input) ⇒ IMG4Payload
Returns a new instance of IMG4Payload.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 16 def initialize(input) @input = input @type = input.value[1].value @description = input.value[2].value @payload = MooTool::Models::Decompressor.new(input.value[3].value, @type) @keybag = parse_keybag(input.value[4]) if input.value[4] return unless input.value[5] @extensions = construct(input.value[5]).map do |extension| { extension[0] => extension[1].map(&:to_h).reduce({}, :merge) } end.reduce(&:merge) end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
9 10 11 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 9 def payload @payload end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
9 10 11 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 9 def signature @signature end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 9 def type @type end |
Instance Method Details
#hashes ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 58 def hashes results = [OpenSSL::Digest::SHA384.digest(to_bytes)] @payload.hashes.each do |hash| results << hash end results.uniq.map { |h| Models::Digest.create(h) } end |
#inspect ⇒ Object
50 51 52 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 50 def inspect to_h.ai end |
#parse_keybag(input) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 30 def parse_keybag(input) value = construct(OpenSSL::ASN1.decode(input)) return value unless value.is_a? Array return value unless value.all?(OpenSSL::ASN1) value.map do |keybag| iv = Models::Digest.create(keybag[1].raw, 'IV') { KEYBAG_TYPES[keybag[0]] => { iv: iv, key: keybag[2] } } end.reduce(&:merge) end |
#to_bytes ⇒ Object
54 55 56 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 54 def to_bytes @input.to_der end |
#to_h ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/mootool/models/img4/img4_payload.rb', line 42 def to_h result = { type: @type, description: @description, payload: @payload } result[:keybag] = @keybag if @keybag result[:extensions] = @extensions if @extensions result end |