Method: As2.base64_encode

Defined in:
lib/as2.rb

.base64_encode(content, scheme: 'rfc4648') ⇒ String

create a base64 string from content, based on the given encoding scheme

Parameters:

  • content (String)
  • scheme (String) (defaults to: 'rfc4648')

    one of As2.valid_base64_schemes

Returns:

  • (String)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/as2.rb', line 38

def self.base64_encode(content, scheme: 'rfc4648')
  case scheme.to_s
  when 'rfc2045'
    # "This method complies with RFC 2045."
    # https://ruby-doc.org/stdlib-3.0.4/libdoc/base64/rdoc/Base64.html#method-i-encode64
    # https://www.rfc-editor.org/rfc/rfc2045#section-6.8
    then Base64.encode64(content)
  when 'rfc4648'
    # "This method complies with RFC 4648."
    # https://ruby-doc.org/stdlib-3.0.4/libdoc/base64/rdoc/Base64.html#method-i-strict_encode64
    # https://www.rfc-editor.org/rfc/rfc4648#section-4
    then Base64.strict_encode64(content)
  else
    raise ArgumentError, "unsupported scheme '#{scheme}'. choose one of: #{valid_base64_schemes}"
  end
end