url_safe_base64 0.2.1
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.
- data/.gitignore +1 -0
- data/MIT-LICENSE +20 -0
- data/README +36 -0
- data/Rakefile +36 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/string_ext.rb +11 -0
- data/lib/url_safe_base64.rb +18 -0
- data/rails/init.rb +5 -0
- data/test/test_png.png +0 -0
- data/test/url_safe_base64_test.rb +48 -0
- data/url_safe_base64.gemspec +51 -0
- metadata +78 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Joe Noon
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
UrlSafeBase64
|
2
|
+
=============
|
3
|
+
|
4
|
+
Converts strings to/from a slightly modified base64 that contains only url-safe characters
|
5
|
+
|
6
|
+
Examples
|
7
|
+
========
|
8
|
+
|
9
|
+
Normal:
|
10
|
+
|
11
|
+
>> "Test string".url_safe_encode64
|
12
|
+
=> "VGVzdCBzdHJpbmc"
|
13
|
+
|
14
|
+
>> Base64.encode64 "Test string"
|
15
|
+
=> "VGVzdCBzdHJpbmc=\n"
|
16
|
+
|
17
|
+
>> Base64.decode64 "VGVzdCBzdHJpbmc=\n"
|
18
|
+
=> "Test string"
|
19
|
+
|
20
|
+
With this gem:
|
21
|
+
|
22
|
+
>> UrlSafeBase64.encode64 "Test string"
|
23
|
+
=> "VGVzdCBzdHJpbmc"
|
24
|
+
|
25
|
+
>> UrlSafeBase64.decode64 "VGVzdCBzdHJpbmc=\n"
|
26
|
+
=> "Test string"
|
27
|
+
|
28
|
+
Or:
|
29
|
+
|
30
|
+
>> "Test string".url_safe_encode64
|
31
|
+
=> "VGVzdCBzdHJpbmc"
|
32
|
+
|
33
|
+
>> "VGVzdCBzdHJpbmc".url_safe_decode64
|
34
|
+
=> "Test string"
|
35
|
+
|
36
|
+
Copyright (c) 2008 Joe Noon, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the url_safe_base64 plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the url_safe_base64 plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'UrlSafeBase64'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'jeweler'
|
26
|
+
Jeweler::Tasks.new do |gemspec|
|
27
|
+
gemspec.name = "url_safe_base64"
|
28
|
+
gemspec.summary = "Converts strings to/from a slightly modified base64 that contains only url-safe characters"
|
29
|
+
gemspec.description = "Converts strings to/from a slightly modified base64 that contains only url-safe characters"
|
30
|
+
gemspec.email = "joenoon@gmail.com"
|
31
|
+
gemspec.homepage = "http://github.com/joenoon/url_safe_base64"
|
32
|
+
gemspec.authors = ["Joe Noon"]
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
36
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
data/lib/string_ext.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'base64'
|
2
|
+
module UrlSafeBase64
|
3
|
+
|
4
|
+
def self.encode64(str)
|
5
|
+
Base64.encode64(str).gsub(/[\s=]+/, "").gsub("+", "-").gsub("/", "_")
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.decode64(str)
|
9
|
+
case str.length.modulo(4)
|
10
|
+
when 2
|
11
|
+
str += '=='
|
12
|
+
when 3
|
13
|
+
str += '='
|
14
|
+
end
|
15
|
+
Base64.decode64(str.gsub("-", "+").gsub("_", "/"))
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/rails/init.rb
ADDED
data/test/test_png.png
ADDED
Binary file
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__),"..","lib","url_safe_base64.rb")
|
3
|
+
|
4
|
+
class UrlSafeBase64Test < Test::Unit::TestCase
|
5
|
+
|
6
|
+
TEST_FILE = File.read(File.join(File.dirname(__FILE__),"test_png.png"))
|
7
|
+
TEST_NORM_ENCODE64 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAGXRFWHRTb2Z0\nd2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAjpJREFUeNpMUs9LG1EQnmw2\n260lalIqadIVqSHQNpKAGL2JBoTSBkIPuXnqyUvAP0JPgvVQ8JZa6NFADoGI\n6UHwaEBUSE2kJErp2nSbXek2+yN56+RtNnQYlvdmvm/fzDfjsiwL/rPf9Xq1\nWPxVreL58fR0eHk5NDs7zLrQLGp4ka6uCtlsrVRiMEHTGCUAzxKJd7u7wXh8\nwCEEg/D96OhzOq0rCgfAAjAOugdgYprjMnt7sUym/wISWpeXHxcWTEXhATSe\nV3l+VNfHOx0kdAEM6oTj3pdKzxcX+4RcKlUrFh8CNAIBEotNhsNis8mcnLwS\nRZO+oAN0AJ5Eo9lKhRXPz79RtOz1epeWVtfXPR4PdvVlZ+dnoRCUZbsZrE28\nuKgdHDD1w0OGFi36fIlkEtOGYUiS9GJ+vunzsU5LbuoIZuWbm8GdEFPTTBN7\nUVRVlSWJJcTloO2fytfXbFfXbb2EdvtrPv/I7we3+0+rVSmXI+22Xc9wUl3T\nZMdCIVs+v6r+PTv7tLHhm5hQWq3I7e3Tu7suTRHHR4NB14/T0w/xOAqK/oBW\n/I/KylhWj8pqUllRJQ1gdX+fCczMTOIQnAR+eU3rWZZB1RwGkTkmCJGVFewE\n3m5vWxynU4SN0x30MILnN1tbbo7rE4S5uUwuh7PU6Lv2mDpOGRrlvN7cjKbT\ng9Ww969xfJxfW8M9dTvLZ4sxLghYwstUymXbkIBGej3c1nq53G40TMPwT01N\nJ5NYNzcygkh7ve8FGACA/yuDGxf1iwAAAABJRU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ABCD']
|
14
|
+
}
|
15
|
+
|
16
|
+
def test_the_test
|
17
|
+
result = Base64.encode64(TEST_FILE)
|
18
|
+
assert_equal TEST_NORM_ENCODE64, result
|
19
|
+
result = Base64.decode64(result)
|
20
|
+
assert_equal TEST_FILE, result
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_url_safe_base64_on_png
|
24
|
+
result = UrlSafeBase64.encode64(TEST_FILE)
|
25
|
+
assert_equal TEST_SAFE_EXPECTED, result
|
26
|
+
result = UrlSafeBase64.decode64(result)
|
27
|
+
assert_equal TEST_FILE, result
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_mod_groups
|
31
|
+
MOD_GROUPS.keys.each do |key|
|
32
|
+
MOD_GROUPS[key].each do |str|
|
33
|
+
result = UrlSafeBase64.encode64(str)
|
34
|
+
result = UrlSafeBase64.decode64(result)
|
35
|
+
assert_equal str, result
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_for_correct_mod_values
|
41
|
+
MOD_GROUPS.keys.each do |key|
|
42
|
+
MOD_GROUPS[key].each do |str|
|
43
|
+
assert_equal key.to_i, UrlSafeBase64.encode64(str).length.modulo(4)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{url_safe_base64}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Joe Noon"]
|
12
|
+
s.date = %q{2010-07-22}
|
13
|
+
s.description = %q{Converts strings to/from a slightly modified base64 that contains only url-safe characters}
|
14
|
+
s.email = %q{joenoon@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"init.rb",
|
25
|
+
"lib/string_ext.rb",
|
26
|
+
"lib/url_safe_base64.rb",
|
27
|
+
"rails/init.rb",
|
28
|
+
"test/test_png.png",
|
29
|
+
"test/url_safe_base64_test.rb",
|
30
|
+
"url_safe_base64.gemspec"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/joenoon/url_safe_base64}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{Converts strings to/from a slightly modified base64 that contains only url-safe characters}
|
37
|
+
s.test_files = [
|
38
|
+
"test/url_safe_base64_test.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: url_safe_base64
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joe Noon
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-22 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Converts strings to/from a slightly modified base64 that contains only url-safe characters
|
23
|
+
email: joenoon@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- MIT-LICENSE
|
33
|
+
- README
|
34
|
+
- Rakefile
|
35
|
+
- VERSION
|
36
|
+
- init.rb
|
37
|
+
- lib/string_ext.rb
|
38
|
+
- lib/url_safe_base64.rb
|
39
|
+
- rails/init.rb
|
40
|
+
- test/test_png.png
|
41
|
+
- test/url_safe_base64_test.rb
|
42
|
+
- url_safe_base64.gemspec
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/joenoon/url_safe_base64
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Converts strings to/from a slightly modified base64 that contains only url-safe characters
|
77
|
+
test_files:
|
78
|
+
- test/url_safe_base64_test.rb
|