Skip to content

Commit

Permalink
validation: add Rust-side certificate validation helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuo-cpp committed Oct 24, 2023
1 parent 724697f commit 49dd508
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/rust/cryptography-x509-validation/src/certificate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is dual licensed under the terms of the Apache License, Version
// 2.0, and the BSD License. See the LICENSE file in the root of this repository
// for complete details.

//! Validation-specific certificate functionality.
use cryptography_x509::certificate::Certificate;

use crate::ops::CryptoOps;

pub(crate) fn cert_is_self_issued(cert: &Certificate<'_>) -> bool {
cert.issuer() == cert.subject()
}

pub(crate) fn cert_is_self_signed<B: CryptoOps>(cert: &Certificate<'_>, ops: &B) -> bool {
match ops.public_key(cert) {
Ok(pk) => cert_is_self_issued(cert) && ops.verify_signed_by(cert, pk).is_ok(),
Err(_) => false,
}
}
1 change: 1 addition & 0 deletions src/rust/cryptography-x509-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![forbid(unsafe_code)]
#![deny(rust_2018_idioms, clippy::undocumented_unsafe_blocks)]

pub mod certificate;
pub mod ops;
pub mod policy;
pub mod trust_store;
Expand Down

0 comments on commit 49dd508

Please sign in to comment.