lib/blind_index.rb in blind_index-1.0.2 vs lib/blind_index.rb in blind_index-2.0.0
- old
+ new
@@ -1,9 +1,9 @@
# dependencies
require "active_support"
require "openssl"
-require "argon2"
+require "argon2/kdf"
# modules
require "blind_index/key_generator"
require "blind_index/model"
require "blind_index/version"
@@ -16,11 +16,11 @@
attr_writer :master_key
end
self.default_options = {}
def self.master_key
- @master_key ||= ENV["BLIND_INDEX_MASTER_KEY"]
+ @master_key ||= ENV["BLIND_INDEX_MASTER_KEY"] || (defined?(Lockbox.master_key) && Lockbox.master_key)
end
def self.generate_bidx(value, key:, **options)
options = {
encode: true
@@ -62,11 +62,11 @@
# m is memory in kibibytes (1024 bytes)
m = (cost_options[:m] || (options[:slow] ? 15 : 12)).to_i
# use same bounds as rbnacl
raise BlindIndex::Error, "m must be between 3 and 22" if m < 3 || m > 22
- [Argon2::Engine.hash_argon2id(value, key, t, m, size)].pack("H*")
+ Argon2::KDF.argon2id(value, salt: key, t: t, m: m, p: 1, length: size)
when :pbkdf2_sha256
iterations = cost_options[:iterations] || options[:iterations] || (options[:slow] ? 100000 : 10000)
OpenSSL::PKCS5.pbkdf2_hmac(value, key, iterations, size, "sha256")
when :argon2i
t = (cost_options[:t] || 3).to_i
@@ -76,11 +76,11 @@
# m is memory in kibibytes (1024 bytes)
m = (cost_options[:m] || 12).to_i
# use same bounds as rbnacl
raise BlindIndex::Error, "m must be between 3 and 22" if m < 3 || m > 22
- [Argon2::Engine.hash_argon2i(value, key, t, m, size)].pack("H*")
+ Argon2::KDF.argon2i(value, salt: key, t: t, m: m, p: 1, length: size)
when :scrypt
n = cost_options[:n] || 4096
r = cost_options[:r] || 8
cp = cost_options[:p] || 1
SCrypt::Engine.scrypt(value, key, n, r, cp, size)
@@ -131,15 +131,10 @@
ActiveSupport.on_load(:active_record) do
require "blind_index/extensions"
extend BlindIndex::Model
- if defined?(ActiveRecord::TableMetadata)
- ActiveRecord::TableMetadata.prepend(BlindIndex::Extensions::TableMetadata)
- else
- ActiveRecord::PredicateBuilder.singleton_class.prepend(BlindIndex::Extensions::PredicateBuilder)
- end
-
+ ActiveRecord::TableMetadata.prepend(BlindIndex::Extensions::TableMetadata)
ActiveRecord::DynamicMatchers::Method.prepend(BlindIndex::Extensions::DynamicMatchers)
unless ActiveRecord::VERSION::STRING.start_with?("5.1.")
ActiveRecord::Validations::UniquenessValidator.prepend(BlindIndex::Extensions::UniquenessValidator)
end