Module: Ronin::Support::Encoding::Base64

Defined in:
lib/ronin/support/encoding/base64.rb

Overview

Base64 encoding/decoding.

Core-Ext Methods

Since:

  • 1.0.0

Class Method Summary collapse

Class Method Details

.decode(data, mode: nil) ⇒ String

Base64 decodes the given data.

Parameters:

  • data (String)

    The Base64 data to decode.

  • mode (:strict, :url_safe, nil) (defaults to: nil)

    The Base64 encoding mode.

Returns:

  • (String)

    The decoded data.

Since:

  • 1.0.0



71
72
73
74
75
76
77
78
79
# File 'lib/ronin/support/encoding/base64.rb', line 71

def self.decode(data, mode: nil)
  case mode
  when :strict   then ::Base64.strict_decode64(data)
  when :url_safe then ::Base64.urlsafe_decode64(data)
  when nil       then ::Base64.decode64(data)
  else
    raise(ArgumentError,"Base64 mode must be either :string, :url, or nil: #{mode.inspect}")
  end
end

.encode(data, mode: nil) ⇒ String

Base64 encodes the given data.

Parameters:

  • data (String)

    The data to Base64 encode.

  • mode (:strict, :url_safe, nil) (defaults to: nil)

    The Base64 encoding mode.

Returns:

  • (String)

    The Base64 encoded data.

Since:

  • 1.0.0



49
50
51
52
53
54
55
56
57
# File 'lib/ronin/support/encoding/base64.rb', line 49

def self.encode(data, mode: nil)
  case mode
  when :strict   then ::Base64.strict_encode64(data)
  when :url_safe then ::Base64.urlsafe_encode64(data)
  when nil       then ::Base64.encode64(data)
  else
    raise(ArgumentError,"Base64 mode must be either :string, :url, or nil: #{mode.inspect}")
  end
end