rubysl-base64 1.0.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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/base64.rb +1 -0
- data/lib/rubysl/base64.rb +2 -0
- data/lib/rubysl/base64/base64.rb +117 -0
- data/lib/rubysl/base64/version.rb +5 -0
- data/rubysl-base64.gemspec +22 -0
- data/spec/b64encode_spec.rb +34 -0
- data/spec/decode64_spec.rb +7 -0
- data/spec/decode_b_spec.rb +17 -0
- data/spec/encode64_spec.rb +12 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c49f921de785db060ecfe5f7024c961740de36b1
|
4
|
+
data.tar.gz: 38fcda91c7b456a80b9ce055d53c4c93801ab3e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97f4bd1eadcbed407724885f8f6d32fb74820c404b928d96c06a17ba02c4ef50d90f90217953e3656be534f9d8268650a0287e259e90be0422d4e44294b2da62
|
7
|
+
data.tar.gz: b9edcc08db8dfd6523e9b1c6d3d4b75959244d212e8e217c13cc03fad31ee88e9fce64f02d4851d38bd0383d9d3b29920ac76c0b455153787b4981134c80c987
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Brian Shirai
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the library nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
23
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
25
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rubysl::Base64
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubysl-base64'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubysl-base64
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/base64.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/base64"
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#
|
2
|
+
# = base64.rb: methods for base64-encoding and -decoding stings
|
3
|
+
#
|
4
|
+
# Author:: Yukihiro Matsumoto
|
5
|
+
# Documentation:: Dave Thomas and Gavin Sinclair
|
6
|
+
#
|
7
|
+
# Until Ruby 1.8.1, these methods were defined at the top-level. Now
|
8
|
+
# they are in the Base64 module but included in the top-level, where
|
9
|
+
# their usage is deprecated.
|
10
|
+
#
|
11
|
+
# See Base64 for documentation.
|
12
|
+
#
|
13
|
+
|
14
|
+
#require "kconv"
|
15
|
+
|
16
|
+
|
17
|
+
# The Base64 module provides for the encoding (#encode64) and decoding
|
18
|
+
# (#decode64) of binary data using a Base64 representation.
|
19
|
+
#
|
20
|
+
# The following particular features are also provided:
|
21
|
+
# - encode into lines of a given length (#b64encode)
|
22
|
+
# - decode the special format specified in RFC2047 for the
|
23
|
+
# representation of email headers (decode_b)
|
24
|
+
#
|
25
|
+
# == Example
|
26
|
+
#
|
27
|
+
# A simple encoding and decoding.
|
28
|
+
#
|
29
|
+
# require "base64"
|
30
|
+
#
|
31
|
+
# enc = Base64.encode64('Send reinforcements')
|
32
|
+
# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
|
33
|
+
# plain = Base64.decode64(enc)
|
34
|
+
# # -> "Send reinforcements"
|
35
|
+
#
|
36
|
+
# The purpose of using base64 to encode data is that it translates any
|
37
|
+
# binary data into purely printable characters. It is specified in
|
38
|
+
# RFC 2045 (http://www.faqs.org/rfcs/rfc2045.html).
|
39
|
+
|
40
|
+
module Base64
|
41
|
+
module_function
|
42
|
+
|
43
|
+
# Returns the Base64-decoded version of +str+.
|
44
|
+
#
|
45
|
+
# require 'base64'
|
46
|
+
# str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
|
47
|
+
# 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
|
48
|
+
# 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
|
49
|
+
# puts Base64.decode64(str)
|
50
|
+
#
|
51
|
+
# <i>Generates:</i>
|
52
|
+
#
|
53
|
+
# This is line one
|
54
|
+
# This is line two
|
55
|
+
# This is line three
|
56
|
+
# And so on...
|
57
|
+
|
58
|
+
def decode64(str)
|
59
|
+
str.unpack("m")[0]
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
# Decodes text formatted using a subset of RFC2047 (the one used for
|
64
|
+
# mime-encoding mail headers).
|
65
|
+
#
|
66
|
+
# Only supports an encoding type of 'b' (base 64), and only supports
|
67
|
+
# the character sets ISO-2022-JP and SHIFT_JIS (so the only two
|
68
|
+
# encoded word sequences recognized are <tt>=?ISO-2022-JP?B?...=</tt> and
|
69
|
+
# <tt>=?SHIFT_JIS?B?...=</tt>). Recognition of these sequences is case
|
70
|
+
# insensitive.
|
71
|
+
|
72
|
+
def decode_b(str)
|
73
|
+
str.gsub!(/=\?ISO-2022-JP\?B\?([!->@-~]+)\?=/i) {
|
74
|
+
decode64($1)
|
75
|
+
}
|
76
|
+
#str = Kconv::toeuc(str)
|
77
|
+
str.gsub!(/=\?SHIFT_JIS\?B\?([!->@-~]+)\?=/i) {
|
78
|
+
decode64($1)
|
79
|
+
}
|
80
|
+
#str = Kconv::toeuc(str)
|
81
|
+
str.gsub!(/\n/, ' ')
|
82
|
+
str.gsub!(/\0/, '')
|
83
|
+
str
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns the Base64-encoded version of +str+.
|
87
|
+
#
|
88
|
+
# require 'base64'
|
89
|
+
# Base64.b64encode("Now is the time for all good coders\nto learn Ruby")
|
90
|
+
#
|
91
|
+
# <i>Generates:</i>
|
92
|
+
#
|
93
|
+
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
|
94
|
+
# UnVieQ==
|
95
|
+
|
96
|
+
def encode64(bin)
|
97
|
+
[bin].pack("m")
|
98
|
+
end
|
99
|
+
|
100
|
+
# _Prints_ the Base64 encoded version of +bin+ (a +String+) in lines of
|
101
|
+
# +len+ (default 60) characters.
|
102
|
+
#
|
103
|
+
# require 'base64'
|
104
|
+
# data = "Now is the time for all good coders\nto learn Ruby"
|
105
|
+
# Base64.b64encode(data)
|
106
|
+
#
|
107
|
+
# <i>Generates:</i>
|
108
|
+
#
|
109
|
+
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
|
110
|
+
# UnVieQ==
|
111
|
+
|
112
|
+
def b64encode(bin, len = 60)
|
113
|
+
encode64(bin).scan(/.{1,#{len}}/) do
|
114
|
+
print $&, "\n"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/base64/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-base64"
|
6
|
+
spec.version = RubySL::Base64::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library base64.}
|
10
|
+
spec.summary = %q{Ruby standard library base64.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-base64"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
ruby_version_is "" ... "1.9" do
|
4
|
+
describe "Base64#b64encode" do
|
5
|
+
it "returns the Base64-encoded version of the given string with a newline at 60 characters" do
|
6
|
+
b64encoded_version = "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMgdG8gbGVhcm4g\nUnVieQ==\n"
|
7
|
+
lambda {
|
8
|
+
Base64.b64encode("Now is the time for all good coders to learn Ruby").should == b64encoded_version
|
9
|
+
}.should output
|
10
|
+
end
|
11
|
+
|
12
|
+
it "prints the Base64-encoded version of the given string with a newline after 60 characters" do
|
13
|
+
b64encoded_version ="Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMgdG8gbGVhcm4g\nUnVieQ==\n"
|
14
|
+
lambda {
|
15
|
+
Base64.b64encode("Now is the time for all good coders to learn Ruby")
|
16
|
+
}.should output(b64encoded_version)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Base64#b64encode with length" do
|
21
|
+
it "returns the Base64-encoded version of the given string with a newline at 60 characters" do
|
22
|
+
b64encoded_version = "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMgdG8gbGVhcm4g\nUnVieQ==\n"
|
23
|
+
lambda {
|
24
|
+
Base64.b64encode("Now is the time for all good coders to learn Ruby", 2).should == b64encoded_version
|
25
|
+
}.should output
|
26
|
+
end
|
27
|
+
|
28
|
+
it "prints the Base64-encoded version of the given stringwith a newline after length characters" do
|
29
|
+
lambda {
|
30
|
+
Base64.b64encode("hello", 2).should == "aGVsbG8=\n"
|
31
|
+
}.should output("aG\nVs\nbG\n8=\n")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
ruby_version_is "" ... "1.9" do
|
4
|
+
describe "Base64#decode_b" do
|
5
|
+
it "supports an encoding type of base64 and the charachter set SHIFT_JIS" do
|
6
|
+
Base64.decode_b("=?SHIFT_JIS?B?Zm9v?=").should == 'foo'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "supports an encoding type of base64 and the character set ISO-2022-JP" do
|
10
|
+
Base64.decode_b("=?ISO-2022-JP?B?Zm9v?=").should == 'foo'
|
11
|
+
end
|
12
|
+
|
13
|
+
# mSpec doesn't have pending specs yet
|
14
|
+
# Waiting on Kconv implementation
|
15
|
+
# it "decodes MIME encoded string and convert halfwidth katakana to fullwidth katakana."
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
describe "Base64#encode64" do
|
4
|
+
it "returns the Base64-encoded version of the given string" do
|
5
|
+
Base64.encode64("Now is the time for all good coders\nto learn Ruby").should ==
|
6
|
+
"Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the Base64-encoded version of the given string" do
|
10
|
+
Base64.encode64('Send reinforcements').should == "U2VuZCByZWluZm9yY2VtZW50cw==\n"
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubysl-base64
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Shirai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
description: Ruby standard library base64.
|
56
|
+
email:
|
57
|
+
- brixen@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/base64.rb
|
69
|
+
- lib/rubysl/base64.rb
|
70
|
+
- lib/rubysl/base64/base64.rb
|
71
|
+
- lib/rubysl/base64/version.rb
|
72
|
+
- rubysl-base64.gemspec
|
73
|
+
- spec/b64encode_spec.rb
|
74
|
+
- spec/decode64_spec.rb
|
75
|
+
- spec/decode_b_spec.rb
|
76
|
+
- spec/encode64_spec.rb
|
77
|
+
homepage: https://github.com/rubysl/rubysl-base64
|
78
|
+
licenses:
|
79
|
+
- BSD
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.7
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Ruby standard library base64.
|
101
|
+
test_files:
|
102
|
+
- spec/b64encode_spec.rb
|
103
|
+
- spec/decode64_spec.rb
|
104
|
+
- spec/decode_b_spec.rb
|
105
|
+
- spec/encode64_spec.rb
|