Class: HipChatSecrets::Crypt

Inherits:
Object
  • Object
show all
Defined in:
lib/crypt.rb

Class Method Summary collapse

Class Method Details

.decode(str) ⇒ Object



11
12
13
# File 'lib/crypt.rb', line 11

def self.decode str
  xor Base64::decode64(str)
end

.encode(str) ⇒ Object



7
8
9
# File 'lib/crypt.rb', line 7

def self.encode str
  Base64::encode64(xor str).strip
end

.secretObject

You have to figure out the Secret on your own. Good luck!



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/crypt.rb', line 28

def self.secret
  return @@key if defined? @@key
  key_file = File.expand_path('~/.hipchat_secret')

  send 'secret=',
    if ENV['HIPCHAT_SECRET']
      ENV['HIPCHAT_SECRET']
    elsif File.exists? key_file
      File.open(key_file, 'r') {|f| f.read }
    else
      raise "Could not locate HipChat Secret Key in HIPCHAT_SECRET or #{key_file}"
    end
end

.secret=(key) ⇒ Object



42
43
44
# File 'lib/crypt.rb', line 42

def self.secret= key
  @@key = key.strip.unpack 'U*'
end

.secret_strObject



46
47
48
# File 'lib/crypt.rb', line 46

def self.secret_str
  secret.pack 'U*'
end

.xor(input) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/crypt.rb', line 15

def self.xor input
  input = input.unpack 'U*'
  output = []

  input.each_with_index do |num,index|
    output << (num ^ secret[index%secret.length])
  end

  output.pack 'U*'
end