Class: Sigil::Base
- Inherits:
-
Object
- Object
- Sigil::Base
- Defined in:
- lib/sigil/base.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params, key) ⇒ Base
constructor
A new instance of Base.
- #to_query ⇒ Object
- #verify(provided_signature) ⇒ Object
- #verify!(provided_signature) ⇒ Object
Constructor Details
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/sigil/base.rb', line 4 def key @key end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/sigil/base.rb', line 4 def params @params end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
4 5 6 |
# File 'lib/sigil/base.rb', line 4 def signature @signature end |
Class Method Details
.sign(string, key) ⇒ Object
26 27 28 29 |
# File 'lib/sigil/base.rb', line 26 def self.sign(string, key) hmacd = OpenSSL::HMAC.new(key, OpenSSL::Digest::SHA1.new) hmacd.update(string) end |
Instance Method Details
#to_query ⇒ Object
14 15 16 |
# File 'lib/sigil/base.rb', line 14 def to_query @params.to_query end |
#verify(provided_signature) ⇒ Object
31 32 33 34 35 |
# File 'lib/sigil/base.rb', line 31 def verify(provided_signature) verify!(provided_signature) rescue Sigil::Error false end |
#verify!(provided_signature) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/sigil/base.rb', line 37 def verify!(provided_signature) raise Sigil::Error, "Params not set" if params.empty? raise Sigil::Error, "Signature not set" if provided_signature.blank? raise Sigil::Error, "Signature does not match" unless signature == provided_signature true end |