class Snowden::EncryptedSearchIndex
Attributes
backend[R]
bytestream_generator[R]
crypto[R]
wildcard_generator[R]
Public Class Methods
new(args)
click to toggle source
Creates a new search index
@param args [Hash] A hash that must contain the following keys: * :crypto - an instance of Snowden::Crypto primed with some key and iv * :backend - a Snowden::Backends compatible backend. * :wildcard_generator - an instance of Snowden::WildcardGenerator
# File lib/snowden/encrypted_search_index.rb, line 11 def initialize(args) @crypto = args.fetch(:crypto) @backend = args.fetch(:backend) @wildcard_generator = args.fetch(:wildcard_generator) end
Public Instance Methods
search(key)
click to toggle source
Looks up the key in the backend
@api private
@param key [String] the key to look up in the backend. Note: the key does
not have wildcarding applied to it. Calling this method directly is probably a bad idea.
# File lib/snowden/encrypted_search_index.rb, line 37 def search(key) backend.find(key) end
store(key, value)
click to toggle source
Stores a value under the key
@param key [String] the key to store the value under @param value [String] the value to store in the key @return nil
# File lib/snowden/encrypted_search_index.rb, line 23 def store(key, value) wildcard_generator.wildcards(key).each do |wildcard| backend.save(encrypt_key(wildcard), encrypt_value(value)) end nil end
Private Instance Methods
encrypt_key(key)
click to toggle source
# File lib/snowden/encrypted_search_index.rb, line 45 def encrypt_key(key) crypto.encrypt(key) end
encrypt_value(value)
click to toggle source
# File lib/snowden/encrypted_search_index.rb, line 49 def encrypt_value(value) crypto.padded_encrypt(value) end