Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compute_hash_digest to Algorithm objects #819

Closed
wants to merge 1 commit into from

Conversation

sirosen
Copy link
Contributor

@sirosen sirosen commented Oct 31, 2022

Algorithm.compute_hash_digest is defined as a method which inspects the object to see that it has the requisite attributes, hash_alg.

If hash_alg is not set, then the method raises a NotImplementedError. This applies to classes like NoneAlgorithm.

If hash_alg is set, then it is checked for

has_crypto  # is cryptography available?
and isinstance(hash_alg, type)
and issubclass(hash_alg, hashes.HashAlgorithm)

to see which API for computing a digest is appropriate -- hashlib vs cryptography.hazmat.primitives.hashes.

These checks could be avoided at runtime if it were necessary to optimize further (e.g. attach compute_hash_digest methods to classes with a class decorator) but this is not clearly a worthwhile optimization. Such perf tuning is intentionally omitted for now.


This is pulled from #775 . I can't tell why that PR didn't get reviewed, but I'll assume it was the doc addition. So I've rebased and taken just the functional part.

resolves #314

`Algorithm.compute_hash_digest` is defined as a method which inspects
the object to see that it has the requisite attributes, `hash_alg`.

If `hash_alg` is not set, then the method raises a
NotImplementedError. This applies to classes like NoneAlgorithm.

If `hash_alg` is set, then it is checked for
```
has_crypto  # is cryptography available?
and isinstance(hash_alg, type)
and issubclass(hash_alg, hashes.HashAlgorithm)
```
to see which API for computing a digest is appropriate --
`hashlib` vs `cryptography.hazmat.primitives.hashes`.

These checks could be avoided at runtime if it were necessary to
optimize further (e.g. attach compute_hash_digest methods to classes
with a class decorator) but this is not clearly a worthwhile
optimization. Such perf tuning is intentionally omitted for now.
@auvipy
Copy link
Collaborator

auvipy commented Nov 1, 2022

bot automatically closed that

@sirosen
Copy link
Contributor Author

sirosen commented Nov 1, 2022

I'm aware that the bot automatically closed it. But like I said, I have no information about why that never got reviewed.

If you can't get a reply to PRs in a few months (which, believe me, I understand -- I'm a package maintainer too), consider increasing your stalebot window. It doesn't serve anyone to have it closing things which are relatively fresh and unreviewed.

By a similar token, I've been trying to get #314 solved for 5 years now. I get that I seem to be the only person who cares about this, but it's demoralizing to leave a well-intentioned, polite comment like this one and then have stalebot come back and close it.

For low-touch and legacy projects I maintain, I do not use stalebot. It does more harm than good in those cases.

In any case, #775 now seems poised to merge, so I'm closing this as a duplicate.

@sirosen sirosen closed this Nov 1, 2022
@sirosen sirosen deleted the compute-hash-digest branch November 2, 2022 14:41
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.

Support exposure of hash algorithm digest to handle OIDC at_hash, potentially other spec extensions
2 participants