Class: JWE::Serialization::Compact

Inherits:
Object
  • Object
show all
Defined in:
lib/jwe/serialization/compact.rb

Overview

The default and suggested way of serializing JWE messages.

Class Method Summary collapse

Class Method Details

.decode(payload) ⇒ Object

Raises:


10
11
12
13
14
15
16
17
# File 'lib/jwe/serialization/compact.rb', line 10

def self.decode(payload)
  parts = payload.split('.')
  raise JWE::DecodeError.new('Not enough or too many segments') unless parts.length == 5

  parts.map do |part|
    JWE::Base64.jwe_decode(part)
  end
end

.encode(header, encrypted_cek, iv, ciphertext, tag) ⇒ Object


6
7
8
# File 'lib/jwe/serialization/compact.rb', line 6

def self.encode(header, encrypted_cek, iv, ciphertext, tag)
  [header, encrypted_cek, iv, ciphertext, tag].map { |piece| JWE::Base64.jwe_encode(piece) }.join '.'
end