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

Abstract methods added to Key for signing scheme dissection #837

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

L77H
Copy link
Contributor

@L77H L77H commented Jun 28, 2024

Description of the changes being introduced by the pull request:

  • get_hash_algorithm_str abstract method added to Key class
  • get_hash_algorithm abstract method added to Key class
  • get_padding_name_str abstract method added to Key class
  • get_padding_name abstract method added to Key class
  • removed duplicate code

This PR tries to make classes using the Key instance independent of the specific Key implementation.
It also includes the changes from PR #836.

Fixes #594

"""Return payload padding name used for this key as a AsymmetricPadding"""

raise NotImplementedError

Copy link
Member

Choose a reason for hiding this comment

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

I can't really see a benefit of adding these to the Key interface. The only subclass, which implements them, is SSlibKey. Why don't make these SSlibKey-only methods?

Copy link
Contributor Author

@L77H L77H Jul 2, 2024

Choose a reason for hiding this comment

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

In _azure_signer.py and _gcp_signer.py both AzureSigner and GCPSigner take in a public key which is a Key object, on which they use the get hash method. Can this be changed to SSlibKey?

Copy link
Member

Choose a reason for hiding this comment

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

Hm. Good question. It looks like all Signer implementations take Keys, even though they can only handle specific Key implementations. That's probably okay. And I definitely don't want to disrupt anyone, by changing it.

But adding new behaviour to an abstract base class, which is specific to one subclass only, and raising NotImplementedError everywhere else, does not feel right.

Would it be okay to add regular functions, e.g. to _utils?

Thoughts, @jku?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I admit I didn't look at the specific uses in AzureSigner and GCPSigner yet but I would say it's fine for them to handle SSlibKey only -- that sounds correct to me, what else could the key be?

Whether that should be done in practice by type checking inside the AzureSigner and GCPSigner functions or by changing some public argument types I can't say without having a closer look...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my last commit the methods are now SSlibKey-only methods. I added the stricter type checking on GCPSigner and AzureSigner and some of their methods including a method from the Signer class. It seems to pass all the tests, but a more detailed review by @lukpueh and @jku would be advised.

Copy link
Member

Choose a reason for hiding this comment

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

Looks great! If the change isn't likely to bother any user, then I'd go with it. I'll give a detailed review after #836 is merged.

l77h and others added 3 commits July 2, 2024 19:48
Copy link
Collaborator

@jku jku left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

I did leave one comment but I really don't think it's that important, this looks good to merge

Comment on lines +62 to +63
class UnsupportedKeyType(Exception): # noqa: N818
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be marked private (_UnsupportedKeyType) since I don't think we intend to leak it outside... but that's a nit

@jku jku requested a review from lukpueh July 31, 2024 09:40
Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

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

Looks mostly good. Please address inline comment and consider updating the PR title.

raise NotImplementedError

def get_padding_name(self, hash_algorithm: None, salt_length: None) -> None:
raise NotImplementedError
Copy link
Member

Choose a reason for hiding this comment

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

These stubs are no longer needed, right?

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.

signer: deduplicate signing scheme dissection
3 participants