Class: Hermes::B64Y

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

Class Method Summary collapse

Class Method Details

.decodable?(payload) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/support/b64y.rb', line 16

def self.decodable?(payload)
  # check to make sure when we decode that it's going to look like a YAML object
  Base64.strict_decode64(payload)[0..2] == '---'
rescue
  false
end

.decode(payload) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/support/b64y.rb', line 7

def self.decode(payload)
  YAML.load(Base64.strict_decode64(payload))
rescue Exception => e
  Utils.log_and_puts "--- DECODE FAILURE ---"
  Utils.log_and_puts payload
  Utils.log_and_puts "--- DECODE FAILURE ---"
  raise e
end

.encode(payload) ⇒ Object



3
4
5
# File 'lib/support/b64y.rb', line 3

def self.encode(payload)
  Base64.strict_encode64(YAML.dump(payload))
end