dm-encrypted 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ *~
3
+ .DS_Store
4
+ coverage
5
+ rdoc
6
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Quin Hoxie
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.md ADDED
@@ -0,0 +1,45 @@
1
+ dm-encrypted
2
+ ======
3
+ A [DataMapper](http://github.com/datamapper/data_mapper)
4
+ [type](http://github.com/datamapper/dm-more/tree/master/dm-types) that supports
5
+ RSA encrypted columns.
6
+
7
+ Installation
8
+ ------------
9
+ gem install qhoxie-rcrypt qhoxie-dm-encrypted --source http://gems.github.com
10
+
11
+ Usage
12
+ -----
13
+ Private and public key constants need to be set:
14
+
15
+ PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\nMIIEpgI..."
16
+ PUBLIC_KEY = "-----BEGIN RSA PUBLIC KEY-----\nXLPBCgK..."
17
+
18
+ In your models, you simply specify the column type as Encrypted:
19
+
20
+ class Account
21
+ include DataMapper::Resource
22
+
23
+ property :id, Serial
24
+ property :username, String
25
+ property :password, Encrypted
26
+ end
27
+
28
+ Saving and loading those fields will transparently work with plaintext:
29
+
30
+ >> Account.create :username => "me", :password => "secret"
31
+ >> Account.first.password
32
+ => "secret"
33
+
34
+ However it is ciphertext in the database:
35
+
36
+ >> select password from accounts;
37
+ => qxZjz37mt2PU...tcHPf5Un3RGAyxaT==
38
+
39
+ Comments/Suggestions/Requests
40
+ ----------------------------
41
+ Email me: qhoxie on gmail.com
42
+
43
+ Copyright
44
+ ---------
45
+ Copyright (c) 2009 Quin Hoxie. See LICENSE for details.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = dm-encrypted
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Quin Hoxie. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "dm-encrypted"
8
+ gem.summary = %Q{Encrypted column type for DataMapper.}
9
+ gem.description = %Q{Transparently add RSA encryption to DataMapper models.}
10
+ gem.email = "qhoxie@gmail.com"
11
+ gem.homepage = "http://github.com/qhoxie/dm-encrypted"
12
+ gem.authors = ["Quin Hoxie"]
13
+ gem.add_dependency "rcrypt"
14
+ gem.add_development_dependency "thoughtbot-shoulda"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/*_test.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION')
49
+ version = File.read('VERSION')
50
+ else
51
+ version = ""
52
+ end
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "dm-encrypted #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
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 = %q{dm-encrypted}
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 = ["Quin Hoxie"]
12
+ s.date = %q{2009-10-13}
13
+ s.description = %q{Transparently add RSA encryption to DataMapper models.}
14
+ s.email = %q{qhoxie@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.md",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "dm-encrypted.gemspec",
29
+ "lib/dm-encrypted.rb",
30
+ "lib/dm-encrypted/encrypted.rb",
31
+ "test/dm-encrypted_test.rb",
32
+ "test/test_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/qhoxie/dm-encrypted}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Encrypted column type for DataMapper.}
39
+ s.test_files = [
40
+ "test/test_helper.rb",
41
+ "test/dm-encrypted_test.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<rcrypt>, [">= 0"])
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rcrypt>, [">= 0"])
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rcrypt>, [">= 0"])
57
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ require 'pathname'
2
+
3
+ require 'rubygems'
4
+ require 'rcrypt'
5
+
6
+ module DataMapper
7
+ module Types
8
+ dir = File.join(Pathname(__FILE__).dirname.expand_path, 'dm-encrypted').to_s
9
+
10
+ autoload :Encrypted, File.join(dir, 'encrypted')
11
+ end
12
+ end
13
+
@@ -0,0 +1,24 @@
1
+ module DataMapper
2
+ module Types
3
+ class Encrypted < DataMapper::Type
4
+ primitive String
5
+
6
+ def self.load(value, property)
7
+ return unless value
8
+ RCrypt.decrypt(value, ::PRIVATE_KEY)
9
+ end
10
+
11
+ def self.dump(value, property)
12
+ return unless value
13
+ RCrypt.encrypt(value, ::PUBLIC_KEY)
14
+ end
15
+
16
+ def self.typecast(value, property)
17
+ return value if value.is_a?(String)
18
+ return value.to_s if value.respond_to? :to_s
19
+ value
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class DmEncryptedTest < Test::Unit::TestCase
4
+ context "A column of type Encrypted" do
5
+ context "when passed a String" do
6
+ setup do
7
+ @raw = "secret"
8
+ @result = DataMapper::Types::Encrypted.dump(@raw, :property)
9
+ end
10
+
11
+ should "encrypt the plaintext" do
12
+ assert_not_equal @result, @raw
13
+ assert_equal @result.length, 350
14
+ end
15
+
16
+ should "decrypt to the plaintext" do
17
+ assert_equal DataMapper::Types::Encrypted.load(@result, :property), @raw
18
+ end
19
+ end
20
+
21
+ context "when passed nil" do
22
+ should "have nil ciphertext" do
23
+ assert_nil DataMapper::Types::Encrypted.dump(nil, :property)
24
+ end
25
+ end
26
+
27
+ context "when passed non-String values" do
28
+ should "coerce numbers" do
29
+ value = 1234
30
+ assert_equal DataMapper::Types::Encrypted.typecast(value, :property), value.to_s
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'dm-core'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'dm-encrypted'
9
+
10
+ PUBLIC_KEY, PRIVATE_KEY = RCrypt.generate_key_pair.values
11
+
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-encrypted
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Quin Hoxie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rcrypt
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: thoughtbot-shoulda
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Transparently add RSA encryption to DataMapper models.
36
+ email: qhoxie@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ - README.rdoc
45
+ files:
46
+ - .document
47
+ - .gitignore
48
+ - LICENSE
49
+ - README.md
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - dm-encrypted.gemspec
54
+ - lib/dm-encrypted.rb
55
+ - lib/dm-encrypted/encrypted.rb
56
+ - test/dm-encrypted_test.rb
57
+ - test/test_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/qhoxie/dm-encrypted
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Encrypted column type for DataMapper.
86
+ test_files:
87
+ - test/test_helper.rb
88
+ - test/dm-encrypted_test.rb