Skip to content

Fix: Replace IllegalArgumentException with GeneralSecurityException in HpkePrimitiveFactory - #1

Open
LuisCastellanos-dev wants to merge 1 commit into
mainfrom
fix/hpke-primitive-factory-exception-type
Open

Fix: Replace IllegalArgumentException with GeneralSecurityException in HpkePrimitiveFactory#1
LuisCastellanos-dev wants to merge 1 commit into
mainfrom
fix/hpke-primitive-factory-exception-type

Conversation

@LuisCastellanos-dev

Copy link
Copy Markdown
Owner

Problem

HpkePrimitiveFactory.createKem(), createKdf(), and createAead() throw
IllegalArgumentException when an unrecognized algorithm identifier is passed.
This is inconsistent with the rest of Tink's internal API, which uses
GeneralSecurityException as the standard exception type for cryptographic failures.

Callers that wrap these methods inside catch (GeneralSecurityException e)
the idiomatic Tink pattern — will not catch the failure. The exception propagates
as an unchecked RuntimeException, bypassing any recovery logic.

Additionally, createKdf(byte[]) and createKdf(KdfId) did not declare
throws GeneralSecurityException, making the inconsistency visible in the signature.

Changes

HpkePrimitiveFactory.java:

  • Changed all 6 throw new IllegalArgumentException(...) to GeneralSecurityException
  • Added throws GeneralSecurityException to both createKdf overloads

HpkePrimitiveFactoryTest.java:

  • Updated 3 error-path tests to expect GeneralSecurityException
  • Added import java.security.GeneralSecurityException

Impact

Source-compatible for callers already catching GeneralSecurityException.
The createKdf() signature change adds a checked exception where none existed before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant