Module: DoorMat::Crypto
- Defined in:
- lib/door_mat/crypto.rb,
lib/door_mat/crypto/fast_hash.rb,
lib/door_mat/crypto/password_hash.rb,
lib/door_mat/crypto/secure_compare.rb,
lib/door_mat/crypto/symmetric_store.rb,
lib/door_mat/crypto/asymmetric_store.rb
Defined Under Namespace
Modules: AsymmetricStore, FastHash, PasswordHash, SymmetricStore
Classes: SkipCallback
Class Method Summary
collapse
Class Method Details
.current_skip_crypto_callback ⇒ Object
22
23
24
|
# File 'lib/door_mat/crypto.rb', line 22
def self.current_skip_crypto_callback
RequestStore.store[:current_skip_crypto_callback] ||= DoorMat::Crypto::SkipCallback.new
end
|
.decrypt_shared(secrets, with_key) ⇒ Object
16
17
18
19
20
|
# File 'lib/door_mat/crypto.rb', line 16
def self.decrypt_shared(secrets, with_key)
Array(secrets).map do |s|
DoorMat::Crypto::SymmetricStore.decrypt(s, with_key)
end
end
|
.encrypt_shared(secrets, with_key) ⇒ Object
10
11
12
13
14
|
# File 'lib/door_mat/crypto.rb', line 10
def self.encrypt_shared(secrets, with_key)
Array(secrets).map do |s|
DoorMat::Crypto::SymmetricStore.encrypt(s, with_key)[:ciphertext]
end
end
|
.secure_compare(lhs, rhs, constant_length = nil) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/door_mat/crypto/secure_compare.rb', line 8
def secure_compare(lhs, rhs, constant_length=nil)
constant_length ||= DoorMat.configuration.crypto_secure_compare_default_length
constant_length = [constant_length.to_int, lhs.to_str.bytesize, rhs.to_str.bytesize].max
random_padding = SecureRandom.random_bytes(constant_length)
l = lhs.to_str.ljust(constant_length, random_padding).unpack "C#{constant_length}"
r = rhs.to_str.ljust(constant_length, random_padding).unpack "C#{constant_length}"
result = 0
l.zip(r) { |a,b| result |= a ^ b }
0 == result
end
|
.skip_crypto_callback ⇒ Object