Support custom key pair - #5
Open
sodre wants to merge 2 commits into
Open
Conversation
A different approach where the user can pass a CustomKeyPair class to the build callable.
sodre
commented
Mar 30, 2021
| from functools import partial | ||
|
|
||
| from asn1crypto import x509, keys, csr, pem | ||
| from oscrypto import asymmetric |
Author
There was a problem hiding this comment.
We delay loading oscrypto until absolutely necessary.
- In case the public key is not asn1crypto.keys.PublicKeyInfo
- In case the private key does not conform to the duck typing
sodre
commented
Mar 30, 2021
Comment on lines
+165
to
+177
| if not isinstance(value, keys.PublicKeyInfo): | ||
| from oscrypto import asymmetric | ||
| if isinstance(value, asymmetric.PublicKey): | ||
| value = value.asn1 | ||
| else: | ||
| raise TypeError(_pretty_message( | ||
| ''' | ||
| subject_public_key must be an instance of | ||
| asn1crypto.keys.PublicKeyInfo or oscrypto.asymmetric.PublicKey, | ||
| not %s | ||
| ''', | ||
| _type_name(value) | ||
| )) |
Author
There was a problem hiding this comment.
This change is simply inverting the logic, to first look for an asn1crypto.PublicKeyInfo, only if that fails should we import oscrypto.asymmetric.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@wbond
This PR uses a different approach to break the dependency from oscrypto. The user just needs to pass a class to
buildthat has thealgorithmproperty and thesigncallable.I added a UnitTest to show how one can use it the construct.