Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dad9df5

Browse files
committedMar 20, 2025
fix(tests): update error handling in SHAKE and KMAC specs
- Change expected error type from SHA3::Digest::DigestError to SHA3::Digest::Error in SHAKE tests. - Rename TEST_VECTORS to KMAC_TEST_VECTORS for clarity and update error handling for invalid algorithms to raise ArgumentError.
1 parent cdf8fd5 commit dad9df5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
 

‎spec/sha3_digest_core_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@
198198
describe 'SHAKE functionality' do
199199
it 'requires output length for SHAKE algorithms' do
200200
shake = described_class.new(:shake_128)
201-
expect { shake.digest }.to raise_error(SHA3::Digest::DigestError)
202-
expect { shake.hexdigest }.to raise_error(SHA3::Digest::DigestError)
201+
expect { shake.digest }.to raise_error(SHA3::Digest::Error)
202+
expect { shake.hexdigest }.to raise_error(SHA3::Digest::Error)
203203
end
204204

205205
it 'produces variable length output for SHAKE algorithms' do
@@ -340,8 +340,8 @@
340340
end
341341

342342
it 'requires output length for digest methods' do
343-
expect { SHA3::Digest::SHAKE_128.new.digest }.to raise_error(SHA3::Digest::DigestError)
344-
expect { SHA3::Digest::SHAKE_256.new.hexdigest }.to raise_error(SHA3::Digest::DigestError)
343+
expect { SHA3::Digest::SHAKE_128.new.digest }.to raise_error(SHA3::Digest::Error)
344+
expect { SHA3::Digest::SHAKE_256.new.hexdigest }.to raise_error(SHA3::Digest::Error)
345345
end
346346

347347
it 'provides class methods for direct hashing' do

‎spec/sha3_kmac_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Test vectors from NIST SP 800-185
77
# https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/KMAC_samples.pdf
88

9-
TEST_VECTORS = [
9+
KMAC_TEST_VECTORS = [
1010
{
1111
algorithm: :kmac_128,
1212
custom: '',
@@ -60,7 +60,7 @@
6060
end
6161

6262
it 'raises an error for invalid algorithm' do
63-
expect { described_class.new(:invalid_algo, 32, 'my key') }.to raise_error(SHA3::KMAC::KMACError)
63+
expect { described_class.new(:invalid_algo, 32, 'my key') }.to raise_error(ArgumentError)
6464
end
6565

6666
it 'requires the algorithm, output length, and key parameters' do
@@ -246,7 +246,7 @@
246246
end
247247
end
248248

249-
TEST_VECTORS.each do |vector|
249+
KMAC_TEST_VECTORS.each do |vector|
250250
describe "test vector for #{vector[:description]}" do
251251
it 'produces the expected digest' do
252252
kmac = described_class.new(

0 commit comments

Comments
 (0)
Please sign in to comment.