Skip to content

Commit 82c433e

Browse files
committed
webpki-ccadb: support placeholder absent trust bits
panic if this is seen with other trust bits, as that doesn't make any sense.
1 parent 5b76d00 commit 82c433e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

webpki-ccadb/src/lib.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,18 @@ impl CertificateMetadata {
220220
/// Returns the set of trust bits expressed for this certificate. Panics if the raw
221221
/// trust bits are invalid/unknown.
222222
fn trust_bits(&self) -> HashSet<TrustBits> {
223-
self.trust_bits.split(';').map(TrustBits::from).collect()
223+
let bits = self
224+
.trust_bits
225+
.split(';')
226+
.map(TrustBits::from)
227+
.collect::<HashSet<_>>();
228+
if bits.contains(&TrustBits::AllTrustBitsTurnedOff) && bits.len() > 1 {
229+
panic!(
230+
"unexpected trust bits: AllTrustBitsTurnedOff \
231+
is mutually exclusive (found {bits:?})"
232+
);
233+
}
234+
bits
224235
}
225236

226237
/// Returns the PEM metadata for the certificate with the leading/trailing single quotes
@@ -252,6 +263,8 @@ pub enum TrustBits {
252263
Email,
253264
/// certificate is trusted for code signing
254265
Code,
266+
/// certificate is not trusted for anything
267+
AllTrustBitsTurnedOff,
255268
}
256269

257270
impl From<&str> for TrustBits {
@@ -260,6 +273,7 @@ impl From<&str> for TrustBits {
260273
"Websites" => TrustBits::Websites,
261274
"Email" => TrustBits::Email,
262275
"Code" => TrustBits::Code,
276+
"All Trust Bits Turned Off" => TrustBits::AllTrustBitsTurnedOff,
263277
val => panic!("unknown trust bit: {val:?}"),
264278
}
265279
}

0 commit comments

Comments
 (0)