Class: JOSE::JWE::ZIP_DEF

Inherits:
Struct
  • Object
show all
Defined in:
lib/jose/jwe/zip_def.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_map(fields) ⇒ Object

JOSE::JWE callbacks



5
6
7
8
9
10
11
12
# File 'lib/jose/jwe/zip_def.rb', line 5

def self.from_map(fields)
  case fields['zip']
  when 'DEF'
    return new(), fields.except('zip')
  else
    raise ArgumentError, "invalid 'zip' for JWE: #{fields['zip'].inspect}"
  end
end

Instance Method Details

#compress(plain_text) ⇒ Object

JOSE::JWE::ZIP callbacks



20
21
22
23
24
25
26
# File 'lib/jose/jwe/zip_def.rb', line 20

def compress(plain_text)
  zstream = Zlib::Deflate.new(nil, -Zlib::MAX_WBITS)
  buf = zstream.deflate(plain_text, Zlib::FINISH)
  zstream.finish
  zstream.close
  return buf
end

#to_map(fields) ⇒ Object



14
15
16
# File 'lib/jose/jwe/zip_def.rb', line 14

def to_map(fields)
  return fields.put('zip', 'DEF')
end

#uncompress(cipher_text) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/jose/jwe/zip_def.rb', line 28

def uncompress(cipher_text)
  zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
  buf = zstream.inflate(cipher_text)
  zstream.finish
  zstream.close
  return buf
end