Class: EventQ::SignatureProviders::Sha256SignatureProvider
- Inherits:
-
Object
- Object
- EventQ::SignatureProviders::Sha256SignatureProvider
- Defined in:
- lib/eventq_base/signature_providers/sha256_signature_provider.rb
Instance Method Summary collapse
-
#initialize ⇒ Sha256SignatureProvider
constructor
A new instance of Sha256SignatureProvider.
-
#valid?(message:, secret:) ⇒ Boolean
This method is called to validate a message signature.
-
#write(message:, secret:) ⇒ Object
This method is called to create a signature for a message.
Constructor Details
#initialize ⇒ Sha256SignatureProvider
Returns a new instance of Sha256SignatureProvider.
5 6 7 8 9 |
# File 'lib/eventq_base/signature_providers/sha256_signature_provider.rb', line 5 def initialize require 'openssl' require 'base64' @serializer = serialization_provider_manager.get_provider(EventQ::Configuration.serialization_provider) end |
Instance Method Details
#valid?(message:, secret:) ⇒ Boolean
This method is called to validate a message signature
19 20 21 22 |
# File 'lib/eventq_base/signature_providers/sha256_signature_provider.rb', line 19 def valid?(message:, secret:) signature = write(message: , secret: secret) .signature == signature end |
#write(message:, secret:) ⇒ Object
This method is called to create a signature for a message
12 13 14 15 16 |
# File 'lib/eventq_base/signature_providers/sha256_signature_provider.rb', line 12 def write(message:, secret:) json = @serializer.serialize(.content) hash = OpenSSL::HMAC.digest('sha256', secret, json) Base64.encode64(hash) end |