Skip to content

Conversation

alex
Copy link
Member

@alex alex commented Oct 29, 2015

…are on different curves

Copy link
Member

Choose a reason for hiding this comment

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

This fails py3's pep8 with E721 do not compare types, use 'isinstance()'

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I don't know what that means. What's teh right way to check if two curves rae equivilant.

Copy link

Choose a reason for hiding this comment

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

I know this was already fixed another way, but for future reference you could do it as a type check by saying:

    if not isinstance(peer_public_key.curve, type(self.curve)):

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wonder if we should just have an __eq__ on curves.

On Thu, Oct 29, 2015 at 9:37 AM, Ron Frederick notifications@github.com
wrote:

In src/cryptography/hazmat/backends/openssl/ec.py
#2455 (comment):

@@ -182,6 +182,11 @@ def exchange(self, algorithm, peer_public_key):
_Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
)

  •    if type(peer_public_key.curve) is not type(self.curve):
    

I know this was already fixed another way, but for future reference you
could do it as a type check by saying:

if not isinstance(peer_public_key.curve, type(self.curve)):


Reply to this email directly or view it on GitHub
https://github.com/pyca/cryptography/pull/2455/files#r43384597.

"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084

Copy link

Choose a reason for hiding this comment

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

Yeah, that would probably look cleaner. When writing an eq for classes that have other members to compare, part of it is usually involves an isinstance() check of this sort before comparing the members. In this case, if these classes have no other state, the isinstance() by itself could be enough.

That said, is there any reason these are classes instead of instances that could just be compared directly with "is"? Is it just for consistency with other parts of the API where arguments might be passed when constructing such an object?

One possibility here would be to make these singletons, so you still construct them from classes, but the constructor always returns the same instance.

@codecov-io
Copy link

Current coverage is 99.98%

Merging #2455 into master will not affect coverage as of 70b5003

@@            master   #2455   diff @@
======================================
  Files          122     122       
  Stmts        12720   12725     +5
  Branches      1399    1401     +2
  Methods          0       0       
======================================
+ Hit          12718   12723     +5
  Partial          2       2       
  Missed           0       0       

Review entire Coverage Diff as of 70b5003

Powered by Codecov. Updated on successful CI builds.

reaperhulk added a commit that referenced this pull request Oct 29, 2015
Error cleanly if the public and private keys to an ECDH key exchange …
@reaperhulk reaperhulk merged commit a0cb27c into pyca:master Oct 29, 2015
@alex alex deleted the different-curves branch October 29, 2015 12:27
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e245345 on alex:different-curves into ** on pyca:master**.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

5 participants