Class: SyrupPay::JwsSerializer
- Inherits:
-
Object
- Object
- SyrupPay::JwsSerializer
- Includes:
- JwsSupportAlgorithm
- Defined in:
- lib/jose/jws/jws.rb
Defined Under Namespace
Classes: InvalidJwsFormatError, UnSupportHeaderError
Constant Summary
Constants included from JwsSupportAlgorithm
SyrupPay::JwsSupportAlgorithm::ALG
Instance Attribute Summary collapse
-
#claims ⇒ Object
readonly
Returns the value of attribute claims.
-
#header ⇒ Object
Returns the value of attribute header.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #compactDeserialize(serialized_input) ⇒ Object
- #compactSerialize(header = {}, claims) ⇒ Object
-
#initialize(key) ⇒ JwsSerializer
constructor
A new instance of JwsSerializer.
Methods included from JwsSupportAlgorithm
#alg?, #json_to_hash, #signature_algorithm?
Constructor Details
#initialize(key) ⇒ JwsSerializer
Returns a new instance of JwsSerializer.
33 34 35 |
# File 'lib/jose/jws/jws.rb', line 33 def initialize(key) @key = key end |
Instance Attribute Details
#claims ⇒ Object (readonly)
Returns the value of attribute claims.
31 32 33 |
# File 'lib/jose/jws/jws.rb', line 31 def claims @claims end |
#header ⇒ Object
Returns the value of attribute header.
30 31 32 |
# File 'lib/jose/jws/jws.rb', line 30 def header @header end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
31 32 33 |
# File 'lib/jose/jws/jws.rb', line 31 def key @key end |
Instance Method Details
#compactDeserialize(serialized_input) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jose/jws/jws.rb', line 49 def compactDeserialize(serialized_input) validate_deserialize! serialized_input header_json, @claims, sign_value = split_deserialize serialized_input @header = json_to_hash(header_json) jws_alg = signature_algorithm? @header[:alg].try(:to_sym) jws_alg.verify!(@key, hmac_data, UrlSafeBase64.encode64(sign_value)) @claims end |
#compactSerialize(header = {}, claims) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jose/jws/jws.rb', line 37 def compactSerialize(header = {}, claims) @claims = claims @header = header.with_indifferent_access validate_header! jws_alg = signature_algorithm? @header[:alg].try(:to_sym) sign_value = jws_alg.sign(@key, hmac_data) [@header.to_json, claims, sign_value].collect { |parts| UrlSafeBase64.encode64(parts)}.join('.') end |