Module: Omnizip::Password
- Defined in:
- lib/omnizip/password.rb,
lib/omnizip/password/password_validator.rb,
lib/omnizip/password/encryption_registry.rb,
lib/omnizip/password/encryption_strategy.rb,
lib/omnizip/password/winzip_aes_strategy.rb,
lib/omnizip/password/zip_crypto_strategy.rb
Overview
Password protection module Provides encryption and password validation for archives
Defined Under Namespace
Classes: EncryptionRegistry, EncryptionStrategy, PasswordValidator, WinzipAesStrategy, ZipCryptoStrategy
Class Method Summary collapse
-
.create_strategy(method, password, **options) ⇒ EncryptionStrategy
Create encryption strategy.
-
.encryption_methods ⇒ Array<Symbol>
Get available encryption methods.
-
.from_env(var_name = "OMNIZIP_PASSWORD") ⇒ String?
Read password from environment variable.
-
.from_file(file_path) ⇒ String
Read password from file.
-
.prompt(confirm: true) ⇒ String
Prompt for password (with confirmation).
-
.strength(password) ⇒ Symbol
Check password strength.
-
.validate(password, **options) ⇒ Boolean
Validate a password.
Class Method Details
.create_strategy(method, password, **options) ⇒ EncryptionStrategy
Create encryption strategy
37 38 39 |
# File 'lib/omnizip/password.rb', line 37 def create_strategy(method, password, **) EncryptionRegistry.create(method, password, **) end |
.encryption_methods ⇒ Array<Symbol>
Get available encryption methods
43 44 45 |
# File 'lib/omnizip/password.rb', line 43 def encryption_methods EncryptionRegistry.strategies end |
.from_env(var_name = "OMNIZIP_PASSWORD") ⇒ String?
Read password from environment variable
73 74 75 |
# File 'lib/omnizip/password.rb', line 73 def from_env(var_name = "OMNIZIP_PASSWORD") ENV.fetch(var_name, nil) end |
.from_file(file_path) ⇒ String
Read password from file
80 81 82 |
# File 'lib/omnizip/password.rb', line 80 def from_file(file_path) File.read(file_path).strip end |
.prompt(confirm: true) ⇒ String
Prompt for password (with confirmation)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/omnizip/password.rb', line 50 def prompt(confirm: true) require "io/console" print "Enter password: " password = $stdin.noecho(&:gets).chomp puts if confirm print "Confirm password: " confirmation = $stdin.noecho(&:gets).chomp puts unless password == confirmation raise PasswordError, "Passwords do not match" end end password end |
.strength(password) ⇒ Symbol
Check password strength
27 28 29 30 |
# File 'lib/omnizip/password.rb', line 27 def strength(password) validator = PasswordValidator.new validator.strength_label(password) end |
.validate(password, **options) ⇒ Boolean
Validate a password
19 20 21 22 |
# File 'lib/omnizip/password.rb', line 19 def validate(password, **) validator = PasswordValidator.new(**) validator.validate(password) end |