Permalink
Browse files

Addin RSpec

  • Loading branch information...
1 parent 8934364 commit f44b666aefb7fd4f06a2938256402d84ca5b2c41 @jmazzi committed Jul 27, 2012
Showing with 53 additions and 2 deletions.
  1. +2 −0 .rspec
  2. +6 −0 Rakefile
  3. +2 −0 crypt_keeper_providers.gemspec
  4. +2 −2 lib/crypt_keeper_providers.rb
  5. +31 −0 lib/crypt_keeper_providers/aes.rb
  6. +10 −0 spec/spec_helper.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
@@ -1,2 +1,8 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new :spec
+Bundler::GemHelper.install_tasks
+
+task :default => [:spec]
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
gem.name = "crypt_keeper_providers"
gem.require_paths = ["lib"]
gem.version = CryptKeeperProviders::VERSION
+
+ gem.add_development_dependency 'rspec', '~> 2.10.0'
end
@@ -1,5 +1,5 @@
-require "crypt_keeper_providers/version"
+require 'crypt_keeper_providers/version'
+require 'crypt_keeper_providers/aes'
module CryptKeeperProviders
- # Your code goes here...
end
@@ -0,0 +1,31 @@
+require 'digest/sha1'
+require 'openssl'
+require 'base64'
+
+module CryptKeeperProviders
+ class Aes
+ attr_accessor :key, :aes
+
+ def initialize(options = {})
+ @key = options.delete :passphrase
+ @aes = ::OpenSSL::Cipher::Cipher.new("AES-256-CBC")
+ @aes.padding = 1
+ @key = Digest::SHA1.hexdigest(key).unpack('a2'*32).map{|x|x.hex}.pack('c'*32)
+ end
+
+ def encrypt(value)
+ value = value.to_s
+ aes.encrypt
+ aes.key = key
+ Base64::encode64(aes.update(value) + aes.final)
+ end
+
+ def decrypt(value)
+ value = Base64::decode64(value.to_s)
+ aes.decrypt
+ aes.key = key
+ aes.update(value) + aes.final
+ end
+
+ end
+end
View
@@ -0,0 +1,10 @@
+require 'crypt_keeper'
+
+SPEC_ROOT = Pathname.new File.expand_path File.dirname __FILE__
+Dir[SPEC_ROOT.join('support/*.rb')].each{|f| require f }
+
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+end

0 comments on commit f44b666

Please sign in to comment.