crypt_keeper_providers 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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +19 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/crypt_keeper_providers.gemspec +23 -0
- data/lib/crypt_keeper_providers.rb +5 -0
- data/lib/crypt_keeper_providers/aes.rb +39 -0
- data/lib/crypt_keeper_providers/version.rb +3 -0
- data/spec/aes_spec.rb +39 -0
- data/spec/spec_helper.rb +10 -0
- metadata +110 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', version: 2, fail_fast: true, all_on_start: false, all_after_pass: false do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
# Capybara request specs
|
17
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
18
|
+
end
|
19
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Justin Mazzi
|
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,29 @@
|
|
1
|
+
# CryptKeeperProviders
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'crypt_keeper_providers'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install crypt_keeper_providers
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/crypt_keeper_providers/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Justin Mazzi"]
|
6
|
+
gem.email = ["jmazzi@gmail.com"]
|
7
|
+
gem.description = %q{Encryption providers for crypt_keeper}
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "crypt_keeper_providers"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = CryptKeeperProviders::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec', '~> 2.10.0'
|
19
|
+
gem.add_development_dependency 'guard', '~> 1.2.0'
|
20
|
+
gem.add_development_dependency 'guard-rspec', '~> 1.1.0'
|
21
|
+
gem.add_development_dependency 'rake', '~> 0.9.2.2'
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
require 'openssl'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module CryptKeeperProviders
|
6
|
+
class Aes
|
7
|
+
attr_accessor :key, :aes
|
8
|
+
|
9
|
+
# Public: Initializes the class
|
10
|
+
#
|
11
|
+
# options - A hash of options. :passphrase is required
|
12
|
+
def initialize(options = {})
|
13
|
+
@key = options.delete :passphrase
|
14
|
+
@aes = ::OpenSSL::Cipher::Cipher.new("AES-256-CBC")
|
15
|
+
@aes.padding = 1
|
16
|
+
@key = Digest::SHA1.hexdigest(key).unpack('a2'*32).map{|x|x.hex}.pack('c'*32)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Encrypt a string
|
20
|
+
#
|
21
|
+
# Returns a string
|
22
|
+
def encrypt(value)
|
23
|
+
value = value.to_s
|
24
|
+
aes.encrypt
|
25
|
+
aes.key = key
|
26
|
+
Base64::encode64(aes.update(value) + aes.final)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Decrypt a string
|
30
|
+
#
|
31
|
+
# Returns a string
|
32
|
+
def decrypt(value)
|
33
|
+
value = Base64::decode64(value.to_s)
|
34
|
+
aes.decrypt
|
35
|
+
aes.key = key
|
36
|
+
aes.update(value) + aes.final
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/aes_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CryptKeeperProviders
|
4
|
+
describe Aes do
|
5
|
+
subject { Aes.new(passphrase: 'cake') }
|
6
|
+
|
7
|
+
describe "#initialize" do
|
8
|
+
let(:hexed_key) do
|
9
|
+
Digest::SHA1.hexdigest('cake').unpack('a2'*32).map{|x|x.hex}.pack('c'*32)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should extract the key and digest it" do
|
13
|
+
subject.key.should == hexed_key
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#encrypt" do
|
18
|
+
let(:encrypted) do
|
19
|
+
subject.encrypt 'string'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should encrypt the string" do
|
23
|
+
encrypted.should_not == 'string'
|
24
|
+
encrypted.should_not be_nil
|
25
|
+
encrypted.should_not be_empty
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#decrypt" do
|
30
|
+
let(:decrypted) do
|
31
|
+
subject.decrypt "duEAvLPakSVPRx2yGSmP8Q==\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should decrypt the string" do
|
35
|
+
decrypted.should == 'string'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'crypt_keeper_providers'
|
2
|
+
|
3
|
+
SPEC_ROOT = Pathname.new File.expand_path File.dirname __FILE__
|
4
|
+
Dir[SPEC_ROOT.join('support/*.rb')].each{|f| require f }
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crypt_keeper_providers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Justin Mazzi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &7948520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.10.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *7948520
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: guard
|
27
|
+
requirement: &7947820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.2.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *7947820
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard-rspec
|
38
|
+
requirement: &7947140 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.1.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *7947140
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &7946380 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.2.2
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *7946380
|
58
|
+
description: Encryption providers for crypt_keeper
|
59
|
+
email:
|
60
|
+
- jmazzi@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- Gemfile
|
68
|
+
- Guardfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- crypt_keeper_providers.gemspec
|
73
|
+
- lib/crypt_keeper_providers.rb
|
74
|
+
- lib/crypt_keeper_providers/aes.rb
|
75
|
+
- lib/crypt_keeper_providers/version.rb
|
76
|
+
- spec/aes_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: ''
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
hash: 287859248753652762
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: 287859248753652762
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.11
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Encryption providers for crypt_keeper
|
108
|
+
test_files:
|
109
|
+
- spec/aes_spec.rb
|
110
|
+
- spec/spec_helper.rb
|