module Base64

def urlsafe_decode64(str)


Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"

see {Padding}[Base64.html#module-Base64-label-Padding], above:
Padding in +encoded_string+, if present, must be correct:

Base64.urlsafe_decode64("\n") # Raises ArgumentError.
Base64.urlsafe_decode64('/') # Raises ArgumentError.
Base64.urlsafe_decode64('+') # Raises ArgumentError.

see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
+encoded_string+ may not contain non-Base64 characters;

Returns the decoding of an RFC-4648-compliant \Base64-encoded string +encoded_string+:

Base64.urlsafe_decode64(encoded_string) -> decoded_string
:call-seq:
def urlsafe_decode64(str)
  # NOTE: RFC 4648 does say nothing about unpadded input, but says that
  # "the excess pad characters MAY also be ignored", so it is inferred that
  # unpadded input is also acceptable.
  if !str.end_with?("=") && str.length % 4 != 0
    str = str.ljust((str.length + 3) & ~3, "=")
    str.tr!("-_", "+/")
  else
    str = str.tr("-_", "+/")
  end
  strict_decode64(str)
end