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

Better error messages when missing cryptography package #231

Merged
merged 8 commits into from
Dec 1, 2016
Merged

Better error messages when missing cryptography package #231

merged 8 commits into from
Dec 1, 2016

Conversation

vimalloc
Copy link
Contributor

In reference to #230. If trying to use a cryptography algorithm without the cryptography package installed, you will get this error:

NotImplementedError: "cryptography" package must be installed to use this algorithm

instead of:

NotImplementedError: Algorithm not supported

@vimalloc
Copy link
Contributor Author

Whoops, looks like i based this on an older branch. I will update this.

@coveralls
Copy link

coveralls commented Nov 28, 2016

Coverage Status

Coverage decreased (-25.2%) to 74.763% when pulling b83d6e1 on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

coveralls commented Nov 28, 2016

Coverage Status

Coverage decreased (-0.2%) to 99.842% when pulling 2fec851 on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

coveralls commented Nov 28, 2016

Coverage Status

Coverage decreased (-0.2%) to 99.842% when pulling 31494c9 on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

coveralls commented Nov 28, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 8520c8f on vimalloc:master into 5caa1af on jpadilla:master.

6 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 8520c8f on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 8520c8f on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 8520c8f on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 8520c8f on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 8520c8f on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 8520c8f on vimalloc:master into 5caa1af on jpadilla:master.

Copy link
Contributor

@mark-adams mark-adams left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I made a couple of suggestions that I'd like to see made but overall, I think this will be a really helpful change! 👍

@@ -303,6 +303,12 @@ def test_invalid_crypto_alg(self, jws, payload):
with pytest.raises(NotImplementedError):
jws.encode(payload, 'secret', algorithm='HS1024')

@pytest.mark.skipif(has_crypto, reason='Tests better errors if crypography not installed')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better if it just said "Scenario requires that cryptography not be installed"

raise NotImplementedError('Algorithm not supported')
if not has_crypto and algorithm in get_crypto_algorithms():
raise NotImplementedError('"cryptography" package must be '
'installed to use this algorithm')
Copy link
Contributor

Choose a reason for hiding this comment

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

How about something like Algorithm %s could not be found. Do you have cryptography installed?


return default_algorithms


def get_crypto_algorithms():
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of the get_crypto_algorithms() approach, I think it might be simpler to just use a set to define the cryptography-supplied algorithms.

Something like:

requires_cryptography = set([
    'RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES521',
    'PS256', 'PS384', 'PS512'
])

Then instead of if not has_crypto and algorithm in get_crypto_algorithms(), you could simply check if algorithm in requires_cryptography.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thought with having it be a method was so we could define what algorithms required crypto to be installed in a single place, instead of having to remember to update a set as well as the function which actually saves the crypto algorithms as available. If you think this would be better, I would be more then happy to make the change :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, I think that it requires a little extra work to update but it is a little simpler in the actual implementation.

@@ -131,5 +131,6 @@ def main():
else:
p.print_help()


Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you might have added an extra space here?

@@ -171,6 +199,7 @@ def sign(self, msg, key):
def verify(self, msg, key, sig):
return constant_time_compare(sig, self.sign(msg, key))


Copy link
Contributor

Choose a reason for hiding this comment

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

Another extra space?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This (and the other extra space) was to fix flake8 errors reported by the tests. It seemed to be failing to pass without the changes (but maybe that was just a local configuration on my box)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

er. Extra newline, not extra space.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's possible our flake8 in CI just started caring about these. If so, carry on. As long as flake8 is happy, I'm happy.

@vimalloc
Copy link
Contributor Author

Thx for the feedback. I'll make any changes tomorrow and get them pushed to you. Cheers.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage decreased (-1.6%) to 98.379% when pulling 0550fa3 on vimalloc:master into 5caa1af on jpadilla:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.6%) to 98.379% when pulling 0550fa3 on vimalloc:master into 5caa1af on jpadilla:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 2a09da2 on vimalloc:master into 5caa1af on jpadilla:master.

@mark-adams
Copy link
Contributor

One last thing... do you think you could add a line to the CHANGELOG about this?

@vimalloc
Copy link
Contributor Author

Sure. Just a sec

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 439f9a3 on vimalloc:master into 5caa1af on jpadilla:master.

@mark-adams mark-adams merged commit 7dd3d4a into jpadilla:master Dec 1, 2016
@mark-adams
Copy link
Contributor

Thanks for contributing @vimalloc! 👍

@jpadilla
Copy link
Owner

jpadilla commented Dec 1, 2016

@vimalloc @mark-adams thanks! 🎉

@jpadilla
Copy link
Owner

jpadilla commented Dec 1, 2016

@mark-adams there's nothing else pressing, should we release v1.4.3 with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants