Skip to content

fix(contrib): HashTypeFactory.from_composite_str() raise UnknownHashTypeException for unsupported or malformed composite hashes - #1080

Open
vaibhav4046 wants to merge 2 commits into
CycloneDX:mainfrom
vaibhav4046:fix/hash-composite-unknown-type
Open

vaibhav4046 wants to merge 2 commits into
CycloneDX:mainfrom
vaibhav4046:fix/hash-composite-unknown-type

Conversation

@vaibhav4046

@vaibhav4046 vaibhav4046 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

HashTypeFactory.from_composite_str() documents UnknownHashTypeException but raised AttributeError for sha/sha3/blake2 prefixes with no matching HashAlgorithm member (for example blake2b_256, sha224) and IndexError when the colon separator is missing. Both now raise UnknownHashTypeException. Behaviour for supported prefixes is unchanged. New tests in tests/test_contrib/test_hash_factories.py fail on main and pass with the change.

Resolves or fixes issue: #1075

AI Tool Disclosure

  • My contribution does not include any AI-generated content
  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: Instinct (AI assistant working on my behalf)
    • LLMs and versions: model name and version are not exposed to the assistant
    • Prompts: asked to fix this specific open issue with a minimal change and tests that fail before and pass after the fix

Affirmation

…osite hashes

Closes CycloneDX#1075

Signed-off-by: Vaibhav Lalwani <vaibhav4046@users.noreply.github.com>
@vaibhav4046
vaibhav4046 requested a review from a team as a code owner November 25, 2026 16:28
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Comment thread cyclonedx/contrib/hash/factories.py Resolved
@jkowalleck jkowalleck changed the title fix: raise UnknownHashTypeException for unsupported or malformed composite hashes fix(contrib): raise UnknownHashTypeException for unsupported or malformed composite hashes Nov 25, 2026
@jkowalleck jkowalleck added bug Something isn't working contrib Contributed features not part of the core library. labels Nov 25, 2026
@jkowalleck jkowalleck changed the title fix(contrib): raise UnknownHashTypeException for unsupported or malformed composite hashes fix(contrib): HashTypeFactory.from_composite_str() raise UnknownHashTypeException for unsupported or malformed composite hashes Nov 25, 2026
@jkowalleck

Copy link
Copy Markdown
Member

@vaibhav4046 could you have your AI agent update the PR description according to our PR template?
see https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/.github/PULL_REQUEST_TEMPLATE.md

Signed-off-by: Vaibhav Lalwani <vaibhav4046@users.noreply.github.com>
@vaibhav4046

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I rewrote the change to keep it in scope: the original structure of from_composite_str is untouched. It now only adds a missing-separator check and replaces the four getattr lookups with a small helper that raises UnknownHashTypeException. The PR description now follows the template, including the AI disclosure.

('blake2b256:ABC', HashAlgorithm.BLAKE2B_256),
('blake3:ABC', HashAlgorithm.BLAKE3),
):
with self.subTest(composite=composite):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, don't use the subtest.
we use DDT here - https://ddt.readthedocs.io/en/latest/example.html

see the other test files for examples.

This branch has not been deployed

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

Labels

bug Something isn't working contrib Contributed features not part of the core library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HashTypeFactory.from_composite_str() raises AttributeError / IndexError instead of UnknownHashTypeException

2 participants