Module: Smbhash::Private

Defined in:
lib/smbhash.rb

Constant Summary collapse

LM_MAGIC =
"KGS!@\#$%"

Class Method Summary collapse

Class Method Details

.des_crypt56(input, key_str, forward_only) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/smbhash.rb', line 58

def des_crypt56(input, key_str, forward_only)
  key = str_to_key(key_str)
  encoder = OpenSSL::Cipher::DES.new
  encoder.encrypt
  encoder.key = key
  encoder.update(input)
end

.encrypt_14characters(chars) ⇒ Object

Raises:

  • (ArgumentError)


67
68
69
70
71
72
# File 'lib/smbhash.rb', line 67

def encrypt_14characters(chars)
  raise ArgumentError.new("must be <= 14 characters") if chars.size > 14
  chars = chars.to_s.ljust(14, "\000")
  des_crypt56(LM_MAGIC, chars[0, 7], true) +
      des_crypt56(LM_MAGIC, chars[7, 7], true)
end

.normalize_encoding(encoding) ⇒ Object



48
49
50
# File 'lib/smbhash.rb', line 48

def normalize_encoding(encoding)
  encoding.downcase.gsub(/-/, "_")
end

.same_encoding?(a, b) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/smbhash.rb', line 52

def same_encoding?(a, b)
  na = normalize_encoding(a)
  nb = normalize_encoding(b)
  na == nb or na.gsub(/_/, '') == nb.gsub(/_/, '')
end