Class: XSignature::RequestValidator
- Inherits:
-
Object
- Object
- XSignature::RequestValidator
- Defined in:
- lib/x-signature/request_validator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#nonce_validator ⇒ Object
Returns the value of attribute nonce_validator.
-
#signature_validator ⇒ Object
Returns the value of attribute signature_validator.
Instance Method Summary collapse
-
#initialize(signature_validator: nil, nonce_validator: nil) ⇒ RequestValidator
constructor
A new instance of RequestValidator.
- #valid?(**args) ⇒ Boolean
-
#validate(**args) ⇒ Object
:secret, :signature, :client, :nonce, :method, :request_uri, :body.
Constructor Details
#initialize(signature_validator: nil, nonce_validator: nil) ⇒ RequestValidator
Returns a new instance of RequestValidator.
6 7 8 9 |
# File 'lib/x-signature/request_validator.rb', line 6 def initialize(signature_validator: nil, nonce_validator: nil) @signature_validator = signature_validator || SignatureMultiValidator.new(HexSignatureValidator.new, Base64SignatureValidator.new) @nonce_validator = nonce_validator || RedisNonceValidator.new end |
Instance Attribute Details
#nonce_validator ⇒ Object
Returns the value of attribute nonce_validator.
4 5 6 |
# File 'lib/x-signature/request_validator.rb', line 4 def nonce_validator @nonce_validator end |
#signature_validator ⇒ Object
Returns the value of attribute signature_validator.
4 5 6 |
# File 'lib/x-signature/request_validator.rb', line 4 def signature_validator @signature_validator end |
Instance Method Details
#valid?(**args) ⇒ Boolean
22 23 24 25 26 |
# File 'lib/x-signature/request_validator.rb', line 22 def valid?(**args) validate(**args) rescue XSignatureError false end |
#validate(**args) ⇒ Object
:secret, :signature, :client, :nonce, :method, :request_uri, :body
12 13 14 15 16 17 18 19 20 |
# File 'lib/x-signature/request_validator.rb', line 12 def validate(**args) data = Data.new args.each do |k, v| data[k] = v end fail InvalidNonce unless @nonce_validator.valid?(data) fail InvalidSignature unless @signature_validator.valid?(data) true end |