recaptcha-mailhide 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +34 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/recaptcha-mailhide.rb +1 -0
- data/lib/recaptcha_mailhide.rb +13 -0
- data/lib/recaptcha_mailhide/configuration.rb +5 -0
- data/lib/recaptcha_mailhide/encrypt.rb +38 -0
- data/lib/recaptcha_mailhide/url.rb +11 -0
- data/recaptcha-mailhide.gemspec +62 -0
- data/spec/recaptcha_mailhide/encrypt_spec.rb +13 -0
- data/spec/recaptcha_mailhide/url_spec.rb +13 -0
- data/spec/spec_helper.rb +16 -0
- metadata +100 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.9.2.2)
|
11
|
+
rspec (2.3.0)
|
12
|
+
rspec-core (~> 2.3.0)
|
13
|
+
rspec-expectations (~> 2.3.0)
|
14
|
+
rspec-mocks (~> 2.3.0)
|
15
|
+
rspec-core (2.3.1)
|
16
|
+
rspec-expectations (2.3.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.3.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler (~> 1.0.0)
|
25
|
+
jeweler (~> 1.6.4)
|
26
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Pedro Fayolle
|
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.rdoc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
= recaptcha-mailhide
|
2
|
+
|
3
|
+
This gem provides support for ReCAPTCHA's Mailhide API.
|
4
|
+
|
5
|
+
At the moment it only generates URLs, it doesn't provide any link helpers, so it's completely framework agnostic.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Simply run:
|
10
|
+
|
11
|
+
gem install recaptcha-mailhide
|
12
|
+
|
13
|
+
Or if you're using bundler:
|
14
|
+
|
15
|
+
gem 'recaptcha-mailhide'
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
== Contributing to recaptcha-mailhide
|
22
|
+
|
23
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
24
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
25
|
+
* Fork the project
|
26
|
+
* Start a feature/bugfix branch
|
27
|
+
* Commit and push until you are happy with your contribution
|
28
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
29
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
30
|
+
|
31
|
+
== Copyright
|
32
|
+
|
33
|
+
Copyright (c) 2012 Pedro Fayolle. See LICENSE.txt for
|
34
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "recaptcha-mailhide"
|
18
|
+
gem.homepage = "http://github.com/pilaf/recaptcha-mailhide"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{ReCAPTCHA Mailhide for Ruby}
|
21
|
+
gem.description = %Q{Ruby implementation of ReCAPTCHA Mailhide's API}
|
22
|
+
gem.email = "pfayolle@gmail.com"
|
23
|
+
gem.authors = ["Pedro Fayolle"]
|
24
|
+
gem.files.include Dir.glob("lib/**/*.rb")
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "recaptcha-mailhide #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'recaptcha_mailhide'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'recaptcha_mailhide/configuration'
|
2
|
+
require 'recaptcha_mailhide/encrypt'
|
3
|
+
require 'recaptcha_mailhide/url'
|
4
|
+
|
5
|
+
module RecaptchaMailhide
|
6
|
+
def self.configuration
|
7
|
+
@configuration ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module RecaptchaMailhide
|
5
|
+
module Encrypt
|
6
|
+
BLOCK_SIZE = 16
|
7
|
+
INITIALIZATION_VECTOR = 0.chr * 16
|
8
|
+
|
9
|
+
def self.encrypt(string)
|
10
|
+
aes = build_aes
|
11
|
+
encrypted = aes.update(pad_string(string)) + aes.final
|
12
|
+
urlsafe_base64(encrypted)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.urlsafe_base64(string)
|
18
|
+
Base64.encode64(string).tr('+/', '-_').chomp
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.pad_string(string)
|
22
|
+
padding = BLOCK_SIZE - (string.length % BLOCK_SIZE)
|
23
|
+
string + padding.chr * padding
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.build_aes
|
27
|
+
aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
28
|
+
aes.encrypt
|
29
|
+
aes.iv = INITIALIZATION_VECTOR
|
30
|
+
aes.padding = 0
|
31
|
+
|
32
|
+
# Convert the private key from hex to binary
|
33
|
+
aes.key = RecaptchaMailhide.configuration.private_key.unpack('a2' * 16).map {|x| x.hex }.pack('c' * 16)
|
34
|
+
|
35
|
+
aes
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RecaptchaMailhide
|
2
|
+
module URL
|
3
|
+
BASE_URL = "http://www.google.com/recaptcha/mailhide/d"
|
4
|
+
|
5
|
+
def self.url_for(email)
|
6
|
+
public_key = RecaptchaMailhide.configuration.public_key
|
7
|
+
encrypted_email = RecaptchaMailhide::Encrypt.encrypt(email)
|
8
|
+
BASE_URL + "?k=#{public_key}&c=#{encrypted_email}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "recaptcha-mailhide"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Pedro Fayolle"]
|
12
|
+
s.date = "2012-04-17"
|
13
|
+
s.description = "Ruby implementation of ReCAPTCHA Mailhide's API"
|
14
|
+
s.email = "pfayolle@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/recaptcha-mailhide.rb",
|
29
|
+
"lib/recaptcha_mailhide.rb",
|
30
|
+
"lib/recaptcha_mailhide/configuration.rb",
|
31
|
+
"lib/recaptcha_mailhide/encrypt.rb",
|
32
|
+
"lib/recaptcha_mailhide/url.rb",
|
33
|
+
"recaptcha-mailhide.gemspec",
|
34
|
+
"spec/recaptcha_mailhide/encrypt_spec.rb",
|
35
|
+
"spec/recaptcha_mailhide/url_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/pilaf/recaptcha-mailhide"
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = "1.8.10"
|
42
|
+
s.summary = "ReCAPTCHA Mailhide for Ruby"
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RecaptchaMailhide::Encrypt do
|
4
|
+
describe ".encrypt" do
|
5
|
+
it("properly encrypts x@example.com") do
|
6
|
+
RecaptchaMailhide::Encrypt.encrypt("x@example.com").should eq("wBG7nOgntKqWeDpF9ucVNQ==")
|
7
|
+
end
|
8
|
+
|
9
|
+
it("properly encrypts johndoe@example.com") do
|
10
|
+
RecaptchaMailhide::Encrypt.encrypt("johndoe@example.com").should eq("whWIqk0r4urZ-3S7y7uSceC9_ECd3hpAGy71E2o0HpI=")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RecaptchaMailhide::URL do
|
4
|
+
before do
|
5
|
+
RecaptchaMailhide::Encrypt.stub(:encrypt).and_return("ABC")
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".url_for" do
|
9
|
+
it("returns the proper URL") do
|
10
|
+
RecaptchaMailhide::URL.url_for('foo@bar.com').should eq('http://www.google.com/recaptcha/mailhide/d?k=PUBLIC_KEY&c=ABC')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'recaptcha_mailhide'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
end
|
12
|
+
|
13
|
+
RecaptchaMailhide.configure do |config|
|
14
|
+
config.private_key = "deadbeefdeadbeefdeadbeefdeadbeef"
|
15
|
+
config.public_key = "PUBLIC_KEY"
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: recaptcha-mailhide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pedro Fayolle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &17919800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *17919800
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &17916260 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *17916260
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
|
+
requirement: &17914600 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.6.4
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *17914600
|
47
|
+
description: Ruby implementation of ReCAPTCHA Mailhide's API
|
48
|
+
email: pfayolle@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .rspec
|
57
|
+
- Gemfile
|
58
|
+
- Gemfile.lock
|
59
|
+
- LICENSE.txt
|
60
|
+
- README.rdoc
|
61
|
+
- Rakefile
|
62
|
+
- VERSION
|
63
|
+
- lib/recaptcha-mailhide.rb
|
64
|
+
- lib/recaptcha_mailhide.rb
|
65
|
+
- lib/recaptcha_mailhide/configuration.rb
|
66
|
+
- lib/recaptcha_mailhide/encrypt.rb
|
67
|
+
- lib/recaptcha_mailhide/url.rb
|
68
|
+
- recaptcha-mailhide.gemspec
|
69
|
+
- spec/recaptcha_mailhide/encrypt_spec.rb
|
70
|
+
- spec/recaptcha_mailhide/url_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: http://github.com/pilaf/recaptcha-mailhide
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: 4467663709844804569
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.8.10
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: ReCAPTCHA Mailhide for Ruby
|
100
|
+
test_files: []
|