Class: LedgerSync::Util::Signer
- Inherits:
-
Object
- Object
- LedgerSync::Util::Signer
- Defined in:
- lib/ledger_sync/util/signer.rb
Constant Summary collapse
- HMAC_SHA1_DIGEST =
OpenSSL::Digest.new('sha1')
- HMAC_SHA256_DIGEST =
OpenSSL::Digest.new('sha256')
Instance Attribute Summary collapse
-
#str ⇒ Object
readonly
Returns the value of attribute str.
Class Method Summary collapse
Instance Method Summary collapse
- #hmac_sha1(key:, escape: false) ⇒ Object
- #hmac_sha256(key:, escape: false) ⇒ Object
-
#initialize(str:) ⇒ Signer
constructor
A new instance of Signer.
Constructor Details
#initialize(str:) ⇒ Signer
Returns a new instance of Signer.
13 14 15 |
# File 'lib/ledger_sync/util/signer.rb', line 13 def initialize(str:) @str = str end |
Instance Attribute Details
#str ⇒ Object (readonly)
Returns the value of attribute str.
11 12 13 |
# File 'lib/ledger_sync/util/signer.rb', line 11 def str @str end |
Class Method Details
.escape(str:) ⇒ Object
29 30 31 |
# File 'lib/ledger_sync/util/signer.rb', line 29 def self.escape(str:) CGI.escape(str).gsub('+', '%20') end |
.unescape(str:) ⇒ Object
33 34 35 |
# File 'lib/ledger_sync/util/signer.rb', line 33 def self.unescape(str:) CGI.unescape(str.gsub('%20', '+')) end |
Instance Method Details
#hmac_sha1(key:, escape: false) ⇒ Object
17 18 19 20 21 |
# File 'lib/ledger_sync/util/signer.rb', line 17 def hmac_sha1(key:, escape: false) ret = Base64.encode64(OpenSSL::HMAC.digest(HMAC_SHA1_DIGEST, key, str)).strip ret = self.class.escape(str: ret) if escape ret end |
#hmac_sha256(key:, escape: false) ⇒ Object
23 24 25 26 27 |
# File 'lib/ledger_sync/util/signer.rb', line 23 def hmac_sha256(key:, escape: false) ret = Base64.encode64(OpenSSL::HMAC.digest(HMAC_SHA256_DIGEST, key, str)).strip ret = self.class.escape(str: ret) if escape ret end |