Module: Signed

Defined in:
lib/signed.rb,
lib/signed/utils.rb,
lib/signed/version.rb,
lib/signed/signature.rb

Overview

module for signing string

can create and verify signature with expiry

Defined Under Namespace

Modules: Signature, Utils

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.create_signature(data, secret, expiry: nil, algo: 'SHA256') ⇒ Object Also known as: sign

signature format is signature(“#data:#expiry:#secret”):base64(secondary)



13
14
15
16
17
18
# File 'lib/signed.rb', line 13

def create_signature(data, secret, expiry: nil, algo: 'SHA256')
  expiry = 'infinit' unless expiry
  signature = Signature.sign_with(algo, "#{data}:#{expiry}:#{secret}")

  "#{signature}:#{Base64.encode64(expiry.to_s)}"
end

.verify_signature(data, signature, secret, algo: 'SHA256') ⇒ Object Also known as: verify?



20
21
22
23
24
25
26
27
# File 'lib/signed.rb', line 20

def verify_signature(data, signature, secret, algo: 'SHA256')
  sign = signature.split(':')
  return false if sign.count < 2
  hash = sign[0]
  expiry = Base64.decode64(sign[1])
  return false if Utils.check_expiry(expiry)
  Signature.verify_hash(algo, hash, "#{data}:#{expiry}:#{secret}")
end