Class: ASIR::Coder::Sign
- Inherits:
-
ASIR::Coder
- Object
- ASIR::Coder
- ASIR::Coder::Sign
- Defined in:
- lib/asir/coder/sign.rb
Overview
!SLIDE Sign Coder
Sign payload during encode, check signature during decode.
Signature is the digest of secret + payload.
Encode payload as Hash containing the digest function name, signature and payload. Decode and validate Hash containing the digest function name, signature and payload.
Defined Under Namespace
Classes: SignatureError
Instance Attribute Summary collapse
-
#function ⇒ Object
Returns the value of attribute function.
-
#secret ⇒ Object
Returns the value of attribute secret.
Attributes included from Log
Instance Method Summary collapse
Methods inherited from ASIR::Coder
#_subclass_responsibility, #decode, #encode, #prepare
Methods included from Log
#_log, #_log_enabled=, #_log_enabled?, #_log_format, #_log_result, enabled, enabled=, included
Methods included from Initialization
Instance Attribute Details
#function ⇒ Object
Returns the value of attribute function.
16 17 18 |
# File 'lib/asir/coder/sign.rb', line 16 def function @function end |
#secret ⇒ Object
Returns the value of attribute secret.
16 17 18 |
# File 'lib/asir/coder/sign.rb', line 16 def secret @secret end |
Instance Method Details
#_decode(obj) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/asir/coder/sign.rb', line 26 def _decode obj raise SignatureError, "expected Hash, given #{obj.class}" unless Hash === obj payload = obj[:payload] raise SignatureError, "signature invalid" unless obj == _encode(payload) payload end |
#_encode(obj) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/asir/coder/sign.rb', line 18 def _encode obj payload = obj.to_s { :function => function, :signature => ::Digest.const_get(function). new.hexdigest(secret + payload), :payload => payload } end |
#initialize_before_opts ⇒ Object
39 40 41 |
# File 'lib/asir/coder/sign.rb', line 39 def initialize_before_opts @function = :SHA1 end |