Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/alt/ruby27/share/ruby
File: base64.rb
# frozen_string_literal: true
[0] Fix | Delete
#
[1] Fix | Delete
# = base64.rb: methods for base64-encoding and -decoding strings
[2] Fix | Delete
#
[3] Fix | Delete
[4] Fix | Delete
# The Base64 module provides for the encoding (#encode64, #strict_encode64,
[5] Fix | Delete
# #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
[6] Fix | Delete
# #urlsafe_decode64) of binary data using a Base64 representation.
[7] Fix | Delete
#
[8] Fix | Delete
# == Example
[9] Fix | Delete
#
[10] Fix | Delete
# A simple encoding and decoding.
[11] Fix | Delete
#
[12] Fix | Delete
# require "base64"
[13] Fix | Delete
#
[14] Fix | Delete
# enc = Base64.encode64('Send reinforcements')
[15] Fix | Delete
# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
[16] Fix | Delete
# plain = Base64.decode64(enc)
[17] Fix | Delete
# # -> "Send reinforcements"
[18] Fix | Delete
#
[19] Fix | Delete
# The purpose of using base64 to encode data is that it translates any
[20] Fix | Delete
# binary data into purely printable characters.
[21] Fix | Delete
[22] Fix | Delete
module Base64
[23] Fix | Delete
module_function
[24] Fix | Delete
[25] Fix | Delete
# Returns the Base64-encoded version of +bin+.
[26] Fix | Delete
# This method complies with RFC 2045.
[27] Fix | Delete
# Line feeds are added to every 60 encoded characters.
[28] Fix | Delete
#
[29] Fix | Delete
# require 'base64'
[30] Fix | Delete
# Base64.encode64("Now is the time for all good coders\nto learn Ruby")
[31] Fix | Delete
#
[32] Fix | Delete
# <i>Generates:</i>
[33] Fix | Delete
#
[34] Fix | Delete
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
[35] Fix | Delete
# UnVieQ==
[36] Fix | Delete
def encode64(bin)
[37] Fix | Delete
[bin].pack("m")
[38] Fix | Delete
end
[39] Fix | Delete
[40] Fix | Delete
# Returns the Base64-decoded version of +str+.
[41] Fix | Delete
# This method complies with RFC 2045.
[42] Fix | Delete
# Characters outside the base alphabet are ignored.
[43] Fix | Delete
#
[44] Fix | Delete
# require 'base64'
[45] Fix | Delete
# str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
[46] Fix | Delete
# 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
[47] Fix | Delete
# 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
[48] Fix | Delete
# puts Base64.decode64(str)
[49] Fix | Delete
#
[50] Fix | Delete
# <i>Generates:</i>
[51] Fix | Delete
#
[52] Fix | Delete
# This is line one
[53] Fix | Delete
# This is line two
[54] Fix | Delete
# This is line three
[55] Fix | Delete
# And so on...
[56] Fix | Delete
def decode64(str)
[57] Fix | Delete
str.unpack1("m")
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
# Returns the Base64-encoded version of +bin+.
[61] Fix | Delete
# This method complies with RFC 4648.
[62] Fix | Delete
# No line feeds are added.
[63] Fix | Delete
def strict_encode64(bin)
[64] Fix | Delete
[bin].pack("m0")
[65] Fix | Delete
end
[66] Fix | Delete
[67] Fix | Delete
# Returns the Base64-decoded version of +str+.
[68] Fix | Delete
# This method complies with RFC 4648.
[69] Fix | Delete
# ArgumentError is raised if +str+ is incorrectly padded or contains
[70] Fix | Delete
# non-alphabet characters. Note that CR or LF are also rejected.
[71] Fix | Delete
def strict_decode64(str)
[72] Fix | Delete
str.unpack1("m0")
[73] Fix | Delete
end
[74] Fix | Delete
[75] Fix | Delete
# Returns the Base64-encoded version of +bin+.
[76] Fix | Delete
# This method complies with ``Base 64 Encoding with URL and Filename Safe
[77] Fix | Delete
# Alphabet'' in RFC 4648.
[78] Fix | Delete
# The alphabet uses '-' instead of '+' and '_' instead of '/'.
[79] Fix | Delete
# Note that the result can still contain '='.
[80] Fix | Delete
# You can remove the padding by setting +padding+ as false.
[81] Fix | Delete
def urlsafe_encode64(bin, padding: true)
[82] Fix | Delete
str = strict_encode64(bin)
[83] Fix | Delete
str.tr!("+/", "-_")
[84] Fix | Delete
str.delete!("=") unless padding
[85] Fix | Delete
str
[86] Fix | Delete
end
[87] Fix | Delete
[88] Fix | Delete
# Returns the Base64-decoded version of +str+.
[89] Fix | Delete
# This method complies with ``Base 64 Encoding with URL and Filename Safe
[90] Fix | Delete
# Alphabet'' in RFC 4648.
[91] Fix | Delete
# The alphabet uses '-' instead of '+' and '_' instead of '/'.
[92] Fix | Delete
#
[93] Fix | Delete
# The padding character is optional.
[94] Fix | Delete
# This method accepts both correctly-padded and unpadded input.
[95] Fix | Delete
# Note that it still rejects incorrectly-padded input.
[96] Fix | Delete
def urlsafe_decode64(str)
[97] Fix | Delete
# NOTE: RFC 4648 does say nothing about unpadded input, but says that
[98] Fix | Delete
# "the excess pad characters MAY also be ignored", so it is inferred that
[99] Fix | Delete
# unpadded input is also acceptable.
[100] Fix | Delete
str = str.tr("-_", "+/")
[101] Fix | Delete
if !str.end_with?("=") && str.length % 4 != 0
[102] Fix | Delete
str = str.ljust((str.length + 3) & ~3, "=")
[103] Fix | Delete
end
[104] Fix | Delete
strict_decode64(str)
[105] Fix | Delete
end
[106] Fix | Delete
end
[107] Fix | Delete
[108] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function