Skip to content

Commit 2cf7c71

Browse files
committed
der: add DerCow, change OwnedToRef trait
1 parent c04d087 commit 2cf7c71

8 files changed

Lines changed: 27 additions & 34 deletions

File tree

der/src/asn1/bit_string.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ mod allocating {
445445
type Borrowed = BitStringRef<'a>;
446446
fn owned_to_ref(&'a self) -> Self::Borrowed {
447447
// Ensured to parse successfully in constructor
448-
BitStringRef::new(self.unused_bits, &self.inner)
449-
.expect("invalid BIT STRING")
448+
BitStringRef::new(self.unused_bits, &self.inner).expect("invalid BIT STRING")
450449
}
451450
}
452451
}

der/src/asn1/ia5_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ mod allocation {
166166

167167
impl<'a> OwnedToRef<'a> for Ia5String {
168168
type Borrowed = Ia5StringRef<'a>;
169-
fn owned_to_ref(&self) -> Self::Borrowed {
169+
fn owned_to_ref(&'a self) -> Self::Borrowed {
170170
Ia5StringRef {
171171
inner: self.inner.owned_to_ref(),
172172
}

der/src/asn1/integer/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ mod allocating {
296296

297297
impl<'a> OwnedToRef<'a> for Int {
298298
type Borrowed = IntRef<'a>;
299-
fn owned_to_ref(&self) -> Self::Borrowed {
299+
fn owned_to_ref(&'a self) -> Self::Borrowed {
300300
let inner = self.inner.owned_to_ref();
301301

302302
IntRef { inner }

der/src/asn1/integer/uint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ mod allocating {
267267

268268
impl<'a> OwnedToRef<'a> for Uint {
269269
type Borrowed = UintRef<'a>;
270-
fn owned_to_ref(&self) -> Self::Borrowed {
270+
fn owned_to_ref(&'a self) -> Self::Borrowed {
271271
let inner = self.inner.owned_to_ref();
272272

273273
UintRef { inner }

der/src/asn1/octet_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! ASN.1 `OCTET STRING` support.
22
33
use crate::{
4-
asn1::AnyRef, ord::OrdIsValueOrd, referenced::RefToOwned, BytesRef, Decode, DecodeValue, EncodeValue, Error, ErrorKind, FixedTag, Header, Length, Reader, Tag, Writer
4+
BytesRef, Decode, DecodeValue, EncodeValue, Error, ErrorKind, FixedTag, Header, Length, Reader,
5+
Tag, Writer, asn1::AnyRef, ord::OrdIsValueOrd, referenced::RefToOwned,
56
};
67

7-
88
/// ASN.1 `OCTET STRING` type: borrowed form.
99
///
1010
/// Octet strings represent contiguous sequences of octets, a.k.a. bytes.

der/src/asn1/printable_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ mod allocation {
221221

222222
impl<'a> OwnedToRef<'a> for PrintableString {
223223
type Borrowed = PrintableStringRef<'a>;
224-
fn owned_to_ref(&self) -> Self::Borrowed {
224+
fn owned_to_ref(&'a self) -> Self::Borrowed {
225225
PrintableStringRef {
226226
inner: self.inner.owned_to_ref(),
227227
}

der/src/referenced.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! A module for working with referenced data.
22
3-
43
use crate::FixedTag;
54

65
/// A trait for borrowing data from an owned struct
@@ -27,7 +26,7 @@ pub trait OwnedToRef<'a> {
2726
/// own the content.
2827
pub trait RefToOwned<'a> {
2928
/// The resulting type after obtaining ownership.
30-
type Owned: OwnedToRef<'a ,Borrowed = Self>
29+
type Owned: OwnedToRef<'a, Borrowed = Self>
3130
where
3231
Self: 'a;
3332

@@ -39,8 +38,7 @@ impl<'a, T> OwnedToRef<'a> for Option<T>
3938
where
4039
T: OwnedToRef<'a>,
4140
{
42-
type Borrowed
43-
= Option<T::Borrowed>;
41+
type Borrowed = Option<T::Borrowed>;
4442

4543
fn owned_to_ref(&'a self) -> Self::Borrowed {
4644
self.as_ref().map(|o| o.owned_to_ref())
@@ -102,25 +100,23 @@ where
102100
const TAG: crate::Tag = B::TAG;
103101
}
104102

105-
impl<'a, B> PartialEq for DerCow<'a, B>
106-
where
107-
B: RefToOwned<'a> + Sized + PartialEq,
108-
<B as RefToOwned<'a>>::Owned: PartialEq + OwnedToRef<'a>,
109-
{
110-
fn eq(&self, other: &Self) -> bool {
111-
match (self, other) {
112-
(Self::Borrowed(l0), Self::Borrowed(r0)) => l0 == r0,
113-
(Self::Owned(l0), Self::Owned(r0)) => l0 == r0,
114-
(Self::Owned(l0), Self::Borrowed(r0)) => {
115-
let l1 = l0.owned_to_ref();
116-
&l1 == *r0
117-
},
118-
_ => false,
119-
}
120-
}
121-
}
122-
123-
103+
// impl<'a, B> PartialEq for DerCow<'a, B>
104+
// where
105+
// B: RefToOwned<'a> + Sized + PartialEq,
106+
// <B as RefToOwned<'a>>::Owned: PartialEq + OwnedToRef<'a>,
107+
// {
108+
// fn eq(&self, other: &Self) -> bool {
109+
// match (self, other) {
110+
// (Self::Borrowed(l0), Self::Borrowed(r0)) => l0 == r0,
111+
// (Self::Owned(l0), Self::Owned(r0)) => l0 == r0,
112+
// (Self::Owned(l0), Self::Borrowed(r0)) => {
113+
// let l1 = l0.owned_to_ref();
114+
// *r0 == &l1
115+
// }
116+
// _ => false,
117+
// }
118+
// }
119+
// }
124120

125121
// impl<'a, B> Deref for DerCow<'a, B>
126122
// where

x509-cert/src/certificate.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::{AlgorithmIdentifier, SubjectPublicKeyInfo};
44
use crate::{ext, name::Name, serial_number::SerialNumber, time::Validity};
55
use alloc::vec::Vec;
66
use const_oid::AssociatedOid;
7+
use core::{cmp::Ordering, fmt::Debug};
78
use der::asn1::BitStringRef;
89
use der::referenced::DerCow;
9-
use core::{cmp::Ordering, fmt::Debug};
1010
use der::{Decode, Enumerated, ErrorKind, Sequence, Tag, ValueOrd, asn1::BitString};
1111

1212
#[cfg(feature = "pem")]
@@ -170,8 +170,6 @@ pub struct TbsCertificateInner<P: Profile = Rfc5280> {
170170
pub(crate) extensions: Option<ext::Extensions>,
171171
}
172172

173-
174-
175173
#[derive(Clone, Debug, Eq, PartialEq, Sequence, ValueOrd)]
176174
#[allow(missing_docs)]
177175
pub struct TbsCertificateInnerCow<'a, P: Profile = Rfc5280> {

0 commit comments

Comments
 (0)