Class: SignatureVerifierUtils
- Inherits:
-
Object
- Object
- SignatureVerifierUtils
- Defined in:
- lib/ruby-common/common/Utils.rb
Overview
Utility class for signature verification
Class Method Summary collapse
- .base64_decode(key) ⇒ Object
- .base64_encode(key) ⇒ Object
- .character_to_int(value) ⇒ Object
- .encode(key, data) ⇒ Object
- .pad_start(input_string, length, char) ⇒ Object
Class Method Details
.base64_decode(key) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/ruby-common/common/Utils.rb', line 7 def self.base64_decode(key) if key.include? "-" or key.include? "_" then return Base64.urlsafe_decode64(key) end return Base64.decode64(key) end |
.base64_encode(key) ⇒ Object
14 15 16 |
# File 'lib/ruby-common/common/Utils.rb', line 14 def self.base64_encode(key) return Base64.encode64(key) end |
.character_to_int(value) ⇒ Object
3 4 5 |
# File 'lib/ruby-common/common/Utils.rb', line 3 def self.character_to_int(value) value.to_i end |
.encode(key, data) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/ruby-common/common/Utils.rb', line 18 def self.encode(key, data) begin hmac = OpenSSL::HMAC.new(key, 'sha256') return hmac.update(data).digest rescue StandardError => e raise SignatureParseError, "Error encode data" end end |
.pad_start(input_string, length, char) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/ruby-common/common/Utils.rb', line 27 def self.pad_start(input_string, length, char) return input_string if input_string.length >= length padding = char.to_s * (length - input_string.length) padding + input_string end |