Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

der, spki: rename to_owned method #835

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions der/src/asn1/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ mod allocating {

impl<'a> RefToOwned<'a> for AnyRef<'a> {
type Owned = Any;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
Any {
tag: self.tag(),
value: BytesOwned::from(self.value),
Expand All @@ -287,15 +287,15 @@ mod allocating {

impl OwnedToRef for Any {
type Borrowed<'a> = AnyRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
self.into()
}
}

impl Any {
/// Is this value an ASN.1 `NULL` value?
pub fn is_null(&self) -> bool {
self.to_ref() == AnyRef::NULL
self.owned_to_ref() == AnyRef::NULL
}
}
}
4 changes: 2 additions & 2 deletions der/src/asn1/bit_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ mod allocating {

impl<'a> RefToOwned<'a> for BitStringRef<'a> {
type Owned = BitString;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
BitString {
unused_bits: self.unused_bits,
bit_length: self.bit_length,
Expand All @@ -390,7 +390,7 @@ mod allocating {

impl OwnedToRef for BitString {
type Borrowed<'a> = BitStringRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
self.into()
}
}
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/ia5_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ mod allocation {

impl<'a> RefToOwned<'a> for Ia5StringRef<'a> {
type Owned = Ia5String;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
Ia5String {
inner: self.inner.to_owned(),
inner: self.inner.ref_to_owned(),
}
}
}

impl OwnedToRef for Ia5String {
type Borrowed<'a> = Ia5StringRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
Ia5StringRef {
inner: self.inner.to_ref(),
inner: self.inner.owned_to_ref(),
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions der/src/asn1/integer/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,17 @@ mod allocating {

impl<'a> RefToOwned<'a> for IntRef<'a> {
type Owned = Int;
fn to_owned(&self) -> Self::Owned {
let inner = self.inner.to_owned();
fn ref_to_owned(&self) -> Self::Owned {
let inner = self.inner.ref_to_owned();

Int { inner }
}
}

impl OwnedToRef for Int {
type Borrowed<'a> = IntRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
let inner = self.inner.to_ref();
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
let inner = self.inner.owned_to_ref();

IntRef { inner }
}
Expand Down Expand Up @@ -384,17 +384,17 @@ mod allocating {

impl<'a> RefToOwned<'a> for UintRef<'a> {
type Owned = Uint;
fn to_owned(&self) -> Self::Owned {
let inner = self.inner.to_owned();
fn ref_to_owned(&self) -> Self::Owned {
let inner = self.inner.ref_to_owned();

Uint { inner }
}
}

impl OwnedToRef for Uint {
type Borrowed<'a> = UintRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
let inner = self.inner.to_ref();
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
let inner = self.inner.owned_to_ref();

UintRef { inner }
}
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/printable_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,18 @@ mod allocation {

impl<'a> RefToOwned<'a> for PrintableStringRef<'a> {
type Owned = PrintableString;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
PrintableString {
inner: self.inner.to_owned(),
inner: self.inner.ref_to_owned(),
}
}
}

impl OwnedToRef for PrintableString {
type Borrowed<'a> = PrintableStringRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
PrintableStringRef {
inner: self.inner.to_ref(),
inner: self.inner.owned_to_ref(),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/teletex_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ mod allocation {

impl<'a> RefToOwned<'a> for TeletexStringRef<'a> {
type Owned = TeletexString;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
TeletexString {
inner: self.inner.to_owned(),
inner: self.inner.ref_to_owned(),
}
}
}

impl OwnedToRef for TeletexString {
type Borrowed<'a> = TeletexStringRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
TeletexStringRef {
inner: self.inner.to_ref(),
inner: self.inner.owned_to_ref(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion der/src/bytes_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl From<StrRef<'_>> for BytesOwned {

impl OwnedToRef for BytesOwned {
type Borrowed<'a> = BytesRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
BytesRef {
length: self.length,
inner: self.inner.as_ref(),
Expand Down
2 changes: 1 addition & 1 deletion der/src/bytes_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod allocating {

impl<'a> RefToOwned<'a> for BytesRef<'a> {
type Owned = BytesOwned;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
BytesOwned::from(*self)
}
}
Expand Down
12 changes: 6 additions & 6 deletions der/src/referenced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub trait OwnedToRef {
Self: 'a;

/// Creates a new object referencing back to the self for storage
fn to_ref(&self) -> Self::Borrowed<'_>;
fn owned_to_ref(&self) -> Self::Borrowed<'_>;
}

/// A trait for cloning a referenced structure and getting owned objects
Expand All @@ -21,7 +21,7 @@ pub trait RefToOwned<'a> {
Self: 'a;

/// Creates a new object taking ownership of the data
fn to_owned(&self) -> Self::Owned;
fn ref_to_owned(&self) -> Self::Owned;
}

impl<T> OwnedToRef for Option<T>
tarcieri marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -30,8 +30,8 @@ where
{
type Borrowed<'a> = Option<T::Borrowed<'a>> where T: 'a;

fn to_ref(&self) -> Self::Borrowed<'_> {
self.as_ref().map(|o| o.to_ref())
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
self.as_ref().map(|o| o.owned_to_ref())
}
}

Expand All @@ -41,7 +41,7 @@ where
T::Owned: OwnedToRef,
{
type Owned = Option<T::Owned>;
fn to_owned(&self) -> Self::Owned {
self.as_ref().map(|o| o.to_owned())
fn ref_to_owned(&self) -> Self::Owned {
self.as_ref().map(|o| o.ref_to_owned())
}
}
2 changes: 1 addition & 1 deletion der/src/str_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl From<StrRef<'_>> for StrOwned {

impl OwnedToRef for StrOwned {
type Borrowed<'a> = StrRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
StrRef {
length: self.length,
inner: self.inner.as_ref(),
Expand Down
2 changes: 1 addition & 1 deletion der/src/str_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod allocating {

impl<'a> RefToOwned<'a> for StrRef<'a> {
type Owned = StrOwned;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
StrOwned::from(*self)
}
}
Expand Down
8 changes: 4 additions & 4 deletions spki/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@ mod allocating {

impl<'a> RefToOwned<'a> for AlgorithmIdentifierRef<'a> {
type Owned = AlgorithmIdentifierOwned;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
AlgorithmIdentifier {
oid: self.oid,
parameters: self.parameters.to_owned(),
parameters: self.parameters.ref_to_owned(),
}
}
}

impl OwnedToRef for AlgorithmIdentifierOwned {
type Borrowed<'a> = AlgorithmIdentifierRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
AlgorithmIdentifier {
oid: self.oid,
parameters: self.parameters.to_ref(),
parameters: self.parameters.owned_to_ref(),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions spki/src/spki.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ mod allocating {

impl<'a> RefToOwned<'a> for SubjectPublicKeyInfoRef<'a> {
type Owned = SubjectPublicKeyInfoOwned;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
SubjectPublicKeyInfo {
algorithm: self.algorithm.to_owned(),
subject_public_key: self.subject_public_key.to_owned(),
algorithm: self.algorithm.ref_to_owned(),
subject_public_key: self.subject_public_key.ref_to_owned(),
}
}
}

impl OwnedToRef for SubjectPublicKeyInfoOwned {
type Borrowed<'a> = SubjectPublicKeyInfoRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
SubjectPublicKeyInfo {
algorithm: self.algorithm.to_ref(),
subject_public_key: self.subject_public_key.to_ref(),
algorithm: self.algorithm.owned_to_ref(),
subject_public_key: self.subject_public_key.owned_to_ref(),
}
}
}
Expand Down