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.
11 12 13 |
# File 'lib/ledger_sync/util/signer.rb', line 11 def initialize(str:) @str = str end |
Instance Attribute Details
#str ⇒ Object (readonly)
Returns the value of attribute str.
9 10 11 |
# File 'lib/ledger_sync/util/signer.rb', line 9 def str @str end |
Class Method Details
.escape(str:) ⇒ Object
27 28 29 |
# File 'lib/ledger_sync/util/signer.rb', line 27 def self.escape(str:) CGI.escape(str).gsub(/\+/, '%20') end |
.unescape(str:) ⇒ Object
31 32 33 |
# File 'lib/ledger_sync/util/signer.rb', line 31 def self.unescape(str:) CGI.unescape(str.gsub(/%20/, '+')) end |
Instance Method Details
#hmac_sha1(key:, escape: false) ⇒ Object
15 16 17 18 19 |
# File 'lib/ledger_sync/util/signer.rb', line 15 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
21 22 23 24 25 |
# File 'lib/ledger_sync/util/signer.rb', line 21 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 |