rust: bssl-tls: convenient certificate verification outcomes For simple cases in which the decision can be made immediately and synchronously, the new types in this patch allows the verifying party to avoid making their own verifying task types. Signed-off-by: Xiangfei Ding <xfding@google.com> Change-Id: I70294b0adf2c814dee7c5498f1f2ec226a6a6964 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/97267 Reviewed-by: Rudolf Polzer <rpolzer@google.com>
diff --git a/rust/bssl-tls/src/credentials.rs b/rust/bssl-tls/src/credentials.rs index 5c93bd0..76aa523 100644 --- a/rust/bssl-tls/src/credentials.rs +++ b/rust/bssl-tls/src/credentials.rs
@@ -619,6 +619,9 @@ /// /// It is recommended to avoid panicking in the trait implementation. /// A panic in this callback will lead to abort. +/// +/// As a return value, one could use [`VerifyCertificateAccepted`] or [`VerifyCertificateRejected`] +/// to deliver the results if the decision can be made immediately and synchronously. pub trait VerifyCertificate: Send + Sync { /// Decide whether a certificate chain is acceptable. /// @@ -650,6 +653,26 @@ Reject(Option<AlertDescription>), } +/// Certificate verifier accepts the offered certificates. +#[derive(Debug, Clone, Copy)] +pub struct VerifyCertificateAccepted; + +impl VerifyCertificateTask for VerifyCertificateAccepted { + fn complete(&mut self, _: Option<&mut Context<'_>>) -> VerifyResult { + VerifyResult::Accept + } +} + +/// Certificate verifier rejects the offered certificates. +#[derive(Debug, Clone, Copy)] +pub struct VerifyCertificateRejected(pub Option<AlertDescription>); + +impl VerifyCertificateTask for VerifyCertificateRejected { + fn complete(&mut self, _: Option<&mut Context<'_>>) -> VerifyResult { + VerifyResult::Reject(self.0) + } +} + /// Asynchronous custom certificate verification. /// /// This is the `async` analogue of [`VerifyCertificate`].