url-safe-base64-0.2.2/0000755000175600017570000000000012736010025013350 5ustar pravipraviurl-safe-base64-0.2.2/url_safe_base64.gemspec0000644000175600017570000000175512736010025017671 0ustar pravipravi# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'url_safe_base64/version' Gem::Specification.new do |spec| spec.name = "url_safe_base64" spec.version = UrlSafeBase64::VERSION spec.authors = ["Joe Noon"] spec.email = ["joenoon@gmail.com"] spec.description = %q{Converts strings to/from a slightly modified base64 that contains only url-safe characters} spec.summary = %q{Converts strings to/from a slightly modified base64 that contains only url-safe characters} spec.homepage = "http://github.com/joenoon/url_safe_base64" spec.license = "MIT" spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake" end url-safe-base64-0.2.2/README.md0000644000175600017570000000170712736010025014634 0ustar pravipravi# UrlSafeBase64 Copyright (c) 2008 Joe Noon, released under the MIT license Converts strings to/from a slightly modified base64 that contains only url-safe characters ## Installation Add this line to your application's Gemfile: gem 'url_safe_base64' And then execute: $ bundle Or install it yourself as: $ gem install url_safe_base64 ## Usage Normal Base64: ```ruby Base64.encode64 "Test string" #=> "VGVzdCBzdHJpbmc=\n" ``` ```ruby Base64.decode64 "VGVzdCBzdHJpbmc=\n" #=> "Test string" ``` With this gem: ```ruby UrlSafeBase64.encode64 "Test string" #=> "VGVzdCBzdHJpbmc" ``` ```ruby UrlSafeBase64.decode64 "VGVzdCBzdHJpbmc=\n" #=> "Test string" ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request url-safe-base64-0.2.2/test/0000755000175600017570000000000012736010025014327 5ustar pravipraviurl-safe-base64-0.2.2/test/url_safe_base64_test.rb0000644000175600017570000000311612736010025020660 0ustar pravipravirequire 'test/unit' require File.join(File.dirname(__FILE__),"..","lib","url_safe_base64.rb") class UrlSafeBase64Test < Test::Unit::TestCase TEST_STRING = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !@#$%^&*()-=_+/?.:;[]{}\|" TEST_STRING_ENCODED_BASE64 = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXogQUJDREVGR0hJSktMTU5PUFFS\nU1RVVldYWVogMTIzNDU2Nzg5MCAhQCMkJV4mKigpLT1fKy8/Ljo7W117fXw=\n" TEST_STRING_ENCODED_BASE64_URL = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXogQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVogMTIzNDU2Nzg5MCAhQCMkJV4mKigpLT1fKy8_Ljo7W117fXw" MOD_GROUPS = { "2" => [TEST_STRING+'AB', TEST_STRING+'ABCDE'], "3" => [TEST_STRING, TEST_STRING+'ABC'], "0" => [TEST_STRING+'A', TEST_STRING+'ABCD'] } def test_the_test result = Base64.encode64(TEST_STRING) assert_equal TEST_STRING_ENCODED_BASE64, result result = Base64.decode64(result) assert_equal TEST_STRING, result end def test_url_safe_base64_on_png result = UrlSafeBase64.encode64(TEST_STRING) assert_equal TEST_STRING_ENCODED_BASE64_URL, result result = UrlSafeBase64.decode64(result) assert_equal TEST_STRING, result end def test_mod_groups MOD_GROUPS.keys.each do |key| MOD_GROUPS[key].each do |str| result = UrlSafeBase64.encode64(str) result = UrlSafeBase64.decode64(result) assert_equal str, result end end end def test_for_correct_mod_values MOD_GROUPS.keys.each do |key| MOD_GROUPS[key].each do |str| assert_equal key.to_i, UrlSafeBase64.encode64(str).length.modulo(4) end end end end url-safe-base64-0.2.2/Gemfile0000644000175600017570000000012712736010025014643 0ustar pravipravisource 'https://rubygems.org' # Specify your gem's dependencies in x1.gemspec gemspec url-safe-base64-0.2.2/lib/0000755000175600017570000000000012736010025014116 5ustar pravipraviurl-safe-base64-0.2.2/lib/url_safe_base64.rb0000644000175600017570000000044512736010025017412 0ustar pravipravirequire 'base64' require "url_safe_base64/version" module UrlSafeBase64 extend self def encode64(str) Base64.encode64(str).gsub(/[\s=]+/, "").tr('+/','-_') end def decode64(str) str += '=' * (4 - str.length.modulo(4)) Base64.decode64(str.tr('-_','+/')) end end url-safe-base64-0.2.2/lib/url_safe_base64/0000755000175600017570000000000012736010025017062 5ustar pravipraviurl-safe-base64-0.2.2/lib/url_safe_base64/version.rb0000644000175600017570000000005512736010025021074 0ustar pravipravimodule UrlSafeBase64 VERSION = "0.2.2" end url-safe-base64-0.2.2/Rakefile0000644000175600017570000000033312736010025015014 0ustar pravipravirequire "bundler/gem_tasks" require 'rake/testtask' Rake::TestTask.new(:test) do |test| test.libs << 'test' test.warning = true test.verbose = true test.pattern = 'test/**/*_test.rb' end task :default => :test url-safe-base64-0.2.2/MIT-LICENSE0000644000175600017570000000205112736010025015002 0ustar pravipraviCopyright (c) 2008 Joe Noon 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. url-safe-base64-0.2.2/.gitignore0000644000175600017570000000023212736010025015335 0ustar pravipravi*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp