base64 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{LICENSE.txt → BSDL} +3 -3
- data/COPYING +56 -0
- data/LEGAL +60 -0
- data/lib/base64.rb +333 -62
- data/sig/base64.rbs +355 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da8017f88b13b4bcce299b2b4b5a3023ceca129259e34c96cf4ee8444651cb54
|
4
|
+
data.tar.gz: c13e817c37612d65668c7266945f2356982e090f0781d739cc9e2fbaadf5bad7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c070995dc383eb45bb66d9b413eaf567434932477a4121834567c6deb5493c3498c652db0f23901696232ff098573db5b094f180c7ad2b90be189156f98e87e
|
7
|
+
data.tar.gz: a23bc57298678e16663a9a2f0007259437b8efe6c25d37481a2e47585b31229fdd9ff5dd76fb9f0618954e88d6a63d9f316a19d531ee7cbe6e9bea607ef859c5
|
data/{LICENSE.txt → BSDL}
RENAMED
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
|
|
4
4
|
modification, are permitted provided that the following conditions
|
5
5
|
are met:
|
6
6
|
1. Redistributions of source code must retain the above copyright
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
8
|
2. Redistributions in binary form must reproduce the above copyright
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
10
|
-
documentation and/or other materials provided with the distribution.
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
11
|
|
12
12
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
13
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
data/COPYING
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a. place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b. use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c. give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d. make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a. distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b. accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c. give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d. make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/LEGAL
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- rdoc -*-
|
2
|
+
|
3
|
+
= LEGAL NOTICE INFORMATION
|
4
|
+
--------------------------
|
5
|
+
|
6
|
+
All the files in this distribution are covered under either the Ruby's
|
7
|
+
license (see the file COPYING) or public-domain except some files
|
8
|
+
mentioned below.
|
9
|
+
|
10
|
+
== MIT License
|
11
|
+
>>>
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
a copy of this software and associated documentation files (the
|
14
|
+
"Software"), to deal in the Software without restriction, including
|
15
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
the following conditions:
|
19
|
+
|
20
|
+
The above copyright notice and this permission notice shall be
|
21
|
+
included in all copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
|
31
|
+
== Old-style BSD license
|
32
|
+
>>>
|
33
|
+
Redistribution and use in source and binary forms, with or without
|
34
|
+
modification, are permitted provided that the following conditions
|
35
|
+
are met:
|
36
|
+
1. Redistributions of source code must retain the above copyright
|
37
|
+
notice, this list of conditions and the following disclaimer.
|
38
|
+
2. Redistributions in binary form must reproduce the above copyright
|
39
|
+
notice, this list of conditions and the following disclaimer in the
|
40
|
+
documentation and/or other materials provided with the distribution.
|
41
|
+
3. Neither the name of the University nor the names of its contributors
|
42
|
+
may be used to endorse or promote products derived from this software
|
43
|
+
without specific prior written permission.
|
44
|
+
|
45
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
46
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
47
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
48
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
49
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
50
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
51
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
52
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
53
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
54
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
55
|
+
SUCH DAMAGE.
|
56
|
+
|
57
|
+
IMPORTANT NOTE::
|
58
|
+
|
59
|
+
From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
|
60
|
+
paragraph 3 above is now null and void.
|
data/lib/base64.rb
CHANGED
@@ -1,85 +1,345 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# \Module \Base64 provides methods for:
|
4
4
|
#
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# #urlsafe_decode64) of binary data using a Base64 representation.
|
5
|
+
# - \Encoding a binary string (containing non-ASCII characters)
|
6
|
+
# as a string of printable ASCII characters.
|
7
|
+
# - Decoding such an encoded string.
|
9
8
|
#
|
10
|
-
#
|
9
|
+
# \Base64 is commonly used in contexts where binary data
|
10
|
+
# is not allowed or supported:
|
11
11
|
#
|
12
|
-
#
|
12
|
+
# - Images in HTML or CSS files, or in URLs.
|
13
|
+
# - Email attachments.
|
13
14
|
#
|
14
|
-
#
|
15
|
+
# A \Base64-encoded string is about one-third larger that its source.
|
16
|
+
# See the {Wikipedia article}[https://en.wikipedia.org/wiki/Base64]
|
17
|
+
# for more information.
|
15
18
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
19
|
+
# This module provides three pairs of encode/decode methods.
|
20
|
+
# Your choices among these methods should depend on:
|
21
|
+
#
|
22
|
+
# - Which character set is to be used for encoding and decoding.
|
23
|
+
# - Whether "padding" is to be used.
|
24
|
+
# - Whether encoded strings are to contain newlines.
|
25
|
+
#
|
26
|
+
# Note: Examples on this page assume that the including program has executed:
|
27
|
+
#
|
28
|
+
# require 'base64'
|
29
|
+
#
|
30
|
+
# == \Encoding Character Sets
|
31
|
+
#
|
32
|
+
# A \Base64-encoded string consists only of characters from a 64-character set:
|
33
|
+
#
|
34
|
+
# - <tt>('A'..'Z')</tt>.
|
35
|
+
# - <tt>('a'..'z')</tt>.
|
36
|
+
# - <tt>('0'..'9')</tt>.
|
37
|
+
# - <tt>=</tt>, the 'padding' character.
|
38
|
+
# - Either:
|
39
|
+
# - <tt>%w[+ /]</tt>:
|
40
|
+
# {RFC-2045-compliant}[https://datatracker.ietf.org/doc/html/rfc2045];
|
41
|
+
# _not_ safe for URLs.
|
42
|
+
# - <tt>%w[- _]</tt>:
|
43
|
+
# {RFC-4648-compliant}[https://datatracker.ietf.org/doc/html/rfc4648];
|
44
|
+
# safe for URLs.
|
45
|
+
#
|
46
|
+
# If you are working with \Base64-encoded strings that will come from
|
47
|
+
# or be put into URLs, you should choose this encoder-decoder pair
|
48
|
+
# of RFC-4648-compliant methods:
|
49
|
+
#
|
50
|
+
# - Base64.urlsafe_encode64 and Base64.urlsafe_decode64.
|
51
|
+
#
|
52
|
+
# Otherwise, you may choose any of the pairs in this module,
|
53
|
+
# including the pair above, or the RFC-2045-compliant pairs:
|
54
|
+
#
|
55
|
+
# - Base64.encode64 and Base64.decode64.
|
56
|
+
# - Base64.strict_encode64 and Base64.strict_decode64.
|
57
|
+
#
|
58
|
+
# == Padding
|
59
|
+
#
|
60
|
+
# \Base64-encoding changes a triplet of input bytes
|
61
|
+
# into a quartet of output characters.
|
62
|
+
#
|
63
|
+
# <b>Padding in Encode Methods</b>
|
64
|
+
#
|
65
|
+
# Padding -- extending an encoded string with zero, one, or two trailing
|
66
|
+
# <tt>=</tt> characters -- is performed by methods Base64.encode64,
|
67
|
+
# Base64.strict_encode64, and, by default, Base64.urlsafe_encode64:
|
68
|
+
#
|
69
|
+
# Base64.encode64('s') # => "cw==\n"
|
70
|
+
# Base64.strict_encode64('s') # => "cw=="
|
71
|
+
# Base64.urlsafe_encode64('s') # => "cw=="
|
72
|
+
# Base64.urlsafe_encode64('s', padding: false) # => "cw"
|
73
|
+
#
|
74
|
+
# When padding is performed, the encoded string is always of length <em>4n</em>,
|
75
|
+
# where +n+ is a non-negative integer:
|
76
|
+
#
|
77
|
+
# - Input bytes of length <em>3n</em> generate unpadded output characters
|
78
|
+
# of length <em>4n</em>:
|
79
|
+
#
|
80
|
+
# # n = 1: 3 bytes => 4 characters.
|
81
|
+
# Base64.strict_encode64('123') # => "MDEy"
|
82
|
+
# # n = 2: 6 bytes => 8 characters.
|
83
|
+
# Base64.strict_encode64('123456') # => "MDEyMzQ1"
|
84
|
+
#
|
85
|
+
# - Input bytes of length <em>3n+1</em> generate padded output characters
|
86
|
+
# of length <em>4(n+1)</em>, with two padding characters at the end:
|
87
|
+
#
|
88
|
+
# # n = 1: 4 bytes => 8 characters.
|
89
|
+
# Base64.strict_encode64('1234') # => "MDEyMw=="
|
90
|
+
# # n = 2: 7 bytes => 12 characters.
|
91
|
+
# Base64.strict_encode64('1234567') # => "MDEyMzQ1Ng=="
|
92
|
+
#
|
93
|
+
# - Input bytes of length <em>3n+2</em> generate padded output characters
|
94
|
+
# of length <em>4(n+1)</em>, with one padding character at the end:
|
95
|
+
#
|
96
|
+
# # n = 1: 5 bytes => 8 characters.
|
97
|
+
# Base64.strict_encode64('12345') # => "MDEyMzQ="
|
98
|
+
# # n = 2: 8 bytes => 12 characters.
|
99
|
+
# Base64.strict_encode64('12345678') # => "MDEyMzQ1Njc="
|
100
|
+
#
|
101
|
+
# When padding is suppressed, for a positive integer <em>n</em>:
|
102
|
+
#
|
103
|
+
# - Input bytes of length <em>3n</em> generate unpadded output characters
|
104
|
+
# of length <em>4n</em>:
|
105
|
+
#
|
106
|
+
# # n = 1: 3 bytes => 4 characters.
|
107
|
+
# Base64.urlsafe_encode64('123', padding: false) # => "MDEy"
|
108
|
+
# # n = 2: 6 bytes => 8 characters.
|
109
|
+
# Base64.urlsafe_encode64('123456', padding: false) # => "MDEyMzQ1"
|
110
|
+
#
|
111
|
+
# - Input bytes of length <em>3n+1</em> generate unpadded output characters
|
112
|
+
# of length <em>4n+2</em>, with two padding characters at the end:
|
113
|
+
#
|
114
|
+
# # n = 1: 4 bytes => 6 characters.
|
115
|
+
# Base64.urlsafe_encode64('1234', padding: false) # => "MDEyMw"
|
116
|
+
# # n = 2: 7 bytes => 10 characters.
|
117
|
+
# Base64.urlsafe_encode64('1234567', padding: false) # => "MDEyMzQ1Ng"
|
118
|
+
#
|
119
|
+
# - Input bytes of length <em>3n+2</em> generate unpadded output characters
|
120
|
+
# of length <em>4n+3</em>, with one padding character at the end:
|
121
|
+
#
|
122
|
+
# # n = 1: 5 bytes => 7 characters.
|
123
|
+
# Base64.urlsafe_encode64('12345', padding: false) # => "MDEyMzQ"
|
124
|
+
# # m = 2: 8 bytes => 11 characters.
|
125
|
+
# Base64.urlsafe_encode64('12345678', padding: false) # => "MDEyMzQ1Njc"
|
126
|
+
#
|
127
|
+
# <b>Padding in Decode Methods</b>
|
128
|
+
#
|
129
|
+
# All of the \Base64 decode methods support (but do not require) padding.
|
130
|
+
#
|
131
|
+
# \Method Base64.decode64 does not check the size of the padding:
|
132
|
+
#
|
133
|
+
# Base64.decode64("MDEyMzQ1Njc") # => "01234567"
|
134
|
+
# Base64.decode64("MDEyMzQ1Njc=") # => "01234567"
|
135
|
+
# Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
|
136
|
+
#
|
137
|
+
# \Method Base64.strict_decode64 strictly enforces padding size:
|
138
|
+
#
|
139
|
+
# Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError
|
140
|
+
# Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567"
|
141
|
+
# Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
|
142
|
+
#
|
143
|
+
# \Method Base64.urlsafe_decode64 allows padding in the encoded string,
|
144
|
+
# which if present, must be correct:
|
145
|
+
# see {Padding}[Base64.html#module-Base64-label-Padding], above:
|
146
|
+
#
|
147
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
|
148
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
|
149
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
|
150
|
+
#
|
151
|
+
# == Newlines
|
152
|
+
#
|
153
|
+
# An encoded string returned by Base64.encode64 or Base64.urlsafe_encode64
|
154
|
+
# has an embedded newline character
|
155
|
+
# after each 60-character sequence, and, if non-empty, at the end:
|
156
|
+
#
|
157
|
+
# # No newline if empty.
|
158
|
+
# encoded = Base64.encode64("\x00" * 0)
|
159
|
+
# encoded.index("\n") # => nil
|
160
|
+
#
|
161
|
+
# # Newline at end of short output.
|
162
|
+
# encoded = Base64.encode64("\x00" * 1)
|
163
|
+
# encoded.size # => 4
|
164
|
+
# encoded.index("\n") # => 4
|
165
|
+
#
|
166
|
+
# # Newline at end of longer output.
|
167
|
+
# encoded = Base64.encode64("\x00" * 45)
|
168
|
+
# encoded.size # => 60
|
169
|
+
# encoded.index("\n") # => 60
|
170
|
+
#
|
171
|
+
# # Newlines embedded and at end of still longer output.
|
172
|
+
# encoded = Base64.encode64("\x00" * 46)
|
173
|
+
# encoded.size # => 65
|
174
|
+
# encoded.rindex("\n") # => 65
|
175
|
+
# encoded.split("\n").map {|s| s.size } # => [60, 4]
|
176
|
+
#
|
177
|
+
# The string to be encoded may itself contain newlines,
|
178
|
+
# which are encoded as \Base64:
|
179
|
+
#
|
180
|
+
# # Base64.encode64("\n\n\n") # => "CgoK\n"
|
181
|
+
# s = "This is line 1\nThis is line 2\n"
|
182
|
+
# Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
20
183
|
#
|
21
|
-
# The purpose of using base64 to encode data is that it translates any
|
22
|
-
# binary data into purely printable characters.
|
23
|
-
|
24
184
|
module Base64
|
185
|
+
|
186
|
+
VERSION = "0.3.0"
|
187
|
+
|
25
188
|
module_function
|
26
189
|
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
190
|
+
# :call-seq:
|
191
|
+
# Base64.encode64(string) -> encoded_string
|
192
|
+
#
|
193
|
+
# Returns a string containing the RFC-2045-compliant \Base64-encoding of +string+.
|
194
|
+
#
|
195
|
+
# Per RFC 2045, the returned string may contain the URL-unsafe characters
|
196
|
+
# <tt>+</tt> or <tt>/</tt>;
|
197
|
+
# see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
|
198
|
+
#
|
199
|
+
# Base64.encode64("\xFB\xEF\xBE") # => "++++\n"
|
200
|
+
# Base64.encode64("\xFF\xFF\xFF") # => "////\n"
|
201
|
+
#
|
202
|
+
# The returned string may include padding;
|
203
|
+
# see {Padding}[Base64.html#module-Base64-label-Padding] above.
|
204
|
+
#
|
205
|
+
# Base64.encode64('*') # => "Kg==\n"
|
30
206
|
#
|
31
|
-
#
|
32
|
-
#
|
207
|
+
# The returned string ends with a newline character, and if sufficiently long
|
208
|
+
# will have one or more embedded newline characters;
|
209
|
+
# see {Newlines}[Base64.html#module-Base64-label-Newlines] above:
|
33
210
|
#
|
34
|
-
#
|
211
|
+
# Base64.encode64('*') # => "Kg==\n"
|
212
|
+
# Base64.encode64('*' * 46)
|
213
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq\nKg==\n"
|
214
|
+
#
|
215
|
+
# The string to be encoded may itself contain newlines,
|
216
|
+
# which will be encoded as ordinary \Base64:
|
217
|
+
#
|
218
|
+
# Base64.encode64("\n\n\n") # => "CgoK\n"
|
219
|
+
# s = "This is line 1\nThis is line 2\n"
|
220
|
+
# Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
35
221
|
#
|
36
|
-
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
|
37
|
-
# UnVieQ==
|
38
222
|
def encode64(bin)
|
39
223
|
[bin].pack("m")
|
40
224
|
end
|
41
225
|
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
226
|
+
# :call-seq:
|
227
|
+
# Base64.decode(encoded_string) -> decoded_string
|
228
|
+
#
|
229
|
+
# Returns a string containing the decoding of an RFC-2045-compliant
|
230
|
+
# \Base64-encoded string +encoded_string+:
|
231
|
+
#
|
232
|
+
# s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
233
|
+
# Base64.decode64(s) # => "This is line 1\nThis is line 2\n"
|
234
|
+
#
|
235
|
+
# Non-\Base64 characters in +encoded_string+ are ignored;
|
236
|
+
# see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
|
237
|
+
# these include newline characters and characters <tt>-</tt> and <tt>/</tt>:
|
238
|
+
#
|
239
|
+
# Base64.decode64("\x00\n-_") # => ""
|
240
|
+
#
|
241
|
+
# Padding in +encoded_string+ (even if incorrect) is ignored:
|
242
|
+
#
|
243
|
+
# Base64.decode64("MDEyMzQ1Njc") # => "01234567"
|
244
|
+
# Base64.decode64("MDEyMzQ1Njc=") # => "01234567"
|
245
|
+
# Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
|
246
|
+
#
|
58
247
|
def decode64(str)
|
59
|
-
str.
|
248
|
+
str.unpack1("m")
|
60
249
|
end
|
61
250
|
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
251
|
+
# :call-seq:
|
252
|
+
# Base64.strict_encode64(string) -> encoded_string
|
253
|
+
#
|
254
|
+
# Returns a string containing the RFC-2045-compliant \Base64-encoding of +string+.
|
255
|
+
#
|
256
|
+
# Per RFC 2045, the returned string may contain the URL-unsafe characters
|
257
|
+
# <tt>+</tt> or <tt>/</tt>;
|
258
|
+
# see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
|
259
|
+
#
|
260
|
+
# Base64.strict_encode64("\xFB\xEF\xBE") # => "++++\n"
|
261
|
+
# Base64.strict_encode64("\xFF\xFF\xFF") # => "////\n"
|
262
|
+
#
|
263
|
+
# The returned string may include padding;
|
264
|
+
# see {Padding}[Base64.html#module-Base64-label-Padding] above.
|
265
|
+
#
|
266
|
+
# Base64.strict_encode64('*') # => "Kg==\n"
|
267
|
+
#
|
268
|
+
# The returned string will have no newline characters, regardless of its length;
|
269
|
+
# see {Newlines}[Base64.html#module-Base64-label-Newlines] above:
|
270
|
+
#
|
271
|
+
# Base64.strict_encode64('*') # => "Kg=="
|
272
|
+
# Base64.strict_encode64('*' * 46)
|
273
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg=="
|
274
|
+
#
|
275
|
+
# The string to be encoded may itself contain newlines,
|
276
|
+
# which will be encoded as ordinary \Base64:
|
277
|
+
#
|
278
|
+
# Base64.strict_encode64("\n\n\n") # => "CgoK"
|
279
|
+
# s = "This is line 1\nThis is line 2\n"
|
280
|
+
# Base64.strict_encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
|
281
|
+
#
|
65
282
|
def strict_encode64(bin)
|
66
283
|
[bin].pack("m0")
|
67
284
|
end
|
68
285
|
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
286
|
+
# :call-seq:
|
287
|
+
# Base64.strict_decode64(encoded_string) -> decoded_string
|
288
|
+
#
|
289
|
+
# Returns a string containing the decoding of an RFC-2045-compliant
|
290
|
+
# \Base64-encoded string +encoded_string+:
|
291
|
+
#
|
292
|
+
# s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
|
293
|
+
# Base64.strict_decode64(s) # => "This is line 1\nThis is line 2\n"
|
294
|
+
#
|
295
|
+
# Non-\Base64 characters in +encoded_string+ are not allowed;
|
296
|
+
# see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
|
297
|
+
# these include newline characters and characters <tt>-</tt> and <tt>/</tt>:
|
298
|
+
#
|
299
|
+
# Base64.strict_decode64("\n") # Raises ArgumentError
|
300
|
+
# Base64.strict_decode64('-') # Raises ArgumentError
|
301
|
+
# Base64.strict_decode64('_') # Raises ArgumentError
|
302
|
+
#
|
303
|
+
# Padding in +encoded_string+, if present, must be correct:
|
304
|
+
#
|
305
|
+
# Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError
|
306
|
+
# Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567"
|
307
|
+
# Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
|
308
|
+
#
|
73
309
|
def strict_decode64(str)
|
74
|
-
str.
|
310
|
+
str.unpack1("m0")
|
75
311
|
end
|
76
312
|
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
313
|
+
# :call-seq:
|
314
|
+
# Base64.urlsafe_encode64(string) -> encoded_string
|
315
|
+
#
|
316
|
+
# Returns the RFC-4648-compliant \Base64-encoding of +string+.
|
317
|
+
#
|
318
|
+
# Per RFC 4648, the returned string will not contain the URL-unsafe characters
|
319
|
+
# <tt>+</tt> or <tt>/</tt>,
|
320
|
+
# but instead may contain the URL-safe characters
|
321
|
+
# <tt>-</tt> and <tt>_</tt>;
|
322
|
+
# see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
|
323
|
+
#
|
324
|
+
# Base64.urlsafe_encode64("\xFB\xEF\xBE") # => "----"
|
325
|
+
# Base64.urlsafe_encode64("\xFF\xFF\xFF") # => "____"
|
326
|
+
#
|
327
|
+
# By default, the returned string may have padding;
|
328
|
+
# see {Padding}[Base64.html#module-Base64-label-Padding], above:
|
329
|
+
#
|
330
|
+
# Base64.urlsafe_encode64('*') # => "Kg=="
|
331
|
+
#
|
332
|
+
# Optionally, you can suppress padding:
|
333
|
+
#
|
334
|
+
# Base64.urlsafe_encode64('*', padding: false) # => "Kg"
|
335
|
+
#
|
336
|
+
# The returned string will have no newline characters, regardless of its length;
|
337
|
+
# see {Newlines}[Base64.html#module-Base64-label-Newlines] above:
|
338
|
+
#
|
339
|
+
# Base64.urlsafe_encode64('*') # => "Kg=="
|
340
|
+
# Base64.urlsafe_encode64('*' * 46)
|
341
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg=="
|
342
|
+
#
|
83
343
|
def urlsafe_encode64(bin, padding: true)
|
84
344
|
str = strict_encode64(bin)
|
85
345
|
str.chomp!("==") or str.chomp!("=") unless padding
|
@@ -87,14 +347,25 @@ module Base64
|
|
87
347
|
str
|
88
348
|
end
|
89
349
|
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
350
|
+
# :call-seq:
|
351
|
+
# Base64.urlsafe_decode64(encoded_string) -> decoded_string
|
352
|
+
#
|
353
|
+
# Returns the decoding of an RFC-4648-compliant \Base64-encoded string +encoded_string+:
|
354
|
+
#
|
355
|
+
# +encoded_string+ may not contain non-Base64 characters;
|
356
|
+
# see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
|
357
|
+
#
|
358
|
+
# Base64.urlsafe_decode64('+') # Raises ArgumentError.
|
359
|
+
# Base64.urlsafe_decode64('/') # Raises ArgumentError.
|
360
|
+
# Base64.urlsafe_decode64("\n") # Raises ArgumentError.
|
361
|
+
#
|
362
|
+
# Padding in +encoded_string+, if present, must be correct:
|
363
|
+
# see {Padding}[Base64.html#module-Base64-label-Padding], above:
|
364
|
+
#
|
365
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
|
366
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
|
367
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
|
368
|
+
#
|
98
369
|
def urlsafe_decode64(str)
|
99
370
|
# NOTE: RFC 4648 does say nothing about unpadded input, but says that
|
100
371
|
# "the excess pad characters MAY also be ignored", so it is inferred that
|
data/sig/base64.rbs
ADDED
@@ -0,0 +1,355 @@
|
|
1
|
+
# <!-- rdoc-file=lib/base64.rb -->
|
2
|
+
# Module Base64 provides methods for:
|
3
|
+
#
|
4
|
+
# * Encoding a binary string (containing non-ASCII characters) as a string of
|
5
|
+
# printable ASCII characters.
|
6
|
+
# * Decoding such an encoded string.
|
7
|
+
#
|
8
|
+
# Base64 is commonly used in contexts where binary data is not allowed or
|
9
|
+
# supported:
|
10
|
+
#
|
11
|
+
# * Images in HTML or CSS files, or in URLs.
|
12
|
+
# * Email attachments.
|
13
|
+
#
|
14
|
+
# A Base64-encoded string is about one-third larger that its source. See the
|
15
|
+
# [Wikipedia article](https://en.wikipedia.org/wiki/Base64) for more
|
16
|
+
# information.
|
17
|
+
#
|
18
|
+
# This module provides three pairs of encode/decode methods. Your choices among
|
19
|
+
# these methods should depend on:
|
20
|
+
#
|
21
|
+
# * Which character set is to be used for encoding and decoding.
|
22
|
+
# * Whether "padding" is to be used.
|
23
|
+
# * Whether encoded strings are to contain newlines.
|
24
|
+
#
|
25
|
+
# Note: Examples on this page assume that the including program has executed:
|
26
|
+
#
|
27
|
+
# require 'base64'
|
28
|
+
#
|
29
|
+
# ## Encoding Character Sets
|
30
|
+
#
|
31
|
+
# A Base64-encoded string consists only of characters from a 64-character set:
|
32
|
+
#
|
33
|
+
# * `('A'..'Z')`.
|
34
|
+
# * `('a'..'z')`.
|
35
|
+
# * `('0'..'9')`.
|
36
|
+
# * `=`, the 'padding' character.
|
37
|
+
# * Either:
|
38
|
+
# * `%w[+ /]`:
|
39
|
+
# [RFC-2045-compliant](https://datatracker.ietf.org/doc/html/rfc2045);
|
40
|
+
# *not* safe for URLs.
|
41
|
+
# * `%w[- _]`:
|
42
|
+
# [RFC-4648-compliant](https://datatracker.ietf.org/doc/html/rfc4648);
|
43
|
+
# safe for URLs.
|
44
|
+
#
|
45
|
+
# If you are working with Base64-encoded strings that will come from or be put
|
46
|
+
# into URLs, you should choose this encoder-decoder pair of RFC-4648-compliant
|
47
|
+
# methods:
|
48
|
+
#
|
49
|
+
# * Base64.urlsafe_encode64 and Base64.urlsafe_decode64.
|
50
|
+
#
|
51
|
+
# Otherwise, you may choose any of the pairs in this module, including the pair
|
52
|
+
# above, or the RFC-2045-compliant pairs:
|
53
|
+
#
|
54
|
+
# * Base64.encode64 and Base64.decode64.
|
55
|
+
# * Base64.strict_encode64 and Base64.strict_decode64.
|
56
|
+
#
|
57
|
+
# ## Padding
|
58
|
+
#
|
59
|
+
# Base64-encoding changes a triplet of input bytes into a quartet of output
|
60
|
+
# characters.
|
61
|
+
#
|
62
|
+
# **Padding in Encode Methods**
|
63
|
+
#
|
64
|
+
# Padding -- extending an encoded string with zero, one, or two trailing `=`
|
65
|
+
# characters -- is performed by methods Base64.encode64, Base64.strict_encode64,
|
66
|
+
# and, by default, Base64.urlsafe_encode64:
|
67
|
+
#
|
68
|
+
# Base64.encode64('s') # => "cw==\n"
|
69
|
+
# Base64.strict_encode64('s') # => "cw=="
|
70
|
+
# Base64.urlsafe_encode64('s') # => "cw=="
|
71
|
+
# Base64.urlsafe_encode64('s', padding: false) # => "cw"
|
72
|
+
#
|
73
|
+
# When padding is performed, the encoded string is always of length *4n*, where
|
74
|
+
# `n` is a non-negative integer:
|
75
|
+
#
|
76
|
+
# * Input bytes of length *3n* generate unpadded output characters of length
|
77
|
+
# *4n*:
|
78
|
+
#
|
79
|
+
# # n = 1: 3 bytes => 4 characters.
|
80
|
+
# Base64.strict_encode64('123') # => "MDEy"
|
81
|
+
# # n = 2: 6 bytes => 8 characters.
|
82
|
+
# Base64.strict_encode64('123456') # => "MDEyMzQ1"
|
83
|
+
#
|
84
|
+
# * Input bytes of length *3n+1* generate padded output characters of length
|
85
|
+
# *4(n+1)*, with two padding characters at the end:
|
86
|
+
#
|
87
|
+
# # n = 1: 4 bytes => 8 characters.
|
88
|
+
# Base64.strict_encode64('1234') # => "MDEyMw=="
|
89
|
+
# # n = 2: 7 bytes => 12 characters.
|
90
|
+
# Base64.strict_encode64('1234567') # => "MDEyMzQ1Ng=="
|
91
|
+
#
|
92
|
+
# * Input bytes of length *3n+2* generate padded output characters of length
|
93
|
+
# *4(n+1)*, with one padding character at the end:
|
94
|
+
#
|
95
|
+
# # n = 1: 5 bytes => 8 characters.
|
96
|
+
# Base64.strict_encode64('12345') # => "MDEyMzQ="
|
97
|
+
# # n = 2: 8 bytes => 12 characters.
|
98
|
+
# Base64.strict_encode64('12345678') # => "MDEyMzQ1Njc="
|
99
|
+
#
|
100
|
+
# When padding is suppressed, for a positive integer *n*:
|
101
|
+
#
|
102
|
+
# * Input bytes of length *3n* generate unpadded output characters of length
|
103
|
+
# *4n*:
|
104
|
+
#
|
105
|
+
# # n = 1: 3 bytes => 4 characters.
|
106
|
+
# Base64.urlsafe_encode64('123', padding: false) # => "MDEy"
|
107
|
+
# # n = 2: 6 bytes => 8 characters.
|
108
|
+
# Base64.urlsafe_encode64('123456', padding: false) # => "MDEyMzQ1"
|
109
|
+
#
|
110
|
+
# * Input bytes of length *3n+1* generate unpadded output characters of length
|
111
|
+
# *4n+2*, with two padding characters at the end:
|
112
|
+
#
|
113
|
+
# # n = 1: 4 bytes => 6 characters.
|
114
|
+
# Base64.urlsafe_encode64('1234', padding: false) # => "MDEyMw"
|
115
|
+
# # n = 2: 7 bytes => 10 characters.
|
116
|
+
# Base64.urlsafe_encode64('1234567', padding: false) # => "MDEyMzQ1Ng"
|
117
|
+
#
|
118
|
+
# * Input bytes of length *3n+2* generate unpadded output characters of length
|
119
|
+
# *4n+3*, with one padding character at the end:
|
120
|
+
#
|
121
|
+
# # n = 1: 5 bytes => 7 characters.
|
122
|
+
# Base64.urlsafe_encode64('12345', padding: false) # => "MDEyMzQ"
|
123
|
+
# # m = 2: 8 bytes => 11 characters.
|
124
|
+
# Base64.urlsafe_encode64('12345678', padding: false) # => "MDEyMzQ1Njc"
|
125
|
+
#
|
126
|
+
# **Padding in Decode Methods**
|
127
|
+
#
|
128
|
+
# All of the Base64 decode methods support (but do not require) padding.
|
129
|
+
#
|
130
|
+
# Method Base64.decode64 does not check the size of the padding:
|
131
|
+
#
|
132
|
+
# Base64.decode64("MDEyMzQ1Njc") # => "01234567"
|
133
|
+
# Base64.decode64("MDEyMzQ1Njc=") # => "01234567"
|
134
|
+
# Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
|
135
|
+
#
|
136
|
+
# Method Base64.strict_decode64 strictly enforces padding size:
|
137
|
+
#
|
138
|
+
# Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError
|
139
|
+
# Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567"
|
140
|
+
# Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
|
141
|
+
#
|
142
|
+
# Method Base64.urlsafe_decode64 allows padding in `str`, which if present, must
|
143
|
+
# be correct: see [Padding](Base64.html#module-Base64-label-Padding), above:
|
144
|
+
#
|
145
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
|
146
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
|
147
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
|
148
|
+
#
|
149
|
+
# ## Newlines
|
150
|
+
#
|
151
|
+
# An encoded string returned by Base64.encode64 or Base64.urlsafe_encode64 has
|
152
|
+
# an embedded newline character after each 60-character sequence, and, if
|
153
|
+
# non-empty, at the end:
|
154
|
+
#
|
155
|
+
# # No newline if empty.
|
156
|
+
# encoded = Base64.encode64("\x00" * 0)
|
157
|
+
# encoded.index("\n") # => nil
|
158
|
+
#
|
159
|
+
# # Newline at end of short output.
|
160
|
+
# encoded = Base64.encode64("\x00" * 1)
|
161
|
+
# encoded.size # => 4
|
162
|
+
# encoded.index("\n") # => 4
|
163
|
+
#
|
164
|
+
# # Newline at end of longer output.
|
165
|
+
# encoded = Base64.encode64("\x00" * 45)
|
166
|
+
# encoded.size # => 60
|
167
|
+
# encoded.index("\n") # => 60
|
168
|
+
#
|
169
|
+
# # Newlines embedded and at end of still longer output.
|
170
|
+
# encoded = Base64.encode64("\x00" * 46)
|
171
|
+
# encoded.size # => 65
|
172
|
+
# encoded.rindex("\n") # => 65
|
173
|
+
# encoded.split("\n").map {|s| s.size } # => [60, 4]
|
174
|
+
#
|
175
|
+
# The string to be encoded may itself contain newlines, which are encoded as
|
176
|
+
# Base64:
|
177
|
+
#
|
178
|
+
# # Base64.encode64("\n\n\n") # => "CgoK\n"
|
179
|
+
# s = "This is line 1\nThis is line 2\n"
|
180
|
+
# Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
181
|
+
#
|
182
|
+
module Base64
|
183
|
+
# <!--
|
184
|
+
# rdoc-file=lib/base64.rb
|
185
|
+
# - decode64(str)
|
186
|
+
# -->
|
187
|
+
# Returns a string containing the decoding of an RFC-2045-compliant
|
188
|
+
# Base64-encoded string `str`:
|
189
|
+
#
|
190
|
+
# s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
191
|
+
# Base64.decode64(s) # => "This is line 1\nThis is line 2\n"
|
192
|
+
#
|
193
|
+
# Non-Base64 characters in `str` are ignored; see [Encoding Character
|
194
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: these
|
195
|
+
# include newline characters and characters `-` and `/`:
|
196
|
+
#
|
197
|
+
# Base64.decode64("\x00\n-_") # => ""
|
198
|
+
#
|
199
|
+
# Padding in `str` (even if incorrect) is ignored:
|
200
|
+
#
|
201
|
+
# Base64.decode64("MDEyMzQ1Njc") # => "01234567"
|
202
|
+
# Base64.decode64("MDEyMzQ1Njc=") # => "01234567"
|
203
|
+
# Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
|
204
|
+
#
|
205
|
+
def self?.decode64: (String str) -> String
|
206
|
+
|
207
|
+
# <!--
|
208
|
+
# rdoc-file=lib/base64.rb
|
209
|
+
# - encode64(bin)
|
210
|
+
# -->
|
211
|
+
# Returns a string containing the RFC-2045-compliant Base64-encoding of `bin`.
|
212
|
+
#
|
213
|
+
# Per RFC 2045, the returned string may contain the URL-unsafe characters `+` or
|
214
|
+
# `/`; see [Encoding Character
|
215
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above:
|
216
|
+
#
|
217
|
+
# Base64.encode64("\xFB\xEF\xBE") # => "++++\n"
|
218
|
+
# Base64.encode64("\xFF\xFF\xFF") # => "////\n"
|
219
|
+
#
|
220
|
+
# The returned string may include padding; see
|
221
|
+
# [Padding](Base64.html#module-Base64-label-Padding) above.
|
222
|
+
#
|
223
|
+
# Base64.encode64('*') # => "Kg==\n"
|
224
|
+
#
|
225
|
+
# The returned string ends with a newline character, and if sufficiently long
|
226
|
+
# will have one or more embedded newline characters; see
|
227
|
+
# [Newlines](Base64.html#module-Base64-label-Newlines) above:
|
228
|
+
#
|
229
|
+
# Base64.encode64('*') # => "Kg==\n"
|
230
|
+
# Base64.encode64('*' * 46)
|
231
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq\nKg==\n"
|
232
|
+
#
|
233
|
+
# The string to be encoded may itself contain newlines, which will be encoded as
|
234
|
+
# ordinary Base64:
|
235
|
+
#
|
236
|
+
# Base64.encode64("\n\n\n") # => "CgoK\n"
|
237
|
+
# s = "This is line 1\nThis is line 2\n"
|
238
|
+
# Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
239
|
+
#
|
240
|
+
def self?.encode64: (String bin) -> String
|
241
|
+
|
242
|
+
# <!--
|
243
|
+
# rdoc-file=lib/base64.rb
|
244
|
+
# - strict_decode64(str)
|
245
|
+
# -->
|
246
|
+
# Returns a string containing the decoding of an RFC-2045-compliant
|
247
|
+
# Base64-encoded string `str`:
|
248
|
+
#
|
249
|
+
# s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
|
250
|
+
# Base64.strict_decode64(s) # => "This is line 1\nThis is line 2\n"
|
251
|
+
#
|
252
|
+
# Non-Base64 characters in `str` not allowed; see [Encoding Character
|
253
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: these
|
254
|
+
# include newline characters and characters `-` and `/`:
|
255
|
+
#
|
256
|
+
# Base64.strict_decode64("\n") # Raises ArgumentError
|
257
|
+
# Base64.strict_decode64('-') # Raises ArgumentError
|
258
|
+
# Base64.strict_decode64('_') # Raises ArgumentError
|
259
|
+
#
|
260
|
+
# Padding in `str`, if present, must be correct:
|
261
|
+
#
|
262
|
+
# Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError
|
263
|
+
# Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567"
|
264
|
+
# Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
|
265
|
+
#
|
266
|
+
def self?.strict_decode64: (String str) -> String
|
267
|
+
|
268
|
+
# <!--
|
269
|
+
# rdoc-file=lib/base64.rb
|
270
|
+
# - strict_encode64(bin)
|
271
|
+
# -->
|
272
|
+
# Returns a string containing the RFC-2045-compliant Base64-encoding of `bin`.
|
273
|
+
#
|
274
|
+
# Per RFC 2045, the returned string may contain the URL-unsafe characters `+` or
|
275
|
+
# `/`; see [Encoding Character
|
276
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above:
|
277
|
+
#
|
278
|
+
# Base64.strict_encode64("\xFB\xEF\xBE") # => "++++\n"
|
279
|
+
# Base64.strict_encode64("\xFF\xFF\xFF") # => "////\n"
|
280
|
+
#
|
281
|
+
# The returned string may include padding; see
|
282
|
+
# [Padding](Base64.html#module-Base64-label-Padding) above.
|
283
|
+
#
|
284
|
+
# Base64.strict_encode64('*') # => "Kg==\n"
|
285
|
+
#
|
286
|
+
# The returned string will have no newline characters, regardless of its length;
|
287
|
+
# see [Newlines](Base64.html#module-Base64-label-Newlines) above:
|
288
|
+
#
|
289
|
+
# Base64.strict_encode64('*') # => "Kg=="
|
290
|
+
# Base64.strict_encode64('*' * 46)
|
291
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg=="
|
292
|
+
#
|
293
|
+
# The string to be encoded may itself contain newlines, which will be encoded as
|
294
|
+
# ordinary Base64:
|
295
|
+
#
|
296
|
+
# Base64.strict_encode64("\n\n\n") # => "CgoK"
|
297
|
+
# s = "This is line 1\nThis is line 2\n"
|
298
|
+
# Base64.strict_encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
|
299
|
+
#
|
300
|
+
def self?.strict_encode64: (String bin) -> String
|
301
|
+
|
302
|
+
# <!--
|
303
|
+
# rdoc-file=lib/base64.rb
|
304
|
+
# - urlsafe_decode64(str)
|
305
|
+
# -->
|
306
|
+
# Returns the decoding of an RFC-4648-compliant Base64-encoded string `str`:
|
307
|
+
#
|
308
|
+
# `str` may not contain non-Base64 characters; see [Encoding Character
|
309
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above:
|
310
|
+
#
|
311
|
+
# Base64.urlsafe_decode64('+') # Raises ArgumentError.
|
312
|
+
# Base64.urlsafe_decode64('/') # Raises ArgumentError.
|
313
|
+
# Base64.urlsafe_decode64("\n") # Raises ArgumentError.
|
314
|
+
#
|
315
|
+
# Padding in `str`, if present, must be correct: see
|
316
|
+
# [Padding](Base64.html#module-Base64-label-Padding), above:
|
317
|
+
#
|
318
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
|
319
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
|
320
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
|
321
|
+
#
|
322
|
+
def self?.urlsafe_decode64: (String str) -> String
|
323
|
+
|
324
|
+
# <!--
|
325
|
+
# rdoc-file=lib/base64.rb
|
326
|
+
# - urlsafe_encode64(bin, padding: true)
|
327
|
+
# -->
|
328
|
+
# Returns the RFC-4648-compliant Base64-encoding of `bin`.
|
329
|
+
#
|
330
|
+
# Per RFC 4648, the returned string will not contain the URL-unsafe characters
|
331
|
+
# `+` or `/`, but instead may contain the URL-safe characters `-` and `_`; see
|
332
|
+
# [Encoding Character
|
333
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above:
|
334
|
+
#
|
335
|
+
# Base64.urlsafe_encode64("\xFB\xEF\xBE") # => "----"
|
336
|
+
# Base64.urlsafe_encode64("\xFF\xFF\xFF") # => "____"
|
337
|
+
#
|
338
|
+
# By default, the returned string may have padding; see
|
339
|
+
# [Padding](Base64.html#module-Base64-label-Padding), above:
|
340
|
+
#
|
341
|
+
# Base64.urlsafe_encode64('*') # => "Kg=="
|
342
|
+
#
|
343
|
+
# Optionally, you can suppress padding:
|
344
|
+
#
|
345
|
+
# Base64.urlsafe_encode64('*', padding: false) # => "Kg"
|
346
|
+
#
|
347
|
+
# The returned string will have no newline characters, regardless of its length;
|
348
|
+
# see [Newlines](Base64.html#module-Base64-label-Newlines) above:
|
349
|
+
#
|
350
|
+
# Base64.urlsafe_encode64('*') # => "Kg=="
|
351
|
+
# Base64.urlsafe_encode64('*' * 46)
|
352
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg=="
|
353
|
+
#
|
354
|
+
def self?.urlsafe_encode64: (String bin, ?padding: boolish) -> String
|
355
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base64
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke Endoh
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: Support for encoding and decoding binary data using a Base64 representation.
|
14
13
|
email:
|
@@ -17,9 +16,12 @@ executables: []
|
|
17
16
|
extensions: []
|
18
17
|
extra_rdoc_files: []
|
19
18
|
files:
|
20
|
-
-
|
19
|
+
- BSDL
|
20
|
+
- COPYING
|
21
|
+
- LEGAL
|
21
22
|
- README.md
|
22
23
|
- lib/base64.rb
|
24
|
+
- sig/base64.rbs
|
23
25
|
homepage: https://github.com/ruby/base64
|
24
26
|
licenses:
|
25
27
|
- Ruby
|
@@ -27,7 +29,7 @@ licenses:
|
|
27
29
|
metadata:
|
28
30
|
homepage_uri: https://github.com/ruby/base64
|
29
31
|
source_code_uri: https://github.com/ruby/base64
|
30
|
-
|
32
|
+
changelog_uri: https://github.com/ruby/base64/releases
|
31
33
|
rdoc_options: []
|
32
34
|
require_paths:
|
33
35
|
- lib
|
@@ -35,15 +37,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
37
|
requirements:
|
36
38
|
- - ">="
|
37
39
|
- !ruby/object:Gem::Version
|
38
|
-
version: 2.
|
40
|
+
version: '2.4'
|
39
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
43
45
|
version: '0'
|
44
46
|
requirements: []
|
45
|
-
rubygems_version: 3.
|
46
|
-
signing_key:
|
47
|
+
rubygems_version: 3.6.7
|
47
48
|
specification_version: 4
|
48
49
|
summary: Support for encoding and decoding binary data using a Base64 representation.
|
49
50
|
test_files: []
|