pax_global_header00006660000000000000000000000064150162473430014517gustar00rootroot0000000000000052 comment=c5d3c7f3c06b40e956a04b4df57a60c0f5daea39 base64-0.3.0/000077500000000000000000000000001501624734300126035ustar00rootroot00000000000000base64-0.3.0/.github/000077500000000000000000000000001501624734300141435ustar00rootroot00000000000000base64-0.3.0/.github/dependabot.yml000066400000000000000000000001661501624734300167760ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: 'github-actions' directory: '/' schedule: interval: 'weekly' base64-0.3.0/.github/workflows/000077500000000000000000000000001501624734300162005ustar00rootroot00000000000000base64-0.3.0/.github/workflows/push_gem.yml000066400000000000000000000021671501624734300205400ustar00rootroot00000000000000name: Publish gem to rubygems.org on: push: tags: - 'v*' permissions: contents: read jobs: push: if: github.repository == 'ruby/base64' runs-on: ubuntu-latest environment: name: rubygems.org url: https://rubygems.org/gems/base64 permissions: contents: write id-token: write steps: - name: Harden Runner uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 with: egress-policy: audit - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up Ruby uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0 with: bundler-cache: true ruby-version: "ruby" - name: Publish to RubyGems uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1 - name: Create GitHub release run: | tag_name="$(git describe --tags --abbrev=0)" gh release create "${tag_name}" --verify-tag --generate-notes env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} base64-0.3.0/.github/workflows/sig.yml000066400000000000000000000007351501624734300175120ustar00rootroot00000000000000name: sig on: [push, pull_request] jobs: sig: runs-on: "ubuntu-latest" steps: - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: bundler-cache: true ruby-version: ruby - name: Install dependencies run: | bundle config set with 'sig' bundle install - name: Run RBS test, annotate and confirm run: bundle exec rake rbs:{test,annotate,confirm} base64-0.3.0/.github/workflows/test.yml000066400000000000000000000016731501624734300177110ustar00rootroot00000000000000name: test on: [push, pull_request] jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master with: min_version: 2.4 test: needs: ruby-versions name: build (${{ matrix.ruby }} / ${{ matrix.os }}) strategy: matrix: ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }} os: [ ubuntu-latest, macos-latest, windows-latest ] exclude: - { os: macos-latest, ruby: 2.4 } - { os: macos-latest, ruby: 2.5 } - { os: windows-latest, ruby: truffleruby-head } - { os: windows-latest, ruby: truffleruby } runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - name: Install dependencies run: | bundle config set without 'sig' bundle install - name: Run test run: rake test base64-0.3.0/.gitignore000066400000000000000000000001261501624734300145720ustar00rootroot00000000000000/.bundle/ /.yardoc /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ Gemfile.lock base64-0.3.0/BSDL000066400000000000000000000024131501624734300132520ustar00rootroot00000000000000Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. base64-0.3.0/COPYING000066400000000000000000000045731501624734300136470ustar00rootroot00000000000000Ruby is copyrighted free software by Yukihiro Matsumoto . You can redistribute it and/or modify it under either the terms of the 2-clause BSDL (see the file BSDL), or the conditions below: 1. You may make and give away verbatim copies of the source form of the software without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may modify your copy of the software in any way, provided that you do at least ONE of the following: a. place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or by allowing the author to include your modifications in the software. b. use the modified software only within your corporation or organization. c. give non-standard binaries non-standard names, with instructions on where to get the original software distribution. d. make other distribution arrangements with the author. 3. You may distribute the software in object code or binary form, provided that you do at least ONE of the following: a. distribute the binaries and library files of the software, together with instructions (in the manual page or equivalent) on where to get the original distribution. b. accompany the distribution with the machine-readable source of the software. c. give non-standard binaries non-standard names, with instructions on where to get the original software distribution. d. make other distribution arrangements with the author. 4. You may modify and include the part of the software into any other software (possibly commercial). But some files in the distribution are not written by the author, so that they are not under these terms. For the list of those files and their copying conditions, see the file LEGAL. 5. The scripts and library files supplied as input to or produced as output from the software do not automatically fall under the copyright of the software, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this software. 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. base64-0.3.0/Gemfile000066400000000000000000000001611501624734300140740ustar00rootroot00000000000000source "https://rubygems.org" gem "rake" gem "test-unit" group :sig do gem "rbs" gem "rdoc", "<= 6.11" end base64-0.3.0/LEGAL000066400000000000000000000060201501624734300133500ustar00rootroot00000000000000# -*- rdoc -*- = LEGAL NOTICE INFORMATION -------------------------- All the files in this distribution are covered under either the Ruby's license (see the file COPYING) or public-domain except some files mentioned below. == MIT License >>> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. == Old-style BSD license >>> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IMPORTANT NOTE:: From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change paragraph 3 above is now null and void. base64-0.3.0/README.md000066400000000000000000000026251501624734300140670ustar00rootroot00000000000000# Base64 The Base64 module provides for the encoding (`#encode64`, `#strict_encode64`, `#urlsafe_encode64`) and decoding (`#decode64`, `#strict_decode64`, `#urlsafe_decode64`) of binary data using a Base64 representation. ## Installation Add this line to your application's Gemfile: ```ruby gem 'base64' ``` And then execute: $ bundle install Or install it yourself as: $ gem install base64 ## Usage A simple encoding and decoding. ```ruby require "base64" enc = Base64.encode64('Send reinforcements') # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n" plain = Base64.decode64(enc) # -> "Send reinforcements" ``` The purpose of using base64 to encode data is that it translates any binary data into purely printable characters. ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/base64. base64-0.3.0/Rakefile000066400000000000000000000012441501624734300142510ustar00rootroot00000000000000require "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new(:test) do |t| t.libs << "test" t.libs << "lib" t.test_files = FileList["test/**/test_*.rb"] end namespace :rbs do task :test do sh "ruby -I lib test_sig/test_base64.rb" end task :annotate do require "tmpdir" require "pathname" Dir.mktmpdir do |tmpdir| system("rdoc --ri --output #{tmpdir}/doc --root=. lib") system("rbs annotate --no-system --no-gems --no-site --no-home -d #{tmpdir}/doc sig") end end task :confirm do puts "Testing if RBS docs are updated with respect to RDoc" sh "git diff --exit-code sig/" end end task :default => :test base64-0.3.0/base64.gemspec000066400000000000000000000022331501624734300152340ustar00rootroot00000000000000name = File.basename(__FILE__, ".gemspec") version = ["lib", Array.new(name.count("-")+1).join("/")].find do |dir| break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line| /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1 end rescue nil end Gem::Specification.new do |spec| spec.name = name spec.version = version spec.authors = ["Yusuke Endoh"] spec.email = ["mame@ruby-lang.org"] spec.summary = %q{Support for encoding and decoding binary data using a Base64 representation.} spec.description = %q{Support for encoding and decoding binary data using a Base64 representation.} spec.homepage = "https://github.com/ruby/base64" spec.required_ruby_version = Gem::Requirement.new(">= 2.4") spec.licenses = ["Ruby", "BSD-2-Clause"] spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage spec.metadata["changelog_uri"] = spec.homepage + "/releases" spec.files = ["README.md", "BSDL", "COPYING", "LEGAL", "lib/base64.rb", "sig/base64.rbs"] spec.bindir = "exe" spec.executables = [] spec.require_paths = ["lib"] end base64-0.3.0/bin/000077500000000000000000000000001501624734300133535ustar00rootroot00000000000000base64-0.3.0/bin/console000077500000000000000000000005251501624734300147450ustar00rootroot00000000000000#!/usr/bin/env ruby require "bundler/setup" require "base64" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start(__FILE__) base64-0.3.0/bin/setup000077500000000000000000000002031501624734300144340ustar00rootroot00000000000000#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here base64-0.3.0/lib/000077500000000000000000000000001501624734300133515ustar00rootroot00000000000000base64-0.3.0/lib/base64.rb000066400000000000000000000334461501624734300147740ustar00rootroot00000000000000# frozen_string_literal: true # # \Module \Base64 provides methods for: # # - \Encoding a binary string (containing non-ASCII characters) # as a string of printable ASCII characters. # - Decoding such an encoded string. # # \Base64 is commonly used in contexts where binary data # is not allowed or supported: # # - Images in HTML or CSS files, or in URLs. # - Email attachments. # # A \Base64-encoded string is about one-third larger that its source. # See the {Wikipedia article}[https://en.wikipedia.org/wiki/Base64] # for more information. # # This module provides three pairs of encode/decode methods. # Your choices among these methods should depend on: # # - Which character set is to be used for encoding and decoding. # - Whether "padding" is to be used. # - Whether encoded strings are to contain newlines. # # Note: Examples on this page assume that the including program has executed: # # require 'base64' # # == \Encoding Character Sets # # A \Base64-encoded string consists only of characters from a 64-character set: # # - ('A'..'Z'). # - ('a'..'z'). # - ('0'..'9'). # - =, the 'padding' character. # - Either: # - %w[+ /]: # {RFC-2045-compliant}[https://datatracker.ietf.org/doc/html/rfc2045]; # _not_ safe for URLs. # - %w[- _]: # {RFC-4648-compliant}[https://datatracker.ietf.org/doc/html/rfc4648]; # safe for URLs. # # If you are working with \Base64-encoded strings that will come from # or be put into URLs, you should choose this encoder-decoder pair # of RFC-4648-compliant methods: # # - Base64.urlsafe_encode64 and Base64.urlsafe_decode64. # # Otherwise, you may choose any of the pairs in this module, # including the pair above, or the RFC-2045-compliant pairs: # # - Base64.encode64 and Base64.decode64. # - Base64.strict_encode64 and Base64.strict_decode64. # # == Padding # # \Base64-encoding changes a triplet of input bytes # into a quartet of output characters. # # Padding in Encode Methods # # Padding -- extending an encoded string with zero, one, or two trailing # = characters -- is performed by methods Base64.encode64, # Base64.strict_encode64, and, by default, Base64.urlsafe_encode64: # # Base64.encode64('s') # => "cw==\n" # Base64.strict_encode64('s') # => "cw==" # Base64.urlsafe_encode64('s') # => "cw==" # Base64.urlsafe_encode64('s', padding: false) # => "cw" # # When padding is performed, the encoded string is always of length 4n, # where +n+ is a non-negative integer: # # - Input bytes of length 3n generate unpadded output characters # of length 4n: # # # n = 1: 3 bytes => 4 characters. # Base64.strict_encode64('123') # => "MDEy" # # n = 2: 6 bytes => 8 characters. # Base64.strict_encode64('123456') # => "MDEyMzQ1" # # - Input bytes of length 3n+1 generate padded output characters # of length 4(n+1), with two padding characters at the end: # # # n = 1: 4 bytes => 8 characters. # Base64.strict_encode64('1234') # => "MDEyMw==" # # n = 2: 7 bytes => 12 characters. # Base64.strict_encode64('1234567') # => "MDEyMzQ1Ng==" # # - Input bytes of length 3n+2 generate padded output characters # of length 4(n+1), with one padding character at the end: # # # n = 1: 5 bytes => 8 characters. # Base64.strict_encode64('12345') # => "MDEyMzQ=" # # n = 2: 8 bytes => 12 characters. # Base64.strict_encode64('12345678') # => "MDEyMzQ1Njc=" # # When padding is suppressed, for a positive integer n: # # - Input bytes of length 3n generate unpadded output characters # of length 4n: # # # n = 1: 3 bytes => 4 characters. # Base64.urlsafe_encode64('123', padding: false) # => "MDEy" # # n = 2: 6 bytes => 8 characters. # Base64.urlsafe_encode64('123456', padding: false) # => "MDEyMzQ1" # # - Input bytes of length 3n+1 generate unpadded output characters # of length 4n+2, with two padding characters at the end: # # # n = 1: 4 bytes => 6 characters. # Base64.urlsafe_encode64('1234', padding: false) # => "MDEyMw" # # n = 2: 7 bytes => 10 characters. # Base64.urlsafe_encode64('1234567', padding: false) # => "MDEyMzQ1Ng" # # - Input bytes of length 3n+2 generate unpadded output characters # of length 4n+3, with one padding character at the end: # # # n = 1: 5 bytes => 7 characters. # Base64.urlsafe_encode64('12345', padding: false) # => "MDEyMzQ" # # m = 2: 8 bytes => 11 characters. # Base64.urlsafe_encode64('12345678', padding: false) # => "MDEyMzQ1Njc" # # Padding in Decode Methods # # All of the \Base64 decode methods support (but do not require) padding. # # \Method Base64.decode64 does not check the size of the padding: # # Base64.decode64("MDEyMzQ1Njc") # => "01234567" # Base64.decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.decode64("MDEyMzQ1Njc==") # => "01234567" # # \Method Base64.strict_decode64 strictly enforces padding size: # # Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError # Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError # # \Method Base64.urlsafe_decode64 allows padding in the encoded string, # which if present, must be correct: # see {Padding}[Base64.html#module-Base64-label-Padding], above: # # Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567" # Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError. # # == Newlines # # An encoded string returned by Base64.encode64 or Base64.urlsafe_encode64 # has an embedded newline character # after each 60-character sequence, and, if non-empty, at the end: # # # No newline if empty. # encoded = Base64.encode64("\x00" * 0) # encoded.index("\n") # => nil # # # Newline at end of short output. # encoded = Base64.encode64("\x00" * 1) # encoded.size # => 4 # encoded.index("\n") # => 4 # # # Newline at end of longer output. # encoded = Base64.encode64("\x00" * 45) # encoded.size # => 60 # encoded.index("\n") # => 60 # # # Newlines embedded and at end of still longer output. # encoded = Base64.encode64("\x00" * 46) # encoded.size # => 65 # encoded.rindex("\n") # => 65 # encoded.split("\n").map {|s| s.size } # => [60, 4] # # The string to be encoded may itself contain newlines, # which are encoded as \Base64: # # # Base64.encode64("\n\n\n") # => "CgoK\n" # s = "This is line 1\nThis is line 2\n" # Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n" # module Base64 VERSION = "0.3.0" module_function # :call-seq: # Base64.encode64(string) -> encoded_string # # Returns a string containing the RFC-2045-compliant \Base64-encoding of +string+. # # Per RFC 2045, the returned string may contain the URL-unsafe characters # + or /; # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above: # # Base64.encode64("\xFB\xEF\xBE") # => "++++\n" # Base64.encode64("\xFF\xFF\xFF") # => "////\n" # # The returned string may include padding; # see {Padding}[Base64.html#module-Base64-label-Padding] above. # # Base64.encode64('*') # => "Kg==\n" # # The returned string ends with a newline character, and if sufficiently long # will have one or more embedded newline characters; # see {Newlines}[Base64.html#module-Base64-label-Newlines] above: # # Base64.encode64('*') # => "Kg==\n" # Base64.encode64('*' * 46) # # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq\nKg==\n" # # The string to be encoded may itself contain newlines, # which will be encoded as ordinary \Base64: # # Base64.encode64("\n\n\n") # => "CgoK\n" # s = "This is line 1\nThis is line 2\n" # Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n" # def encode64(bin) [bin].pack("m") end # :call-seq: # Base64.decode(encoded_string) -> decoded_string # # Returns a string containing the decoding of an RFC-2045-compliant # \Base64-encoded string +encoded_string+: # # s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n" # Base64.decode64(s) # => "This is line 1\nThis is line 2\n" # # Non-\Base64 characters in +encoded_string+ are ignored; # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above: # these include newline characters and characters - and /: # # Base64.decode64("\x00\n-_") # => "" # # Padding in +encoded_string+ (even if incorrect) is ignored: # # Base64.decode64("MDEyMzQ1Njc") # => "01234567" # Base64.decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.decode64("MDEyMzQ1Njc==") # => "01234567" # def decode64(str) str.unpack1("m") end # :call-seq: # Base64.strict_encode64(string) -> encoded_string # # Returns a string containing the RFC-2045-compliant \Base64-encoding of +string+. # # Per RFC 2045, the returned string may contain the URL-unsafe characters # + or /; # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above: # # Base64.strict_encode64("\xFB\xEF\xBE") # => "++++\n" # Base64.strict_encode64("\xFF\xFF\xFF") # => "////\n" # # The returned string may include padding; # see {Padding}[Base64.html#module-Base64-label-Padding] above. # # Base64.strict_encode64('*') # => "Kg==\n" # # The returned string will have no newline characters, regardless of its length; # see {Newlines}[Base64.html#module-Base64-label-Newlines] above: # # Base64.strict_encode64('*') # => "Kg==" # Base64.strict_encode64('*' * 46) # # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg==" # # The string to be encoded may itself contain newlines, # which will be encoded as ordinary \Base64: # # Base64.strict_encode64("\n\n\n") # => "CgoK" # s = "This is line 1\nThis is line 2\n" # Base64.strict_encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK" # def strict_encode64(bin) [bin].pack("m0") end # :call-seq: # Base64.strict_decode64(encoded_string) -> decoded_string # # Returns a string containing the decoding of an RFC-2045-compliant # \Base64-encoded string +encoded_string+: # # s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK" # Base64.strict_decode64(s) # => "This is line 1\nThis is line 2\n" # # Non-\Base64 characters in +encoded_string+ are not allowed; # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above: # these include newline characters and characters - and /: # # Base64.strict_decode64("\n") # Raises ArgumentError # Base64.strict_decode64('-') # Raises ArgumentError # Base64.strict_decode64('_') # Raises ArgumentError # # Padding in +encoded_string+, if present, must be correct: # # Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError # Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError # def strict_decode64(str) str.unpack1("m0") end # :call-seq: # Base64.urlsafe_encode64(string) -> encoded_string # # Returns the RFC-4648-compliant \Base64-encoding of +string+. # # Per RFC 4648, the returned string will not contain the URL-unsafe characters # + or /, # but instead may contain the URL-safe characters # - and _; # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above: # # Base64.urlsafe_encode64("\xFB\xEF\xBE") # => "----" # Base64.urlsafe_encode64("\xFF\xFF\xFF") # => "____" # # By default, the returned string may have padding; # see {Padding}[Base64.html#module-Base64-label-Padding], above: # # Base64.urlsafe_encode64('*') # => "Kg==" # # Optionally, you can suppress padding: # # Base64.urlsafe_encode64('*', padding: false) # => "Kg" # # The returned string will have no newline characters, regardless of its length; # see {Newlines}[Base64.html#module-Base64-label-Newlines] above: # # Base64.urlsafe_encode64('*') # => "Kg==" # Base64.urlsafe_encode64('*' * 46) # # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg==" # def urlsafe_encode64(bin, padding: true) str = strict_encode64(bin) str.chomp!("==") or str.chomp!("=") unless padding str.tr!("+/", "-_") str end # :call-seq: # Base64.urlsafe_decode64(encoded_string) -> decoded_string # # Returns the decoding of an RFC-4648-compliant \Base64-encoded string +encoded_string+: # # +encoded_string+ may not contain non-Base64 characters; # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above: # # Base64.urlsafe_decode64('+') # Raises ArgumentError. # Base64.urlsafe_decode64('/') # Raises ArgumentError. # Base64.urlsafe_decode64("\n") # Raises ArgumentError. # # Padding in +encoded_string+, if present, must be correct: # see {Padding}[Base64.html#module-Base64-label-Padding], above: # # Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567" # Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError. # 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 end base64-0.3.0/sig/000077500000000000000000000000001501624734300133655ustar00rootroot00000000000000base64-0.3.0/sig/base64.rbs000066400000000000000000000323521501624734300151660ustar00rootroot00000000000000# # Module Base64 provides methods for: # # * Encoding a binary string (containing non-ASCII characters) as a string of # printable ASCII characters. # * Decoding such an encoded string. # # Base64 is commonly used in contexts where binary data is not allowed or # supported: # # * Images in HTML or CSS files, or in URLs. # * Email attachments. # # A Base64-encoded string is about one-third larger that its source. See the # [Wikipedia article](https://en.wikipedia.org/wiki/Base64) for more # information. # # This module provides three pairs of encode/decode methods. Your choices among # these methods should depend on: # # * Which character set is to be used for encoding and decoding. # * Whether "padding" is to be used. # * Whether encoded strings are to contain newlines. # # Note: Examples on this page assume that the including program has executed: # # require 'base64' # # ## Encoding Character Sets # # A Base64-encoded string consists only of characters from a 64-character set: # # * `('A'..'Z')`. # * `('a'..'z')`. # * `('0'..'9')`. # * `=`, the 'padding' character. # * Either: # * `%w[+ /]`: # [RFC-2045-compliant](https://datatracker.ietf.org/doc/html/rfc2045); # *not* safe for URLs. # * `%w[- _]`: # [RFC-4648-compliant](https://datatracker.ietf.org/doc/html/rfc4648); # safe for URLs. # # If you are working with Base64-encoded strings that will come from or be put # into URLs, you should choose this encoder-decoder pair of RFC-4648-compliant # methods: # # * Base64.urlsafe_encode64 and Base64.urlsafe_decode64. # # Otherwise, you may choose any of the pairs in this module, including the pair # above, or the RFC-2045-compliant pairs: # # * Base64.encode64 and Base64.decode64. # * Base64.strict_encode64 and Base64.strict_decode64. # # ## Padding # # Base64-encoding changes a triplet of input bytes into a quartet of output # characters. # # **Padding in Encode Methods** # # Padding -- extending an encoded string with zero, one, or two trailing `=` # characters -- is performed by methods Base64.encode64, Base64.strict_encode64, # and, by default, Base64.urlsafe_encode64: # # Base64.encode64('s') # => "cw==\n" # Base64.strict_encode64('s') # => "cw==" # Base64.urlsafe_encode64('s') # => "cw==" # Base64.urlsafe_encode64('s', padding: false) # => "cw" # # When padding is performed, the encoded string is always of length *4n*, where # `n` is a non-negative integer: # # * Input bytes of length *3n* generate unpadded output characters of length # *4n*: # # # n = 1: 3 bytes => 4 characters. # Base64.strict_encode64('123') # => "MDEy" # # n = 2: 6 bytes => 8 characters. # Base64.strict_encode64('123456') # => "MDEyMzQ1" # # * Input bytes of length *3n+1* generate padded output characters of length # *4(n+1)*, with two padding characters at the end: # # # n = 1: 4 bytes => 8 characters. # Base64.strict_encode64('1234') # => "MDEyMw==" # # n = 2: 7 bytes => 12 characters. # Base64.strict_encode64('1234567') # => "MDEyMzQ1Ng==" # # * Input bytes of length *3n+2* generate padded output characters of length # *4(n+1)*, with one padding character at the end: # # # n = 1: 5 bytes => 8 characters. # Base64.strict_encode64('12345') # => "MDEyMzQ=" # # n = 2: 8 bytes => 12 characters. # Base64.strict_encode64('12345678') # => "MDEyMzQ1Njc=" # # When padding is suppressed, for a positive integer *n*: # # * Input bytes of length *3n* generate unpadded output characters of length # *4n*: # # # n = 1: 3 bytes => 4 characters. # Base64.urlsafe_encode64('123', padding: false) # => "MDEy" # # n = 2: 6 bytes => 8 characters. # Base64.urlsafe_encode64('123456', padding: false) # => "MDEyMzQ1" # # * Input bytes of length *3n+1* generate unpadded output characters of length # *4n+2*, with two padding characters at the end: # # # n = 1: 4 bytes => 6 characters. # Base64.urlsafe_encode64('1234', padding: false) # => "MDEyMw" # # n = 2: 7 bytes => 10 characters. # Base64.urlsafe_encode64('1234567', padding: false) # => "MDEyMzQ1Ng" # # * Input bytes of length *3n+2* generate unpadded output characters of length # *4n+3*, with one padding character at the end: # # # n = 1: 5 bytes => 7 characters. # Base64.urlsafe_encode64('12345', padding: false) # => "MDEyMzQ" # # m = 2: 8 bytes => 11 characters. # Base64.urlsafe_encode64('12345678', padding: false) # => "MDEyMzQ1Njc" # # **Padding in Decode Methods** # # All of the Base64 decode methods support (but do not require) padding. # # Method Base64.decode64 does not check the size of the padding: # # Base64.decode64("MDEyMzQ1Njc") # => "01234567" # Base64.decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.decode64("MDEyMzQ1Njc==") # => "01234567" # # Method Base64.strict_decode64 strictly enforces padding size: # # Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError # Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError # # Method Base64.urlsafe_decode64 allows padding in `str`, which if present, must # be correct: see [Padding](Base64.html#module-Base64-label-Padding), above: # # Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567" # Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError. # # ## Newlines # # An encoded string returned by Base64.encode64 or Base64.urlsafe_encode64 has # an embedded newline character after each 60-character sequence, and, if # non-empty, at the end: # # # No newline if empty. # encoded = Base64.encode64("\x00" * 0) # encoded.index("\n") # => nil # # # Newline at end of short output. # encoded = Base64.encode64("\x00" * 1) # encoded.size # => 4 # encoded.index("\n") # => 4 # # # Newline at end of longer output. # encoded = Base64.encode64("\x00" * 45) # encoded.size # => 60 # encoded.index("\n") # => 60 # # # Newlines embedded and at end of still longer output. # encoded = Base64.encode64("\x00" * 46) # encoded.size # => 65 # encoded.rindex("\n") # => 65 # encoded.split("\n").map {|s| s.size } # => [60, 4] # # The string to be encoded may itself contain newlines, which are encoded as # Base64: # # # Base64.encode64("\n\n\n") # => "CgoK\n" # s = "This is line 1\nThis is line 2\n" # Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n" # module Base64 # # Returns a string containing the decoding of an RFC-2045-compliant # Base64-encoded string `str`: # # s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n" # Base64.decode64(s) # => "This is line 1\nThis is line 2\n" # # Non-Base64 characters in `str` are ignored; see [Encoding Character # Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: these # include newline characters and characters `-` and `/`: # # Base64.decode64("\x00\n-_") # => "" # # Padding in `str` (even if incorrect) is ignored: # # Base64.decode64("MDEyMzQ1Njc") # => "01234567" # Base64.decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.decode64("MDEyMzQ1Njc==") # => "01234567" # def self?.decode64: (String str) -> String # # Returns a string containing the RFC-2045-compliant Base64-encoding of `bin`. # # Per RFC 2045, the returned string may contain the URL-unsafe characters `+` or # `/`; see [Encoding Character # Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: # # Base64.encode64("\xFB\xEF\xBE") # => "++++\n" # Base64.encode64("\xFF\xFF\xFF") # => "////\n" # # The returned string may include padding; see # [Padding](Base64.html#module-Base64-label-Padding) above. # # Base64.encode64('*') # => "Kg==\n" # # The returned string ends with a newline character, and if sufficiently long # will have one or more embedded newline characters; see # [Newlines](Base64.html#module-Base64-label-Newlines) above: # # Base64.encode64('*') # => "Kg==\n" # Base64.encode64('*' * 46) # # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq\nKg==\n" # # The string to be encoded may itself contain newlines, which will be encoded as # ordinary Base64: # # Base64.encode64("\n\n\n") # => "CgoK\n" # s = "This is line 1\nThis is line 2\n" # Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n" # def self?.encode64: (String bin) -> String # # Returns a string containing the decoding of an RFC-2045-compliant # Base64-encoded string `str`: # # s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK" # Base64.strict_decode64(s) # => "This is line 1\nThis is line 2\n" # # Non-Base64 characters in `str` not allowed; see [Encoding Character # Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: these # include newline characters and characters `-` and `/`: # # Base64.strict_decode64("\n") # Raises ArgumentError # Base64.strict_decode64('-') # Raises ArgumentError # Base64.strict_decode64('_') # Raises ArgumentError # # Padding in `str`, if present, must be correct: # # Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError # Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError # def self?.strict_decode64: (String str) -> String # # Returns a string containing the RFC-2045-compliant Base64-encoding of `bin`. # # Per RFC 2045, the returned string may contain the URL-unsafe characters `+` or # `/`; see [Encoding Character # Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: # # Base64.strict_encode64("\xFB\xEF\xBE") # => "++++\n" # Base64.strict_encode64("\xFF\xFF\xFF") # => "////\n" # # The returned string may include padding; see # [Padding](Base64.html#module-Base64-label-Padding) above. # # Base64.strict_encode64('*') # => "Kg==\n" # # The returned string will have no newline characters, regardless of its length; # see [Newlines](Base64.html#module-Base64-label-Newlines) above: # # Base64.strict_encode64('*') # => "Kg==" # Base64.strict_encode64('*' * 46) # # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg==" # # The string to be encoded may itself contain newlines, which will be encoded as # ordinary Base64: # # Base64.strict_encode64("\n\n\n") # => "CgoK" # s = "This is line 1\nThis is line 2\n" # Base64.strict_encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK" # def self?.strict_encode64: (String bin) -> String # # Returns the decoding of an RFC-4648-compliant Base64-encoded string `str`: # # `str` may not contain non-Base64 characters; see [Encoding Character # Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: # # Base64.urlsafe_decode64('+') # Raises ArgumentError. # Base64.urlsafe_decode64('/') # Raises ArgumentError. # Base64.urlsafe_decode64("\n") # Raises ArgumentError. # # Padding in `str`, if present, must be correct: see # [Padding](Base64.html#module-Base64-label-Padding), above: # # Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567" # Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567" # Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError. # def self?.urlsafe_decode64: (String str) -> String # # Returns the RFC-4648-compliant Base64-encoding of `bin`. # # Per RFC 4648, the returned string will not contain the URL-unsafe characters # `+` or `/`, but instead may contain the URL-safe characters `-` and `_`; see # [Encoding Character # Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: # # Base64.urlsafe_encode64("\xFB\xEF\xBE") # => "----" # Base64.urlsafe_encode64("\xFF\xFF\xFF") # => "____" # # By default, the returned string may have padding; see # [Padding](Base64.html#module-Base64-label-Padding), above: # # Base64.urlsafe_encode64('*') # => "Kg==" # # Optionally, you can suppress padding: # # Base64.urlsafe_encode64('*', padding: false) # => "Kg" # # The returned string will have no newline characters, regardless of its length; # see [Newlines](Base64.html#module-Base64-label-Newlines) above: # # Base64.urlsafe_encode64('*') # => "Kg==" # Base64.urlsafe_encode64('*' * 46) # # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg==" # def self?.urlsafe_encode64: (String bin, ?padding: boolish) -> String end base64-0.3.0/test/000077500000000000000000000000001501624734300135625ustar00rootroot00000000000000base64-0.3.0/test/base64/000077500000000000000000000000001501624734300146465ustar00rootroot00000000000000base64-0.3.0/test/base64/test_base64.rb000066400000000000000000000123671501624734300173270ustar00rootroot00000000000000# coding: US-ASCII # frozen_string_literal: true require "test/unit" require "base64" class TestBase64 < Test::Unit::TestCase def test_sample assert_equal("U2VuZCByZWluZm9yY2VtZW50cw==\n", Base64.encode64('Send reinforcements')) assert_equal('Send reinforcements', Base64.decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n")) assert_equal( "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n", Base64.encode64("Now is the time for all good coders\nto learn Ruby")) assert_equal( "Now is the time for all good coders\nto learn Ruby", Base64.decode64("Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n")) assert_equal( "VGhpcyBpcyBsaW5lIG9uZQpUaGlzIGlzIGxpbmUgdHdvClRoaXMgaXMgbGlu\nZSB0aHJlZQpBbmQgc28gb24uLi4K\n", Base64.encode64("This is line one\nThis is line two\nThis is line three\nAnd so on...\n")) assert_equal( "This is line one\nThis is line two\nThis is line three\nAnd so on...\n", Base64.decode64("VGhpcyBpcyBsaW5lIG9uZQpUaGlzIGlzIGxpbmUgdHdvClRoaXMgaXMgbGluZSB0aHJlZQpBbmQgc28gb24uLi4K")) end def test_encode64 assert_equal("", Base64.encode64("")) assert_equal("AA==\n", Base64.encode64("\0")) assert_equal("AAA=\n", Base64.encode64("\0\0")) assert_equal("AAAA\n", Base64.encode64("\0\0\0")) assert_equal("/w==\n", Base64.encode64("\377")) assert_equal("//8=\n", Base64.encode64("\377\377")) assert_equal("////\n", Base64.encode64("\377\377\377")) assert_equal("/+8=\n", Base64.encode64("\xff\xef")) end def test_decode64 assert_equal("", Base64.decode64("")) assert_equal("\0", Base64.decode64("AA==\n")) assert_equal("\0\0", Base64.decode64("AAA=\n")) assert_equal("\0\0\0", Base64.decode64("AAAA\n")) assert_equal("\377", Base64.decode64("/w==\n")) assert_equal("\377\377", Base64.decode64("//8=\n")) assert_equal("\377\377\377", Base64.decode64("////\n")) assert_equal("\xff\xef", Base64.decode64("/+8=\n")) end def test_strict_encode64 assert_equal("", Base64.strict_encode64("")) assert_equal("AA==", Base64.strict_encode64("\0")) assert_equal("AAA=", Base64.strict_encode64("\0\0")) assert_equal("AAAA", Base64.strict_encode64("\0\0\0")) assert_equal("/w==", Base64.strict_encode64("\377")) assert_equal("//8=", Base64.strict_encode64("\377\377")) assert_equal("////", Base64.strict_encode64("\377\377\377")) assert_equal("/+8=", Base64.strict_encode64("\xff\xef")) end def test_strict_decode64 assert_equal("", Base64.strict_decode64("")) assert_equal("\0", Base64.strict_decode64("AA==")) assert_equal("\0\0", Base64.strict_decode64("AAA=")) assert_equal("\0\0\0", Base64.strict_decode64("AAAA")) assert_equal("\377", Base64.strict_decode64("/w==")) assert_equal("\377\377", Base64.strict_decode64("//8=")) assert_equal("\377\377\377", Base64.strict_decode64("////")) assert_equal("\xff\xef", Base64.strict_decode64("/+8=")) assert_raise(ArgumentError) { Base64.strict_decode64("^") } assert_raise(ArgumentError) { Base64.strict_decode64("A") } assert_raise(ArgumentError) { Base64.strict_decode64("A^") } assert_raise(ArgumentError) { Base64.strict_decode64("AA") } assert_raise(ArgumentError) { Base64.strict_decode64("AA=") } assert_raise(ArgumentError) { Base64.strict_decode64("AA===") } assert_raise(ArgumentError) { Base64.strict_decode64("AA=x") } assert_raise(ArgumentError) { Base64.strict_decode64("AAA") } assert_raise(ArgumentError) { Base64.strict_decode64("AAA^") } assert_raise(ArgumentError) { Base64.strict_decode64("AB==") } assert_raise(ArgumentError) { Base64.strict_decode64("AAB=") } end def test_urlsafe_encode64 assert_equal("", Base64.urlsafe_encode64("")) assert_equal("AA==", Base64.urlsafe_encode64("\0")) assert_equal("AAA=", Base64.urlsafe_encode64("\0\0")) assert_equal("AAAA", Base64.urlsafe_encode64("\0\0\0")) assert_equal("_w==", Base64.urlsafe_encode64("\377")) assert_equal("__8=", Base64.urlsafe_encode64("\377\377")) assert_equal("____", Base64.urlsafe_encode64("\377\377\377")) assert_equal("_-8=", Base64.urlsafe_encode64("\xff\xef")) end def test_urlsafe_encode64_unpadded assert_equal("", Base64.urlsafe_encode64("", padding: false)) assert_equal("AA", Base64.urlsafe_encode64("\0", padding: false)) assert_equal("AAA", Base64.urlsafe_encode64("\0\0", padding: false)) assert_equal("AAAA", Base64.urlsafe_encode64("\0\0\0", padding: false)) end def test_urlsafe_decode64 assert_equal("", Base64.urlsafe_decode64("")) assert_equal("\0", Base64.urlsafe_decode64("AA==")) assert_equal("\0\0", Base64.urlsafe_decode64("AAA=")) assert_equal("\0\0\0", Base64.urlsafe_decode64("AAAA")) assert_equal("\377", Base64.urlsafe_decode64("_w==")) assert_equal("\377\377", Base64.urlsafe_decode64("__8=")) assert_equal("\377\377\377", Base64.urlsafe_decode64("____")) assert_equal("\xff\xef", Base64.urlsafe_decode64("_+8=")) end def test_urlsafe_decode64_unpadded assert_equal("\0", Base64.urlsafe_decode64("AA")) assert_equal("\0\0", Base64.urlsafe_decode64("AAA")) assert_equal("\0\0\0", Base64.urlsafe_decode64("AAAA")) assert_raise(ArgumentError) { Base64.urlsafe_decode64("AA=") } end end base64-0.3.0/test_sig/000077500000000000000000000000001501624734300144245ustar00rootroot00000000000000base64-0.3.0/test_sig/test_base64.rb000066400000000000000000000022371501624734300171000ustar00rootroot00000000000000# frozen_string_literal: true require 'base64' require 'test/unit' require 'rbs/unit_test' class Base64SingletonTest < Test::Unit::TestCase include RBS::UnitTest::TypeAssertions library 'base64' testing "singleton(::Base64)" def test_decode64 assert_send_type '(String) -> String', Base64, :decode64, 'aGVsbG8gd29ybGQ=' end def test_encode64 assert_send_type '(String) -> String', Base64, :encode64, 'hello world' end def test_strict_decode64 assert_send_type '(String) -> String', Base64, :strict_decode64, 'aGVsbG8gd29ybGQ=' end def test_strict_encode64 assert_send_type '(String) -> String', Base64, :strict_encode64, 'hello world' end def test_urlsafe_decode64 assert_send_type '(String) -> String', Base64, :urlsafe_decode64, 'aGVsbG8gd29ybGQ=' end def test_urlsafe_encode64 assert_send_type '(String) -> String', Base64, :urlsafe_encode64, 'hello world' assert_send_type '(String, padding: bool) -> String', Base64, :urlsafe_encode64, '*', padding: false end end