|
1 | 1 | import calendar |
2 | 2 | import datetime |
3 | | - |
4 | 3 | from base64 import b16encode |
| 4 | +import functools |
5 | 5 | from functools import partial |
6 | | -from operator import __eq__, __ne__, __lt__, __le__, __gt__, __ge__ |
7 | 6 |
|
8 | 7 | from cryptography import utils, x509 |
9 | 8 | from cryptography.hazmat.primitives.asymmetric import dsa, rsa |
@@ -528,6 +527,7 @@ def get_elliptic_curve(name): |
528 | 527 | raise ValueError("unknown curve name", name) |
529 | 528 |
|
530 | 529 |
|
| 530 | +@functools.total_ordering |
531 | 531 | class X509Name: |
532 | 532 | """ |
533 | 533 | An X.509 Distinguished Name. |
@@ -642,23 +642,17 @@ def __getattr__(self, name): |
642 | 642 | _lib.OPENSSL_free(result_buffer[0]) |
643 | 643 | return result |
644 | 644 |
|
645 | | - def _cmp(op): |
646 | | - def f(self, other): |
647 | | - if not isinstance(other, X509Name): |
648 | | - return NotImplemented |
649 | | - result = _lib.X509_NAME_cmp(self._name, other._name) |
650 | | - return op(result, 0) |
651 | | - |
652 | | - return f |
| 645 | + def __eq__(self, other): |
| 646 | + if not isinstance(other, X509Name): |
| 647 | + return NotImplemented |
653 | 648 |
|
654 | | - __eq__ = _cmp(__eq__) |
655 | | - __ne__ = _cmp(__ne__) |
| 649 | + return _lib.X509_NAME_cmp(self._name, other._name) == 0 |
656 | 650 |
|
657 | | - __lt__ = _cmp(__lt__) |
658 | | - __le__ = _cmp(__le__) |
| 651 | + def __lt__(self, other): |
| 652 | + if not isinstance(other, X509Name): |
| 653 | + return NotImplemented |
659 | 654 |
|
660 | | - __gt__ = _cmp(__gt__) |
661 | | - __ge__ = _cmp(__ge__) |
| 655 | + return _lib.X509_NAME_cmp(self._name, other._name) < 0 |
662 | 656 |
|
663 | 657 | def __repr__(self): |
664 | 658 | """ |
|
0 commit comments