Skip to content

Commit

Permalink
cleaned up some repetitive code
Browse files Browse the repository at this point in the history
  • Loading branch information
bhesh committed Oct 25, 2023
1 parent 145c704 commit 8a8424b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
29 changes: 5 additions & 24 deletions x509-ocsp/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ pub struct RevokedInfo {
pub revocation_reason: Option<CrlReason>,
}

impl From<RevokedCert> for RevokedInfo {
fn from(rc: RevokedCert) -> Self {
impl From<&RevokedCert> for RevokedInfo {
fn from(rc: &RevokedCert) -> Self {
Self {
revocation_time: match rc.revocation_date {
Time::UtcTime(t) => GeneralizedTime::from_date_time(t.to_date_time()),
Expand All @@ -233,28 +233,9 @@ impl From<RevokedCert> for RevokedInfo {
}
}

impl From<&RevokedCert> for RevokedInfo {
fn from(rc: &RevokedCert) -> Self {
Self {
revocation_time: match rc.revocation_date {
Time::UtcTime(t) => GeneralizedTime::from_date_time(t.to_date_time()),
Time::GeneralTime(t) => t,
},
revocation_reason: if let Some(extensions) = &rc.crl_entry_extensions {
let mut filter = extensions
.iter()
.filter(|ext| ext.extn_id == CrlReason::OID);
match filter.next() {
None => None,
Some(ext) => match CrlReason::from_der(ext.extn_value.as_bytes()) {
Ok(reason) => Some(reason),
Err(_) => None,
},
}
} else {
None
},
}
impl From<RevokedCert> for RevokedInfo {
fn from(rc: RevokedCert) -> Self {
Self::from(&rc)
}
}

Expand Down
9 changes: 8 additions & 1 deletion x509-ocsp/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ impl Nonce {
Ok(Self(OctetString::new(bytes)?))
}

/// Creates a Nonce object given a random generator and a length
/// Creates a Nonce object given a random generator and a length.
///
/// A proposed but not (yet) accepted RFC [RFC 8954] wants to limit nonces. RFC 6960 has no
/// mention of a minimum or maximum length.
///
/// ```text
/// Nonce ::= OCTET STRING(SIZE(1..32))
/// ```
#[cfg(feature = "rand_core")]
pub fn generate<R: CryptoRngCore>(rng: &mut R, length: usize) -> Result<Self, der::Error> {
let mut bytes = Vec::with_capacity(length);
Expand Down

0 comments on commit 8a8424b

Please sign in to comment.