Skip to content

Commit

Permalink
Use dedicated exception class when ECPointFormat is wrong
Browse files Browse the repository at this point in the history
This makes it easier to catch these specific types of errors if the
user wants to, and makes it clearer what is happening.
  • Loading branch information
rot42 authored and dkg committed Aug 1, 2019
1 parent 941dfdc commit 8cc340d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pgpy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
__all__ = ('PGPError',
'PGPEncryptionError',
'PGPDecryptionError',
'PGPIncompatibleECPointFormat',
'PGPOpenSSLCipherNotSupported',
'PGPInsecureCipher',
'WontImplementError',)
Expand All @@ -24,6 +25,11 @@ class PGPDecryptionError(Exception):
pass


class PGPIncompatibleECPointFormat(Exception):
"""Raised when the point format is incompatible with the elliptic curve"""
pass


class PGPOpenSSLCipherNotSupported(Exception):
"""Raised when OpenSSL does not support the requested cipher"""
pass
Expand Down
6 changes: 3 additions & 3 deletions pgpy/packet/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

from ..errors import PGPDecryptionError
from ..errors import PGPError
from ..errors import PGPIncompatibleECPointFormat

from ..symenc import _decrypt
from ..symenc import _encrypt
Expand Down Expand Up @@ -565,8 +566,7 @@ def parse(self, packet):

self.p = ECPoint(packet)
if self.p.format != ECPointFormat.Standard:
raise NotImplementedError("Expected: standard Elliptic curve point format (0x40). Got: 0x{:02X}".format(self.p.format))

raise PGPIncompatibleECPointFormat("Only Standard format is valid for ECDSA")


class ECDHPub(PubKey):
Expand Down Expand Up @@ -637,7 +637,7 @@ def parse(self, packet):

self.p = ECPoint(packet)
if self.p.format != ECPointFormat.Standard:
raise NotImplementedError("Expected: standard Elliptic curve point format (0x40). Got: 0x{:02X}".format(self.p.format))
raise PGPIncompatibleECPointFormat("Only curves using Standard format are currently supported for ECDH")
self.kdf.parse(packet)


Expand Down

0 comments on commit 8cc340d

Please sign in to comment.