Class: GoogleSafeBrowsing::KeyHelper

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

Class Method Summary collapse

Class Method Details

.compute_mac_code(data) ⇒ Object



15
16
17
18
19
20
# File 'lib/google_safe_browsing/key_helper.rb', line 15

def self.compute_mac_code(data)
  sha1 = OpenSSL::HMAC.digest('sha1',
                              GoogleSafeBrowsing.config.client_key,
                              data)
  web_safe_base64_encode sha1
end

.web_safe_base64_decode(str) ⇒ Object



4
5
6
7
8
# File 'lib/google_safe_browsing/key_helper.rb', line 4

def self.web_safe_base64_decode(str)
  str.tr!('-_', '+/')
  str << '=' while str.length % 4 != 0
  Base64.decode64(str)
end

.web_safe_base64_encode(str) ⇒ Object



10
11
12
13
# File 'lib/google_safe_browsing/key_helper.rb', line 10

def self.web_safe_base64_encode(str)
  str = Base64.encode64(str).chomp
  str.tr('+/', '-_')
end