Skip to content
Merged
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
20 changes: 20 additions & 0 deletions spki/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ impl<'a> AlgorithmIdentifier<'a> {
pub fn parameters_oid(&self) -> Result<ObjectIdentifier> {
Ok(ObjectIdentifier::try_from(self.parameters_any()?)?)
}

/// Convert to a pair of [`ObjectIdentifier`]s.
///
/// This method is helpful for decomposing in match statements. Note in
/// particular that `NULL` parameters are treated the same as missing
/// parameters.
///
/// Returns an error if parameters are present but not an OID.
pub fn oids(&self) -> der::Result<(ObjectIdentifier, Option<ObjectIdentifier>)> {
Ok((
self.oid,
match self.parameters {
None => None,
Some(p) => match p {
Any::NULL => None,
_ => Some(p.oid()?),
},
},
Comment on lines +88 to +94
Copy link
Member

@tarcieri tarcieri Feb 23, 2022

Choose a reason for hiding this comment

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

Suggested change
match self.parameters {
None => None,
Some(p) => match p {
Any::NULL => None,
_ => Some(p.oid()?),
},
},
self.parameters.and_then(|p| match p {
Any::NULL => None,
_ => Some(p.oid()?),
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tarcieri This actually doesn't compile because it embeds the error handling in the function. I think my version is actually cleaner due to this.

))
}
}

impl<'a> Decodable<'a> for AlgorithmIdentifier<'a> {
Expand Down