Class: Omnizip::Password::EncryptionStrategy
- Inherits:
-
Object
- Object
- Omnizip::Password::EncryptionStrategy
- Defined in:
- lib/omnizip/password/encryption_strategy.rb
Overview
Base class for encryption strategies Defines the interface for encrypting/decrypting archive entries
Direct Known Subclasses
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
Instance Method Summary collapse
-
#compression_method ⇒ Integer
Get encryption method ID for ZIP format.
-
#decrypt(data) ⇒ String
Decrypt data.
-
#encrypt(data) ⇒ String
Encrypt data.
-
#encryption_flags ⇒ Integer
Get encryption flags for ZIP header.
-
#extra_field_data ⇒ String
Get extra field data for ZIP header.
-
#initialize(password) ⇒ EncryptionStrategy
constructor
Initialize encryption strategy.
-
#method_name ⇒ Symbol
Get encryption method name.
-
#supports?(_data) ⇒ Boolean
Check if this strategy supports the given data.
Constructor Details
#initialize(password) ⇒ EncryptionStrategy
Initialize encryption strategy
12 13 14 15 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 12 def initialize(password) @password = password validate_password end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
8 9 10 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 8 def password @password end |
Instance Method Details
#compression_method ⇒ Integer
Get encryption method ID for ZIP format
36 37 38 39 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 36 def compression_method raise NotImplementedError, "#{self.class} must implement #compression_method" end |
#decrypt(data) ⇒ String
Decrypt data
29 30 31 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 29 def decrypt(data) raise NotImplementedError, "#{self.class} must implement #decrypt" end |
#encrypt(data) ⇒ String
Encrypt data
21 22 23 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 21 def encrypt(data) raise NotImplementedError, "#{self.class} must implement #encrypt" end |
#encryption_flags ⇒ Integer
Get encryption flags for ZIP header
49 50 51 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 49 def encryption_flags 0x0001 # Bit 0: encrypted end |
#extra_field_data ⇒ String
Get extra field data for ZIP header
43 44 45 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 43 def extra_field_data "" end |
#method_name ⇒ Symbol
Get encryption method name
62 63 64 65 66 67 68 69 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 62 def method_name self.class.name.split("::").last .gsub(/Strategy$/, "") .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase .to_sym end |
#supports?(_data) ⇒ Boolean
Check if this strategy supports the given data
56 57 58 |
# File 'lib/omnizip/password/encryption_strategy.rb', line 56 def supports?(_data) true end |