Class: KeePass::Password::CharSet

Inherits:
Set
  • Object
show all
Defined in:
lib/keepass/password/char_set.rb

Overview

Character sets for the KeePass password generator.

Constant Summary collapse

UPPERCASE =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LOWERCASE =
"abcdefghijklmnopqrstuvwxyz"
DIGITS =
"0123456789"
UPPER_CONSONANTS =
"BCDFGHJKLMNPQRSTVWXYZ"
LOWER_CONSONANTS =
"bcdfghjklmnpqrstvwxyz"
UPPER_VOWELS =
"AEIOU"
LOWER_VOWELS =
"aeiou"
PUNCTUATION =
",.;:"
BRACKETS =
"[]{}()<>"
PRINTABLE_ASCII_SPECIAL =
"!\"#\$%&'()*+,-./:;<=>?[\\]^_{|}~"
UPPER_HEX =
"0123456789ABCDEF"
LOWER_HEX =
"0123456789abcdef"
HIGH_ANSI =
(0x7f..0xfe).map { |i| i.chr }.join
DEFAULT_MAPPING =
{
  'a' => [LOWERCASE, DIGITS],
  'A' => [LOWERCASE, UPPERCASE, DIGITS],
  'U' => [UPPERCASE, DIGITS],
  'c' => [LOWER_CONSONANTS],
  'C' => [LOWER_CONSONANTS, UPPER_CONSONANTS],
  'z' => [UPPER_CONSONANTS],
  'd' => [DIGITS],
  'h' => [LOWER_HEX],
  'H' => [UPPER_HEX],
  'l' => [LOWERCASE],
  'L' => [LOWERCASE, UPPERCASE],
  'u' => [UPPERCASE],
  'p' => [PUNCTUATION],
  'b' => [BRACKETS],
  's' => [PRINTABLE_ASCII_SPECIAL],
  'S' => [UPPERCASE, LOWERCASE, DIGITS, PRINTABLE_ASCII_SPECIAL],
  'v' => [LOWER_VOWELS],
  'V' => [LOWER_VOWELS, UPPER_VOWELS],
  'Z' => [UPPER_VOWELS],
  'x' => [HIGH_ANSI],
}
ASCII_MAPPING =
DEFAULT_MAPPING.reject { |k, v| k == 'x' }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CharSet

Instantiates a new CharSet object.

See Also:

  • Set#new


59
60
61
62
# File 'lib/keepass/password/char_set.rb', line 59

def initialize(*args)
  @mapping = DEFAULT_MAPPING
  super
end

Instance Attribute Details

#mappingHash

Returns the KeePass character set ID mapping.

Returns:

  • (Hash)

    the KeePass character set ID mapping



54
55
56
# File 'lib/keepass/password/char_set.rb', line 54

def mapping
  @mapping
end

Instance Method Details

#add_from_char_set_id(char_set_id) ⇒ CharSet

Adds several characters according to the KeePass character class.

Parameters:

  • char_set_id (String)

    the KeePass character set ID

Returns:

Raises:

See Also:



70
71
72
73
74
75
76
# File 'lib/keepass/password/char_set.rb', line 70

def add_from_char_set_id(char_set_id)
  if strings = mapping[char_set_id]
    add_from_strings *strings
  else
    raise InvalidCharSetIDError, "no such char set ID #{char_set_id.inspect}"
  end
end

#add_from_strings(*strings) ⇒ CharSet

Adds each character from one or more strings.

Parameters:

  • *strings (Array)

    one or more strings to add

Returns:



82
83
84
85
# File 'lib/keepass/password/char_set.rb', line 82

def add_from_strings(*strings)
  strings.each { |s| merge Set.new(s.split('')) }
  self
end