refcode 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e758644ad3263ebb08c54c505b606c310ba5a88a
4
+ data.tar.gz: 5eef6a2ba89fa9dc55922ee1ea6fe54488155c72
5
+ SHA512:
6
+ metadata.gz: aa418e724d2bc68c26e7fb06ce6758d8ab2aa04d96aa5b3aaadaf5981750ab8e428706016d15d0c543ddd0f88b38807f8f91ab2fcd209839ee60263c853b36c5
7
+ data.tar.gz: d098a3bd746a7f4afe3fb4db4240c7ec645b795f8e99e7296d91bd8677bd013203536cb79437a35e6a843947882727caa35c4be16f8b44a469e7c49197915d00
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in refcode.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jordan Sitkin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Refcode
2
+
3
+ Currently a standalone gem for converting arbitrary Ruby objects into encrypted,
4
+ URL-safe strings. The strings can be simply decrypted later to be used by your
5
+ application.
6
+
7
+ Refcode was conceived as a way to attach referral data to tracking links. Encryption
8
+ makes it unlikely that the links can be tampered with.
9
+
10
+ ## Implementation
11
+
12
+ - **Encryption** using the AES-256-CBC algorithm with https://github.com/attr-encrypted/encryptor which wraps the Ruby OpenSSL library.
13
+
14
+ - **Base64 encoding** is handled by https://github.com/nojima/base64url which implements a slight tweak to the standard Base64 algorithm to create URL-safe strings.
15
+
16
+ - **Serialization** with YAML.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'refcode'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install refcode
31
+
32
+ ## Usage
33
+
34
+ encoder = Refcode::Encoder.new do |e|
35
+ e.secret = "a long crunchy secret"
36
+ e.salt = "some salt"
37
+ end
38
+
39
+ something = OpenStruct.new(channel: 'facebook', action: 'message', user_id: 43765)
40
+ encoded_param = encoder.encode something
41
+
42
+ # in some future request...
43
+
44
+ something = encoder.decode params[:encoded_param]
45
+ puts something.channel # 'facebook'
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'test'
5
+ test.warning = true
6
+ test.verbose = true
7
+ test.pattern = 'test/**/*_test.rb'
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module Refcode
2
+ VERSION = "0.0.1"
3
+ end
data/lib/refcode.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'uri'
2
+ require 'yaml'
3
+ require 'base64url'
4
+ require 'encryptor'
5
+ require 'refcode/version'
6
+
7
+ module Refcode
8
+
9
+ class Encoder
10
+
11
+ attr_accessor :secret, :salt
12
+
13
+ def initialize
14
+ yield self if block_given?
15
+ end
16
+
17
+ def encode val
18
+ Base64URL.encode(encrypt(YAML.dump(val)))
19
+ end
20
+
21
+ def decode val
22
+ YAML.load(decrypt(Base64URL.decode(val)))
23
+ end
24
+
25
+ def encrypt val
26
+ Encryptor.encrypt(:value => val, :key => @secret, :salt => @salt, :iv => iv)
27
+ end
28
+
29
+ def decrypt val
30
+ Encryptor.decrypt(:value => val, :key => @secret, :salt => @salt, :iv => iv)
31
+ end
32
+
33
+ private
34
+
35
+ def iv
36
+ [@secret, @salt].join
37
+ end
38
+
39
+ end
40
+
41
+ end
data/refcode.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'refcode/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "refcode"
8
+ spec.version = Refcode::VERSION
9
+ spec.authors = ["Jordan Sitkin"]
10
+ spec.email = ["jordan@fiftyfootfoghorn.com"]
11
+ spec.description = %q{Encrypts and encodes values into URL friendly strings}
12
+ spec.summary = %q{Hide sensitive data in plain sight, right in your URL}
13
+ spec.homepage = "http://github.com/dustMason/refcode"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "base64url", "~> 1.0"
22
+ spec.add_runtime_dependency "encryptor", "~> 1.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,42 @@
1
+ require 'ostruct'
2
+ require 'test/unit'
3
+ require File.join(File.dirname(__FILE__),"..","lib","refcode.rb")
4
+
5
+ class RefcodeTest < Test::Unit::TestCase
6
+
7
+ SECRET = "686cb0461769ebed556f56bc88c956bfdf786646ab1920f58201723c557ccbaeb57112fd53302c06475e6e19a176ba617ee284b091d375858cb259e8578c620f"
8
+ SALT = "dcc74de5efdab0d80b5d763f8a63bef3d37c7453ee45446fbbccd26648af8ca6a112576dafbf5475f3cd7b968703cc9e0682ee45b8b622045cec287908f536e8"
9
+
10
+ def test_encoder_against_hash
11
+ test_hash = { :channel => 'email', :record_id => 49203, :action => 'forward' }
12
+ assert_equal test_hash, encode_and_decode(test_hash)
13
+ end
14
+
15
+ def test_encoder_against_string
16
+ test_string = "secret referral data"
17
+ assert_equal test_string, encode_and_decode(test_string)
18
+ end
19
+
20
+ def test_encoder_against_int
21
+ assert_equal 4857, encode_and_decode(4857)
22
+ end
23
+
24
+ def test_encoder_against_open_struct
25
+ test_struct = OpenStruct.new({:test => 42})
26
+ assert_equal test_struct, encode_and_decode(test_struct)
27
+ end
28
+
29
+ private
30
+
31
+ def encoder
32
+ @encoder ||= Refcode::Encoder.new do |e|
33
+ e.secret = SECRET
34
+ e.salt = SALT
35
+ end
36
+ end
37
+
38
+ def encode_and_decode val
39
+ encoder.decode(encoder.encode(val))
40
+ end
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refcode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Sitkin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: base64url
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: encryptor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Encrypts and encodes values into URL friendly strings
70
+ email:
71
+ - jordan@fiftyfootfoghorn.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/refcode.rb
82
+ - lib/refcode/version.rb
83
+ - refcode.gemspec
84
+ - test/refcode_test.rb
85
+ homepage: http://github.com/dustMason/refcode
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.0.5
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Hide sensitive data in plain sight, right in your URL
109
+ test_files:
110
+ - test/refcode_test.rb