diff --git a/README.md b/README.md index 6e936ec..e4a8c2a 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ require 'snowden' aes_key = "a"*(256/8) aes_iv = "b"*(128/8) -index = Snowden.new_encrypted_index(aes_key, aes_iv) +index = Snowden.new_encrypted_index(aes_key, aes_iv, Snowden::Backends::HashBackend.new) searcher = Snowden.new_encrypted_searcher(aes_key, aes_iv, index) index.store("bacon", "bits") @@ -106,24 +106,7 @@ index = Snowden.new_encrypted_index(aes_key, aes_iv, redis_backend) ## Configuration Snowden has a core configuration object that allows you to change various -aspects of the gem's operation. Examples include: - - -###Changing the default backend used by indices -```ruby -require "redis" - -redis = Redis.new(:driver => :hiredis) -redis_backend = Snowden::Backends::RedisBackend.new("index_namespace", redis) - -Snowden.configuration.backend = redis_backend - -#Sometime later: -aes_key = OpenSSL::Random.random_bytes(256/8) -aes_iv = OpenSSL::Random.random_bytes(128/8) - -index = Snowden.new_encrypted_index(aes_key, aes_iv) -``` +aspects of the gem's operation. ###Changing the cipher used by Snowden @@ -131,7 +114,7 @@ index = Snowden.new_encrypted_index(aes_key, aes_iv) Snowden.configuration.cipher_spec = "RC4" #Sometime later: -index = Snowden.new_encrypted_index(key, iv) +index = Snowden.new_encrypted_index(key, iv, Snowden::Backends::HashBackend.new) ``` For a complete list of possible ciphers you can use this snippet in `irb` diff --git a/lib/snowden.rb b/lib/snowden.rb index eb2e318..19d5583 100644 --- a/lib/snowden.rb +++ b/lib/snowden.rb @@ -28,7 +28,7 @@ def self.configuration # @return [Snowden::EncryptedSearchIndex] # a snowden index to store values in. # - def self.new_encrypted_index(key, iv, backend=configuration.backend) + def self.new_encrypted_index(key, iv, backend) EncryptedSearchIndex.new( :crypto => crypto_for(key, iv), :backend => backend, diff --git a/lib/snowden/configuration.rb b/lib/snowden/configuration.rb index 7712fde..ad78acc 100644 --- a/lib/snowden/configuration.rb +++ b/lib/snowden/configuration.rb @@ -15,20 +15,14 @@ module Snowden # Change at your own risk. # Never set to lower than 2 blocks if you're # using a block cipher. - # - #@attr backend The default snowden storage backend. - # Defaults to an instance of Snowden::Backends::HashBackend class Configuration attr_accessor :edit_distance, :cipher_spec, :padding_byte_size, :backend - - #Sets up the configuration object def initialize @edit_distance = 3 @cipher_spec = "AES-256-CBC" @padding_byte_size = 32 - @backend = Snowden::Backends::HashBackend.new end end end diff --git a/spec/readme_spec.rb b/spec/readme_spec.rb index 29018c9..862c419 100644 --- a/spec/readme_spec.rb +++ b/spec/readme_spec.rb @@ -5,7 +5,6 @@ describe "the examples from the readme" do before do Redis.new(:driver => :hiredis).flushdb - Snowden.configuration.backend = Snowden::Backends::HashBackend.new("",{}) end it "works for the example in the usage section" do @@ -13,7 +12,7 @@ aes_key = "a"*(256/8) aes_iv = "b"*(128/8) - index = Snowden.new_encrypted_index(aes_key, aes_iv) + index = Snowden.new_encrypted_index(aes_key, aes_iv, Snowden::Backends::HashBackend.new("",{})) searcher = Snowden.new_encrypted_searcher(aes_key, aes_iv, index) index.store("bacon", "bits") @@ -36,20 +35,6 @@ expect(searcher.search("bac")).to eq(["bits"]) end - it "works for the redis example in the configuration section" do - aes_key = "a"*(256/8) - aes_iv = "b"*(128/8) - - redis = Redis.new(:driver => :hiredis) - redis_backend = Snowden::Backends::RedisBackend.new("index_namespace", redis) - - Snowden.configuration.backend = redis_backend - - #Sometime later: - index = Snowden.new_encrypted_index(aes_key, aes_iv) - expect(index.instance_variable_get(:@backend)).to be_a(Snowden::Backends::RedisBackend) - end - it "works for the cipher_spec example in the configuration section" do Snowden.configuration.cipher_spec = "RC4" @@ -57,6 +42,6 @@ aes_iv = "b"*(128/8) #Sometime later: - index = Snowden.new_encrypted_index(aes_key, aes_iv) + index = Snowden.new_encrypted_index(aes_key, aes_iv, Snowden::Backends::HashBackend.new("",{})) end end diff --git a/spec/snowden_spec.rb b/spec/snowden_spec.rb index 9223b2b..74d94a3 100644 --- a/spec/snowden_spec.rb +++ b/spec/snowden_spec.rb @@ -6,7 +6,12 @@ let(:iv) { "b"*(128/8) } describe ".new_encrypted_index" do - subject(:index) { Snowden.new_encrypted_index(key, iv) } + subject(:index) { Snowden.new_encrypted_index( + key, + iv, + Snowden::Backends::HashBackend.new({}) + ) + } it "gives back an index" do expect(index).to be_a_kind_of Snowden::EncryptedSearchIndex @@ -23,7 +28,12 @@ end describe ".new_encrypted_searcher" do - let(:index) { Snowden.new_encrypted_index(key, iv) } + let(:index) { Snowden.new_encrypted_index( + key, + iv, + Snowden::Backends::HashBackend.new({}) + ) + } subject(:searcher) { Snowden.new_encrypted_searcher(key, iv, index) } it "gives back a searcher" do