Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/faker/default/crypto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
module Faker
class Crypto < Base
class << self
# Setting the lorem character number lower than the default of
# 255 reduces the time complexity of each hash algorithm while
# still returning deterministically unique values. See
# https://github.com/faker-ruby/faker/pull/2938 for more info.
MD5_MIN_NUMBER_OF_CHARACTERS = 25
SHA1_MIN_NUMBER_OF_CHARACTERS = 31
SHA256_MIN_NUMBER_OF_CHARACTERS = 50
SHA512_MIN_NUMBER_OF_CHARACTERS = 100

##
# Produces an MD5 hash.
#
Expand All @@ -15,7 +24,7 @@ class << self
#
# @faker.version 1.6.4
def md5
OpenSSL::Digest::MD5.hexdigest(Lorem.characters)
OpenSSL::Digest::MD5.hexdigest(Lorem.characters(number: MD5_MIN_NUMBER_OF_CHARACTERS))
end

##
Expand All @@ -28,7 +37,7 @@ def md5
#
# @faker.version 1.6.4
def sha1
OpenSSL::Digest::SHA1.hexdigest(Lorem.characters)
OpenSSL::Digest::SHA1.hexdigest(Lorem.characters(number: SHA1_MIN_NUMBER_OF_CHARACTERS))
end

##
Expand All @@ -41,7 +50,7 @@ def sha1
#
# @faker.version 1.6.4
def sha256
OpenSSL::Digest::SHA256.hexdigest(Lorem.characters)
OpenSSL::Digest::SHA256.hexdigest(Lorem.characters(number: SHA256_MIN_NUMBER_OF_CHARACTERS))
end

##
Expand All @@ -54,7 +63,7 @@ def sha256
#
# @faker.version next
def sha512
OpenSSL::Digest::SHA512.hexdigest(Lorem.characters)
OpenSSL::Digest::SHA512.hexdigest(Lorem.characters(number: SHA512_MIN_NUMBER_OF_CHARACTERS))
end
end
end
Expand Down