Skip to content

Commit

Permalink
Adds FFaker::Crypto::sha256 (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
professor committed Sep 7, 2023
1 parent da88ae9 commit 43352f6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## development

- Add your change HERE
- Adds FFaker::Crypto.sha256 [@professor]
- Update README [@professor]
- Adds FFaker::Number.between [@professor]
- Fixed `FFaker::Number.unique.number(digits: 1)` under Ruby 3 [@simonhildebrandt]
Expand Down
7 changes: 7 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* [FFaker::CompanySE](#ffakercompanyse)
* [FFaker::Conference](#ffakerconference)
* [FFaker::CoursesFR](#ffakercoursesfr)
* [FFaker::Crypto](#ffakercrypto)
* [FFaker::Currency](#ffakercurrency)
* [FFaker::Date](#ffakerdate)
* [FFaker::DizzleIpsum](#ffakerdizzleipsum)
Expand Down Expand Up @@ -1056,6 +1057,12 @@
| Method | Example |
| ------ | ------- |

## FFaker::Crypto

| Method | Example |
|----------| ------- |
| `sha256` | 57ce6f7c592f8dfd81d794830bf97622bcbb64ab7698559f9fb04d57414bf769|

## FFaker::Currency

| Method | Example |
Expand Down
1 change: 1 addition & 0 deletions lib/ffaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def self.bothify(masks)
autoload :CompanySE, 'ffaker/company_se'
autoload :Conference, 'ffaker/conference'
autoload :CoursesFR, 'ffaker/courses_fr'
autoload :Crypto, 'ffaker/crypto'
autoload :Currency, 'ffaker/currency'
autoload :Date, 'ffaker/date'
autoload :DizzleIpsum, 'ffaker/dizzle_ipsum'
Expand Down
13 changes: 13 additions & 0 deletions lib/ffaker/crypto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'openssl'

module FFaker
module Crypto
extend ModuleUtils
extend self

def sha256
OpenSSL::Digest::SHA256.hexdigest(Lorem.characters)
end
end
end
15 changes: 15 additions & 0 deletions test/test_crypto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require_relative 'helper'

class TestCrypto < Test::Unit::TestCase
include DeterministicHelper

assert_methods_are_deterministic(FFaker::Crypto, :sha256)

def test_sha256
assert FFaker::Crypto.sha256.is_a?(String)
assert FFaker::Crypto.sha256.length == 64
assert_match(/\A[a-z\d]{64}\z/, FFaker::Crypto.sha256)
end
end

0 comments on commit 43352f6

Please sign in to comment.