Class: Saml::Encoding

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

Class Method Summary collapse

Class Method Details

.decode_64(base64_string) ⇒ Object



11
12
13
# File 'lib/saml/encoding.rb', line 11

def self.decode_64 base64_string
  Base64.decode64 base64_string
end

.decode_gzip(gzip_binary_string) ⇒ Object



19
20
21
22
23
24
# File 'lib/saml/encoding.rb', line 19

def self.decode_gzip gzip_binary_string
  # Adding a - sign to MAX_WBITS makes zlib ignore the zlib headers
  inflate(gzip_binary_string, -Zlib::MAX_WBITS)
rescue ::Zlib::DataError
  inflate(gzip_binary_string) rescue nil
end

.encode_64(string) ⇒ Object



7
8
9
# File 'lib/saml/encoding.rb', line 7

def self.encode_64 string
  Base64.encode64(string).chomp
end

.encode_gzip(string) ⇒ Object



15
16
17
# File 'lib/saml/encoding.rb', line 15

def self.encode_gzip string
  Zlib::Deflate.deflate(string, 9)[2..-5]
end

.inflate(gzip_binary_string, max_bits = nil) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/saml/encoding.rb', line 26

def self.inflate gzip_binary_string, max_bits=nil
  zstream = Zlib::Inflate.new(max_bits)
  begin
    zstream.inflate(gzip_binary_string)
  ensure
    zstream.close
  end
end