Skip to content

Commit

Permalink
Merge pull request #2236 from dbussink/use-openssl-digest
Browse files Browse the repository at this point in the history
Move Digest classes to OpenSSL
  • Loading branch information
koic authored Feb 23, 2021
2 parents 0e219fa + e4d6e6f commit e75aa3c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/faker/blockchain/bitcoin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'digest'
require 'openssl'
require 'securerandom'

module Faker
Expand Down Expand Up @@ -51,7 +51,7 @@ def testnet_address
def address_for(network)
version = PROTOCOL_VERSIONS.fetch(network)
packed = version.chr + Faker::Config.random.bytes(20)
checksum = Digest::SHA2.digest(Digest::SHA2.digest(packed))[0..3]
checksum = OpenSSL::Digest::SHA256.digest(OpenSSL::Digest::SHA256.digest(packed))[0..3]
Faker::Base58.encode(packed + checksum)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/faker/blockchain/tezos.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'digest'
require 'openssl'
require 'securerandom'

module Faker
Expand Down Expand Up @@ -126,7 +126,7 @@ def secret_key
def encode_tz(prefix, payload_size)
prefix = PREFIXES.fetch(prefix)
packed = prefix.map(&:chr).join('') + Faker::Config.random.bytes(payload_size)
checksum = Digest::SHA2.digest(Digest::SHA2.digest(packed))[0..3]
checksum = OpenSSL::Digest::SHA256.digest(OpenSSL::Digest::SHA256.digest(packed))[0..3]
Faker::Base58.encode(packed + checksum)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/faker/default/crypto.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'digest'
require 'openssl'

module Faker
class Crypto < Base
Expand All @@ -15,7 +15,7 @@ class << self
#
# @faker.version 1.6.4
def md5
Digest::MD5.hexdigest(Lorem.characters)
OpenSSL::Digest::MD5.hexdigest(Lorem.characters)
end

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

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

0 comments on commit e75aa3c

Please sign in to comment.