Class: SyrupPay::CompactDeserialization

Inherits:
Object
  • Object
show all
Defined in:
lib/syruppay_jose.rb

Defined Under Namespace

Classes: UnSupportAlgorithmError

Class Method Summary collapse

Class Method Details

.deserialization(key, serialized_src) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/syruppay_jose.rb', line 26

def self.deserialization(key, serialized_src)
  header_json = UrlSafeBase64.decode64(serialized_src.split('.').first)

  header = json_to_hash(header_json)

  if (jwe_algorithm?(header[:alg].try(:to_sym)))
    jwe_serializer = SyrupPay::JweSerializer.new(key)
    jwe_serializer.compactDeserialize serialized_src
  elsif (jws_algorithm?(header[:alg].try(:to_sym)))
    jws_serializer = SyrupPay::JwsSerializer.new(key)
    jws_serializer.compactDeserialize serialized_src
  else
    raise UnSupportAlgorithmError, (header[:alg].presence||'alg(nil)')+' is not supported'
  end
end