Class: Zip::ExtraField::AES

Inherits:
Generic
  • Object
show all
Defined in:
lib/zip/extra_field/aes.rb

Overview

Info-ZIP Extra for AES encryption

Constant Summary collapse

HEADER_ID =
[0x9901].pack('v')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#initial_parse, name, register_map, #to_c_dir_bin, #to_local_bin

Constructor Details

#initialize(binstr = nil) ⇒ AES

Returns a new instance of AES.



11
12
13
14
15
16
17
# File 'lib/zip/extra_field/aes.rb', line 11

def initialize(binstr = nil)
  @vendor_version = nil
  @vendor_id = nil
  @encryption_strength = nil
  @compression_method = nil
  binstr && merge(binstr)
end

Instance Attribute Details

#compression_methodObject (readonly)

:nodoc:



6
7
8
# File 'lib/zip/extra_field/aes.rb', line 6

def compression_method
  @compression_method
end

#encryption_strengthObject (readonly)

:nodoc:



6
7
8
# File 'lib/zip/extra_field/aes.rb', line 6

def encryption_strength
  @encryption_strength
end

#vendor_idObject (readonly)

:nodoc:



6
7
8
# File 'lib/zip/extra_field/aes.rb', line 6

def vendor_id
  @vendor_id
end

#vendor_versionObject (readonly)

:nodoc:



6
7
8
# File 'lib/zip/extra_field/aes.rb', line 6

def vendor_version
  @vendor_version
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
23
24
# File 'lib/zip/extra_field/aes.rb', line 19

def ==(other)
  @vendor_version == other.vendor_version &&
    @vendor_id == other.vendor_id &&
    @encryption_strength == other.encryption_strength &&
    @compression_method == other.compression_method
end

#merge(binstr) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/zip/extra_field/aes.rb', line 26

def merge(binstr)
  return if binstr.empty?

  size, content = initial_parse(binstr)
  (size && content) || return

  @vendor_version, @vendor_id,
    @encryption_strength, @compression_method = content.unpack('va2Cv')
end

#pack_for_c_dirObject



41
42
43
# File 'lib/zip/extra_field/aes.rb', line 41

def pack_for_c_dir
  pack_for_local
end

#pack_for_localObject



36
37
38
39
# File 'lib/zip/extra_field/aes.rb', line 36

def pack_for_local
  [@vendor_version, @vendor_id,
   @encryption_strength, @compression_method].pack('va2Cv')
end