Skip to content

Commit 60001a7

Browse files
feat!: Change Verifier to hold a Cow<'a, CertificateTrustPolicy rather than a reference (#1238)
(Supports upcoming work I'm planning around configuring trust for reading CAWG identity assertions.)
1 parent 89bafcc commit 60001a7

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

sdk/src/cose_validator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// specific language governing permissions and limitations under
1212
// each license.
1313

14-
use std::io::Write;
14+
use std::{borrow::Cow, io::Write};
1515

1616
use async_generic::async_generic;
1717
use x509_parser::{num_bigint::BigUint, prelude::*};
@@ -56,8 +56,8 @@ pub(crate) fn verify_cose(
5656
) -> Result<CertificateInfo> {
5757
let verifier = if cert_check {
5858
match get_settings_value::<bool>("verify.verify_trust") {
59-
Ok(true) => Verifier::VerifyTrustPolicy(ctp),
60-
_ => Verifier::VerifyCertificateProfileOnly(ctp),
59+
Ok(true) => Verifier::VerifyTrustPolicy(Cow::Borrowed(ctp)),
60+
_ => Verifier::VerifyCertificateProfileOnly(Cow::Borrowed(ctp)),
6161
}
6262
} else {
6363
Verifier::IgnoreProfileAndTrustPolicy

sdk/src/crypto/cose/certificate_trust_policy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum TrustAnchorType {
4141
/// A `CertificateTrustPolicy` is configured with information about trust
4242
/// anchors, privately-accepted end-entity certificates, and allowed EKUs. It
4343
/// can be used to evaluate a signing certificate against those policies.
44-
#[derive(Debug)]
44+
#[derive(Clone, Debug)]
4545
pub struct CertificateTrustPolicy {
4646
/// Trust anchors (root X.509 certificates) in DER format.
4747
trust_anchor_ders: Vec<Vec<u8>>,

sdk/src/crypto/cose/verifier.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// specific language governing permissions and limitations under
1212
// each license.
1313

14-
use std::io::Write;
14+
use std::{borrow::Cow, io::Write};
1515

1616
use asn1_rs::FromDer;
1717
use async_generic::async_generic;
@@ -48,12 +48,12 @@ pub enum Verifier<'a> {
4848
/// Use a [`CertificateTrustPolicy`] to validate the signing certificate's
4949
/// profile against C2PA requirements _and_ validate the certificate's
5050
/// membership against a trust configuration.
51-
VerifyTrustPolicy(&'a CertificateTrustPolicy),
51+
VerifyTrustPolicy(Cow<'a, CertificateTrustPolicy>),
5252

5353
/// Validate the certificate's membership against a trust configuration, but
5454
/// do not against any trust list. The [`CertificateTrustPolicy`] is used to
5555
/// enforce EKU (Extended Key Usage) policy only.
56-
VerifyCertificateProfileOnly(&'a CertificateTrustPolicy),
56+
VerifyCertificateProfileOnly(Cow<'a, CertificateTrustPolicy>),
5757

5858
/// Ignore both trust configuration and trust lists.
5959
IgnoreProfileAndTrustPolicy,
@@ -184,8 +184,8 @@ impl Verifier<'_> {
184184
validation_log: &mut StatusTracker,
185185
) -> Result<(), CoseError> {
186186
let ctp = match self {
187-
Self::VerifyTrustPolicy(ctp) => *ctp,
188-
Self::VerifyCertificateProfileOnly(ctp) => *ctp,
187+
Self::VerifyTrustPolicy(ref ctp) => ctp,
188+
Self::VerifyCertificateProfileOnly(ref ctp) => ctp,
189189
Self::IgnoreProfileAndTrustPolicy => {
190190
return Ok(());
191191
}
@@ -196,7 +196,7 @@ impl Verifier<'_> {
196196

197197
Ok(check_end_entity_certificate_profile(
198198
end_entity_cert_der,
199-
ctp,
199+
ctp.as_ref(),
200200
validation_log,
201201
tst_info,
202202
)?)
@@ -213,9 +213,9 @@ impl Verifier<'_> {
213213
// IMPORTANT: This function assumes that verify_profile has already been called.
214214

215215
let ctp = match self {
216-
Self::VerifyTrustPolicy(ctp) => *ctp,
216+
Self::VerifyTrustPolicy(ref ctp) => ctp,
217217

218-
Self::VerifyCertificateProfileOnly(_ctp) => {
218+
Self::VerifyCertificateProfileOnly(ref _ctp) => {
219219
return Ok(TrustAnchorType::NoCheck);
220220
}
221221

0 commit comments

Comments
 (0)