Skip to content

Commit

Permalink
Fixes for api comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Phippen committed Sep 19, 2013
1 parent c5fe7dc commit e824dac
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 46 deletions.
23 changes: 3 additions & 20 deletions README.md
Expand Up @@ -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")
Expand Down Expand Up @@ -106,32 +106,15 @@ 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

```ruby
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`
Expand Down
2 changes: 1 addition & 1 deletion lib/snowden.rb
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions lib/snowden/configuration.rb
Expand Up @@ -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
19 changes: 2 additions & 17 deletions spec/readme_spec.rb
Expand Up @@ -5,15 +5,14 @@
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
# 256 bit aes with 128 bit block
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")
Expand All @@ -36,27 +35,13 @@
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"

aes_key = "a"*(256/8)
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
14 changes: 12 additions & 2 deletions spec/snowden_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e824dac

Please sign in to comment.