|
10 | 10 | use cfg_if::cfg_if; |
11 | 11 | use foreign_types::{ForeignType, ForeignTypeRef}; |
12 | 12 | use libc::{c_int, c_long}; |
| 13 | +use std::cmp; |
13 | 14 | use std::error::Error; |
14 | 15 | use std::ffi::{CStr, CString}; |
15 | 16 | use std::fmt; |
@@ -600,6 +601,29 @@ impl ToOwned for X509Ref { |
600 | 601 | } |
601 | 602 | } |
602 | 603 |
|
| 604 | +impl Ord for X509Ref { |
| 605 | + fn cmp(&self, other: &Self) -> cmp::Ordering { |
| 606 | + // X509_cmp returns a number <0 for less than, 0 for equal and >0 for greater than. |
| 607 | + // It can't fail if both pointers are valid, which we know is true. |
| 608 | + let cmp = unsafe { ffi::X509_cmp(self.as_ptr(), other.as_ptr()) }; |
| 609 | + cmp.cmp(&0) |
| 610 | + } |
| 611 | +} |
| 612 | + |
| 613 | +impl PartialOrd for X509Ref { |
| 614 | + fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { |
| 615 | + Some(self.cmp(other)) |
| 616 | + } |
| 617 | +} |
| 618 | + |
| 619 | +impl PartialEq for X509Ref { |
| 620 | + fn eq(&self, other: &Self) -> bool { |
| 621 | + self.cmp(other).is_eq() |
| 622 | + } |
| 623 | +} |
| 624 | + |
| 625 | +impl Eq for X509Ref {} |
| 626 | + |
603 | 627 | impl X509 { |
604 | 628 | /// Returns a new builder. |
605 | 629 | pub fn builder() -> Result<X509Builder, ErrorStack> { |
@@ -700,6 +724,26 @@ impl Stackable for X509 { |
700 | 724 | type StackType = ffi::stack_st_X509; |
701 | 725 | } |
702 | 726 |
|
| 727 | +impl Ord for X509 { |
| 728 | + fn cmp(&self, other: &Self) -> cmp::Ordering { |
| 729 | + X509Ref::cmp(self, other) |
| 730 | + } |
| 731 | +} |
| 732 | + |
| 733 | +impl PartialOrd for X509 { |
| 734 | + fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { |
| 735 | + X509Ref::partial_cmp(self, other) |
| 736 | + } |
| 737 | +} |
| 738 | + |
| 739 | +impl PartialEq for X509 { |
| 740 | + fn eq(&self, other: &Self) -> bool { |
| 741 | + X509Ref::eq(self, other) |
| 742 | + } |
| 743 | +} |
| 744 | + |
| 745 | +impl Eq for X509 {} |
| 746 | + |
703 | 747 | /// A context object required to construct certain `X509` extension values. |
704 | 748 | pub struct X509v3Context<'a>(ffi::X509V3_CTX, PhantomData<(&'a X509Ref, &'a ConfRef)>); |
705 | 749 |
|
|
0 commit comments