Skip to content

Fix copy-pasted pattern in OCSPCertID hash algorithm normalization - #311

Open
ZayanKhan-12 wants to merge 1 commit into
apple:mainfrom
ZayanKhan-12:fix/ocsp-certid-sha512-pattern
Open

Fix copy-pasted pattern in OCSPCertID hash algorithm normalization#311
ZayanKhan-12 wants to merge 1 commit into
apple:mainfrom
ZayanKhan-12:fix/ocsp-certid-sha512-pattern

Conversation

@ZayanKhan-12

Copy link
Copy Markdown

Fixes #273 (@Lukasa invited a PR there and the reporter never followed up, so picking it up).

Motivation

The sha512 case of OCSPCertID's hash-algorithm normalization switch reads:

case .sha512, .sha1UsingNil:
    return .sha512UsingNil

The .sha1UsingNil pattern is a copy-paste from the sha1 case — and it's dead code, since .sha1UsingNil is already matched by case .sha1, .sha1UsingNil: above.

To be candid about impact: behavior is accidentally correct today. .sha512 still hits the first pattern and normalizes properly, and .sha512UsingNil falls through to default, which returns it unchanged — the same result the intended pattern produces. So this is a correctness-of-intent fix, not a behavior change; the danger was latent (e.g. if the default case ever changed).

Modifications

  • case .sha512, .sha1UsingNil:case .sha512, .sha512UsingNil:
  • Added testCertIDNormalizesHashAlgorithmParameters, pinning the absent-parameters → NULL-parameters normalization (and the already-normalized spellings) for all four supported hash algorithms, so the intended mapping is now under test.

Result

The switch states its intent; normalization behavior for every supported algorithm is covered by tests. Full suite: 578 tests pass; changed files clean under swift format lint.

🤖 Generated with Claude Code

The sha512 normalization case in OCSPCertID's DER parser matched
".sha512, .sha1UsingNil" instead of ".sha512, .sha512UsingNil" - an
apparent copy-paste from the sha1 case. The second pattern was dead
(already matched by the sha1 case above), and .sha512UsingNil inputs
happened to be preserved by the default case, so behavior was
accidentally correct; the pattern now states the intent directly.

Adds a test pinning the parameter normalization of all four supported
hash algorithms.

Fixes apple#273.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

Incorrect AlgorithmIdentifier

1 participant