base64 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5a5ed97490e357afc22d3a6abd81a414b83f0ba0518ae6d70ce96e1fc27ceacc
4
+ data.tar.gz: 6f5e2d2f066a6ef3fd672023ad169676bb91462edc19a4091bdb04f33bc4e2de
5
+ SHA512:
6
+ metadata.gz: 472ef81375e3cfae4baf72a77f6253f219d044726ba2f108f93ad334a435912465dc231022760b7b05fdf76ef6da0dc8bdcd189f5d0c20c3f3386ad2b547a90a
7
+ data.tar.gz: 13b206da0ad209a9ba9aee927b7f3512551b1649c15e10562a51e17845cc1b8d924eb0e36b481e0f31e4f2c8a90956d7cffeb61c771484073f812285329c5a60
@@ -0,0 +1,24 @@
1
+ name: test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
+ strategy:
9
+ matrix:
10
+ ruby: [ 2.7, 2.6, 2.5, head ]
11
+ os: [ ubuntu-latest, macos-latest ]
12
+ runs-on: ${{ matrix.os }}
13
+ steps:
14
+ - uses: actions/checkout@master
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: Install dependencies
20
+ run: |
21
+ gem install bundler --no-document
22
+ bundle install
23
+ - name: Run test
24
+ run: rake test
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rake"
4
+ gem "minitest"
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
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.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,48 @@
1
+ # Base64
2
+
3
+ The Base64 module provides for the encoding (`#encode64`, `#strict_encode64`,
4
+ `#urlsafe_encode64`) and decoding (`#decode64`, `#strict_decode64`,
5
+ `#urlsafe_decode64`) of binary data using a Base64 representation.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'base64'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install base64
22
+
23
+ ## Usage
24
+
25
+ A simple encoding and decoding.
26
+
27
+ ```ruby
28
+ require "base64"
29
+
30
+ enc = Base64.encode64('Send reinforcements')
31
+ # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
32
+ plain = Base64.decode64(enc)
33
+ # -> "Send reinforcements"
34
+ ```
35
+
36
+ The purpose of using base64 to encode data is that it translates any
37
+ binary data into purely printable characters.
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/base64.
48
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/test_*.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "base64"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Yusuke Endoh"]
5
+ spec.email = ["mame@ruby-lang.org"]
6
+
7
+ spec.summary = %q{Support for encoding and decoding binary data using a Base64 representation.}
8
+ spec.description = %q{Support for encoding and decoding binary data using a Base64 representation.}
9
+ spec.homepage = "https://github.com/ruby/base64"
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
12
+
13
+ spec.metadata["homepage_uri"] = spec.homepage
14
+ spec.metadata["source_code_uri"] = spec.homepage
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "base64"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # = base64.rb: methods for base64-encoding and -decoding strings
4
+ #
5
+
6
+ # The Base64 module provides for the encoding (#encode64, #strict_encode64,
7
+ # #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
8
+ # #urlsafe_decode64) of binary data using a Base64 representation.
9
+ #
10
+ # == Example
11
+ #
12
+ # A simple encoding and decoding.
13
+ #
14
+ # require "base64"
15
+ #
16
+ # enc = Base64.encode64('Send reinforcements')
17
+ # # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
18
+ # plain = Base64.decode64(enc)
19
+ # # -> "Send reinforcements"
20
+ #
21
+ # The purpose of using base64 to encode data is that it translates any
22
+ # binary data into purely printable characters.
23
+
24
+ module Base64
25
+ module_function
26
+
27
+ # Returns the Base64-encoded version of +bin+.
28
+ # This method complies with RFC 2045.
29
+ # Line feeds are added to every 60 encoded characters.
30
+ #
31
+ # require 'base64'
32
+ # Base64.encode64("Now is the time for all good coders\nto learn Ruby")
33
+ #
34
+ # <i>Generates:</i>
35
+ #
36
+ # Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
37
+ # UnVieQ==
38
+ def encode64(bin)
39
+ [bin].pack("m")
40
+ end
41
+
42
+ # Returns the Base64-decoded version of +str+.
43
+ # This method complies with RFC 2045.
44
+ # Characters outside the base alphabet are ignored.
45
+ #
46
+ # require 'base64'
47
+ # str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
48
+ # 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
49
+ # 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
50
+ # puts Base64.decode64(str)
51
+ #
52
+ # <i>Generates:</i>
53
+ #
54
+ # This is line one
55
+ # This is line two
56
+ # This is line three
57
+ # And so on...
58
+ def decode64(str)
59
+ str.unpack1("m")
60
+ end
61
+
62
+ # Returns the Base64-encoded version of +bin+.
63
+ # This method complies with RFC 4648.
64
+ # No line feeds are added.
65
+ def strict_encode64(bin)
66
+ [bin].pack("m0")
67
+ end
68
+
69
+ # Returns the Base64-decoded version of +str+.
70
+ # This method complies with RFC 4648.
71
+ # ArgumentError is raised if +str+ is incorrectly padded or contains
72
+ # non-alphabet characters. Note that CR or LF are also rejected.
73
+ def strict_decode64(str)
74
+ str.unpack1("m0")
75
+ end
76
+
77
+ # Returns the Base64-encoded version of +bin+.
78
+ # This method complies with ``Base 64 Encoding with URL and Filename Safe
79
+ # Alphabet'' in RFC 4648.
80
+ # The alphabet uses '-' instead of '+' and '_' instead of '/'.
81
+ # Note that the result can still contain '='.
82
+ # You can remove the padding by setting +padding+ as false.
83
+ def urlsafe_encode64(bin, padding: true)
84
+ str = strict_encode64(bin)
85
+ str.tr!("+/", "-_")
86
+ str.delete!("=") unless padding
87
+ str
88
+ end
89
+
90
+ # Returns the Base64-decoded version of +str+.
91
+ # This method complies with ``Base 64 Encoding with URL and Filename Safe
92
+ # Alphabet'' in RFC 4648.
93
+ # The alphabet uses '-' instead of '+' and '_' instead of '/'.
94
+ #
95
+ # The padding character is optional.
96
+ # This method accepts both correctly-padded and unpadded input.
97
+ # Note that it still rejects incorrectly-padded input.
98
+ def urlsafe_decode64(str)
99
+ # NOTE: RFC 4648 does say nothing about unpadded input, but says that
100
+ # "the excess pad characters MAY also be ignored", so it is inferred that
101
+ # unpadded input is also acceptable.
102
+ str = str.tr("-_", "+/")
103
+ if !str.end_with?("=") && str.length % 4 != 0
104
+ str = str.ljust((str.length + 3) & ~3, "=")
105
+ end
106
+ strict_decode64(str)
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: base64
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Endoh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Support for encoding and decoding binary data using a Base64 representation.
14
+ email:
15
+ - mame@ruby-lang.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/test.yml"
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - base64.gemspec
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/base64.rb
30
+ homepage: https://github.com/ruby/base64
31
+ licenses:
32
+ - Ruby
33
+ - BSD-2-Clause
34
+ metadata:
35
+ homepage_uri: https://github.com/ruby/base64
36
+ source_code_uri: https://github.com/ruby/base64
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.2.0.rc.1
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Support for encoding and decoding binary data using a Base64 representation.
56
+ test_files: []