class Snowden::EncryptedSearcher
Attributes
crypto[R]
index[R]
padding_size[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. Note: the key and iv this crypto uses must match the ones used by the index * :index - a Snowden::EncryptedSearchIndex instance . * :wildcard_generator - an instance of Snowden::WildcardGenerator
# File lib/snowden/encrypted_searcher.rb, line 12 def initialize(args) @crypto = args.fetch(:crypto) @index = args.fetch(:index) @wildcard_generator = args.fetch(:wildcard_generator) end
Public Instance Methods
search(search_string)
click to toggle source
Looks up the search string in the index.
@param search_string [String] the string to search the index for
@return [ [String] ] a list of strings that were matched by the search
string in the index.
# File lib/snowden/encrypted_searcher.rb, line 24 def search(search_string) wildcard_generator.wildcards(search_string).flat_map { |wildcard| encrypted_values = encrypted_values_for_key(wildcard) encrypted_values.map {|v| crypto.padded_decrypt(v) } }.uniq end
Private Instance Methods
encrypted_values_for_key(key)
click to toggle source
# File lib/snowden/encrypted_searcher.rb, line 35 def encrypted_values_for_key(key) encrypted_key = crypto.encrypt(key) index.search(encrypted_key) end