Skip to content

Commit 42f905c

Browse files
hieuk09anakinj
authored andcommitted
Use correct methods when raising error during signing/verification with EdDSA
1 parent d9a87bc commit 42f905c

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
- Deprecation warnings for deprecated methods and classes [#629](https://github.com/jwt/ruby-jwt/pull/629) ([@anakinj](https://github.com/anakinj))
1616
- Improved documentation for public apis [#629](https://github.com/jwt/ruby-jwt/pull/629) ([@anakinj](https://github.com/anakinj))
17+
- Use correct methods when raising error during signing/verification with EdDSA [#633](https://github.com/jwt/ruby-jwt/pull/633)
1718
- Your contribution here
1819

1920
## [v2.9.3](https://github.com/jwt/ruby-jwt/tree/v2.9.3) (2024-10-03)

lib/jwt/jwa/eddsa.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ def initialize(alg)
1111

1212
def sign(data:, signing_key:)
1313
unless signing_key.is_a?(RbNaCl::Signatures::Ed25519::SigningKey)
14-
raise_encode_error!("Key given is a #{signing_key.class} but has to be an RbNaCl::Signatures::Ed25519::SigningKey")
14+
raise_sign_error!("Key given is a #{signing_key.class} but has to be an RbNaCl::Signatures::Ed25519::SigningKey")
1515
end
1616

1717
signing_key.sign(data)
1818
end
1919

2020
def verify(data:, signature:, verification_key:)
2121
unless verification_key.is_a?(RbNaCl::Signatures::Ed25519::VerifyKey)
22-
raise_decode_error!("key given is a #{verification_key.class} but has to be a RbNaCl::Signatures::Ed25519::VerifyKey")
22+
raise_verify_error!("key given is a #{verification_key.class} but has to be a RbNaCl::Signatures::Ed25519::VerifyKey")
2323
end
2424

2525
verification_key.verify(signature, data)

spec/jwt/jwa/eddsa_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,20 @@
1313
expect(JWT::JWA::Eddsa.verify('RS256', key.verify_key, 'data', signature)).to be(true)
1414
end
1515
end
16+
17+
context 'when when signing with invalid RbNaCl::Signatures::Ed25519::SigningKey' do
18+
it 'raises an error' do
19+
expect do
20+
JWT::JWA::Eddsa.sign('RS256', 'data', 'key')
21+
end.to raise_error(JWT::EncodeError, 'Key given is a String but has to be an RbNaCl::Signatures::Ed25519::SigningKey')
22+
end
23+
end
24+
25+
context 'when when verifying with invalid RbNaCl::Signatures::Ed25519::VerifyKey' do
26+
it 'raises an error' do
27+
expect do
28+
JWT::JWA::Eddsa.verify('RS256', 'key', 'data', 'signature')
29+
end.to raise_error(JWT::DecodeError, 'key given is a String but has to be a RbNaCl::Signatures::Ed25519::VerifyKey')
30+
end
31+
end
1632
end

0 commit comments

Comments
 (0)