Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 101a9ce

Browse files
committed
try excluding trace! calls to increase coverage
1 parent 4868889 commit 101a9ce

File tree

13 files changed

+123
-57
lines changed

13 files changed

+123
-57
lines changed

src/api/core/cacheable_cert.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ impl CacheableIdCert {
153153
))),
154154
)
155155
})?;
156+
#[cfg(not(tarpaulin_include))]
156157
trace!("Serial number: {}", serial_number);
158+
#[cfg(not(tarpaulin_include))]
157159
trace!("Not valid before: {}", &self.not_valid_before.to_string());
160+
#[cfg(not(tarpaulin_include))]
158161
trace!("Not valid after: {}", &self.not_valid_after.to_string());
162+
#[cfg(not(tarpaulin_include))]
159163
trace!(
160164
"Invalidated at: {}",
161165
&self
@@ -170,6 +174,7 @@ impl CacheableIdCert {
170174
.invalidated_at
171175
.map(|v| v.to_string())
172176
.unwrap_or("".to_string());
177+
#[cfg(not(tarpaulin_include))]
173178
trace!("Computed string: {}", string_to_check);
174179
verifying_key
175180
.verify_signature(

src/api/core/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ impl<S: Signature, T: PrivateKey<S>> Session<S, T> {
119119
Ok(())
120120
}
121121

122-
/// Retrieve encrypted private key material from the server. The serial_numbers, if provided,
122+
/// Retrieve encrypted private key material from the server. The `serial_numbers`, if provided,
123123
/// must match the serial numbers of ID-Certs that the client has uploaded key material for.
124-
/// If no serial_numbers are provided, the server will return all key material that the client
124+
/// If no `serial_numbers` are provided, the server will return all key material that the client
125125
/// has uploaded.
126126
pub async fn get_encrypted_pkm(
127127
&self,
@@ -269,6 +269,7 @@ impl HttpClient {
269269
request = request.body(json!({ "timestamp": time }).to_string());
270270
}
271271
let response = request.send().await;
272+
#[cfg(not(tarpaulin_include))]
272273
trace!("Got response: {:?}", response);
273274
let id_cert = HttpClient::handle_response::<CacheableIdCert>(response).await?;
274275
Ok(id_cert)

src/certs/capabilities/basic_constraints.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ impl TryFrom<Extension> for BasicConstraints {
165165
/// this property is critical, use the [Constrained] trait to verify the well-formedness of
166166
/// these resulting [BasicConstraints].
167167
fn try_from(value: Extension) -> Result<Self, Self::Error> {
168-
trace!("Converting Extension to BasicConstraints");
169-
trace!("Extension: {:#?}", value);
168+
#[cfg(not(tarpaulin_include))]
169+
trace!("Converting Extension to BasicConstraints");
170+
#[cfg(not(tarpaulin_include))]
171+
trace!("Extension: {:#?}", value);
170172
#[allow(unreachable_patterns)]
171173
if value.critical && !matches!(value.extn_id.to_string().as_str(), OID_BASIC_CONSTRAINTS) {
172174
// Error if we encounter a "critical" X.509 extension which we do not know of

src/certs/capabilities/key_usage.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::str::FromStr;
66

77
use der::asn1::{BitString, OctetString, SetOfVec};
88
use der::{Any, Decode, Encode, Tag, Tagged};
9+
use log::trace;
910
use spki::ObjectIdentifier;
1011
use x509_cert::attr::Attribute;
1112
use x509_cert::ext::Extension;
@@ -90,7 +91,8 @@ impl KeyUsages {
9091
/// ```
9192
pub fn from_bitstring(bitstring: BitString) -> Result<Self, ConversionError> {
9293
let mut byte_array = bitstring.raw_bytes().to_vec();
93-
log::trace!("[from_bitstring] BitString raw bytes: {:?}", byte_array);
94+
#[cfg(not(tarpaulin_include))]
95+
trace!("[from_bitstring] BitString raw bytes: {:?}", byte_array);
9496
let mut key_usages = Vec::new();
9597
if byte_array == [0] || byte_array.is_empty() {
9698
// TODO: PLEASE write a test for this. Is an empty byte array valid? Is a byte array with a single 0 valid, and does it mean that no KeyUsage is set? -bitfl0wer

src/certs/idcert.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use der::asn1::Uint;
66
use der::pem::LineEnding;
77
use der::{Decode, DecodePem, Encode, EncodePem};
8+
use log::trace;
89
use x509_cert::name::Name;
910
use x509_cert::time::Validity;
1011
use x509_cert::Certificate;
@@ -126,14 +127,19 @@ impl<S: Signature, P: PublicKey<S>> IdCert<S, P> {
126127
issuer: Name,
127128
validity: Validity,
128129
) -> Result<Self, ConversionError> {
129-
log::trace!("[IdCert::from_actor_csr()] creating actor certificate");
130+
#[cfg(not(tarpaulin_include))]
131+
trace!("[IdCert::from_actor_csr()] creating actor certificate");
130132
let signature_algorithm = signing_key.algorithm_identifier();
131-
log::trace!("[IdCert::from_actor_csr()] creating IdCertTbs");
132-
log::trace!("[IdCert::from_actor_csr()] Issuer: {}", issuer.to_string());
133-
log::trace!(
134-
"[IdCert::from_actor_csr()] Subject: {}",
135-
id_csr.inner_csr.subject.to_string()
136-
);
133+
#[cfg(not(tarpaulin_include))]
134+
{
135+
trace!("[IdCert::from_actor_csr()] creating IdCertTbs");
136+
trace!("[IdCert::from_actor_csr()] Issuer: {}", issuer.to_string());
137+
trace!(
138+
"[IdCert::from_actor_csr()] Subject: {}",
139+
id_csr.inner_csr.subject.to_string()
140+
);
141+
}
142+
137143
let id_cert_tbs = IdCertTbs::<S, P> {
138144
serial_number,
139145
signature_algorithm,
@@ -144,13 +150,15 @@ impl<S: Signature, P: PublicKey<S>> IdCert<S, P> {
144150
capabilities: id_csr.inner_csr.capabilities,
145151
s: std::marker::PhantomData,
146152
};
147-
log::trace!("[IdCert::from_actor_csr()] creating Signature");
153+
#[cfg(not(tarpaulin_include))]
154+
trace!("[IdCert::from_actor_csr()] creating Signature");
148155
let signature = signing_key.sign(&id_cert_tbs.clone().to_der()?);
149156
let cert = IdCert {
150157
id_cert_tbs,
151158
signature,
152159
};
153-
log::trace!(
160+
#[cfg(not(tarpaulin_include))]
161+
trace!(
154162
"[IdCert::from_actor_csr()] validating certificate with target {:?}",
155163
Some(Target::Actor)
156164
);
@@ -285,7 +293,8 @@ impl<S: Signature, P: PublicKey<S>> IdCert<S, P> {
285293
return Err(InvalidCert::InvalidValidity);
286294
}
287295
self.validate(Some(Target::Actor))?;
288-
log::trace!("[IdCert::full_verify_actor(&self)] verifying signature (actor certificate)");
296+
#[cfg(not(tarpaulin_include))]
297+
trace!("[IdCert::full_verify_actor(&self)] verifying signature (actor certificate)");
289298
let der = match self.id_cert_tbs.clone().to_der() {
290299
Ok(der) => der,
291300
Err(_) => {
@@ -332,9 +341,8 @@ impl<S: Signature, P: PublicKey<S>> IdCert<S, P> {
332341
)));
333342
}
334343
};
335-
log::trace!(
336-
"[IdCert::full_verify_home_server(&self)] verifying signature (self-signed IdCert)"
337-
);
344+
#[cfg(not(tarpaulin_include))]
345+
trace!("[IdCert::full_verify_home_server(&self)] verifying signature (self-signed IdCert)");
338346
Ok(self
339347
.id_cert_tbs
340348
.subject_public_key

src/certs/idcerttbs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ fn rdns_to_url(rdn_sequence: &RdnSequence) -> Result<url::Url, url::ParseError>
213213
url_str += ".";
214214
}
215215
let _ = url_str.pop();
216-
trace!(r#"Trying to parse string "{}" as url::Url..."#, url_str);
216+
#[cfg(not(tarpaulin_include))]
217+
trace!(r#"Trying to parse string "{}" as url::Url..."#, url_str);
217218
Url::parse(url_str.trim())
218219
}
219220

src/certs/idcsr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::marker::PhantomData;
66

77
use der::pem::LineEnding;
88
use der::{Decode, DecodePem, Encode, EncodePem};
9+
use log::trace;
910
use spki::AlgorithmIdentifierOwned;
1011
use x509_cert::attr::Attributes;
1112
use x509_cert::name::Name;
@@ -84,7 +85,8 @@ impl<S: Signature, P: PublicKey<S>> IdCsr<S, P> {
8485
signature_algorithm,
8586
signature,
8687
};
87-
log::trace!("[IdCsr::new()] Validating self with Target: {:?}", target);
88+
#[cfg(not(tarpaulin_include))]
89+
trace!("[IdCsr::new()] Validating self with Target: {:?}", target);
8890
id_csr.validate(target)?;
8991
Ok(id_csr)
9092
}

src/constraints/certs.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use log::{debug, warn};
5+
use log::{debug, trace, warn};
66

77
use crate::errors::{
88
ERR_MSG_ACTOR_CANNOT_BE_CA, ERR_MSG_DC_MISMATCH_ISSUER_SUBJECT,
@@ -13,12 +13,14 @@ use super::*;
1313

1414
impl<S: Signature, P: PublicKey<S>> Constrained for IdCsrInner<S, P> {
1515
fn validate(&self, target: Option<Target>) -> Result<(), ConstraintError> {
16-
log::trace!(
16+
#[cfg(not(tarpaulin_include))]
17+
trace!(
1718
"[IdCsrInner::validate()] validating capabilities for target: {:?}",
1819
target
1920
);
2021
self.capabilities.validate(target)?;
21-
log::trace!(
22+
#[cfg(not(tarpaulin_include))]
23+
trace!(
2224
"[IdCsrInner::validate()] validating subject for target: {:?}",
2325
target
2426
);
@@ -47,12 +49,13 @@ impl<S: Signature, P: PublicKey<S>> Constrained for IdCsrInner<S, P> {
4749

4850
impl<S: Signature, P: PublicKey<S>> Constrained for IdCsr<S, P> {
4951
fn validate(&self, target: Option<Target>) -> Result<(), ConstraintError> {
50-
log::trace!(
52+
trace!(
5153
"[IdCsr::validate()] validating inner CSR with target {:?}",
5254
target
5355
);
5456
self.inner_csr.validate(target)?;
55-
log::trace!("[IdCsr::validate()] verifying signature");
57+
#[cfg(not(tarpaulin_include))]
58+
trace!("[IdCsr::validate()] verifying signature");
5659
match self.inner_csr.subject_public_key.verify_signature(
5760
&self.signature,
5861
match &self.inner_csr.clone().to_der() {
@@ -74,7 +77,8 @@ impl<S: Signature, P: PublicKey<S>> Constrained for IdCsr<S, P> {
7477

7578
impl<S: Signature, P: PublicKey<S>> Constrained for IdCert<S, P> {
7679
fn validate(&self, target: Option<Target>) -> Result<(), ConstraintError> {
77-
log::trace!(
80+
#[cfg(not(tarpaulin_include))]
81+
trace!(
7882
"[IdCert::validate()] validating inner IdCertTbs with target {:?}",
7983
target
8084
);
@@ -85,7 +89,8 @@ impl<S: Signature, P: PublicKey<S>> Constrained for IdCert<S, P> {
8589

8690
impl<S: Signature, P: PublicKey<S>> Constrained for IdCertTbs<S, P> {
8791
fn validate(&self, target: Option<Target>) -> Result<(), ConstraintError> {
88-
log::trace!(
92+
#[cfg(not(tarpaulin_include))]
93+
trace!(
8994
"[IdCertTbs::validate()] validating if DER encoding is intact for certificate serial {:?}",
9095
self.serial_number
9196
);
@@ -101,25 +106,30 @@ impl<S: Signature, P: PublicKey<S>> Constrained for IdCertTbs<S, P> {
101106
)));
102107
}
103108
};
104-
log::trace!(
109+
#[cfg(not(tarpaulin_include))]
110+
trace!(
105111
"[IdCertTbs::validate()] validating capabilities for target: {:?}",
106112
target
107113
);
108114
self.capabilities.validate(target)?;
109115
dbg!(self.issuer.to_string());
110116
self.issuer.validate(Some(Target::HomeServer))?;
111117
self.subject.validate(target)?;
112-
log::trace!(
113-
"[IdCertTbs::validate()] checking if domain components of issuer and subject are equal"
114-
);
115-
log::trace!(
116-
"[IdCertTbs::validate()] Issuer: {}",
117-
self.issuer.to_string()
118-
);
119-
log::trace!(
120-
"[IdCertTbs::validate()] Subject: {}",
121-
self.subject.to_string()
122-
);
118+
#[cfg(not(tarpaulin_include))]
119+
{
120+
trace!(
121+
"[IdCertTbs::validate()] checking if domain components of issuer and subject are equal"
122+
);
123+
trace!(
124+
"[IdCertTbs::validate()] Issuer: {}",
125+
self.issuer.to_string()
126+
);
127+
trace!(
128+
"[IdCertTbs::validate()] Subject: {}",
129+
self.subject.to_string()
130+
);
131+
}
132+
123133
match equal_domain_components(&self.issuer, &self.subject) {
124134
true => debug!("Domain components of issuer and subject are equal"),
125135
false => {

src/constraints/name.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ impl Constrained for Name {
2323
/// - MAY have other attributes, which might be ignored by other home servers and other clients.
2424
// I apologize. This is horrible. I'll redo it eventually. Depression made me do it. -bitfl0wer
2525
fn validate(&self, target: Option<Target>) -> Result<(), ConstraintError> {
26-
log::trace!("[Name::validate()] Validating Name: {}", self.to_string());
26+
#[cfg(not(tarpaulin_include))]
27+
trace!("[Name::validate()] Validating Name: {}", self.to_string());
2728
let mut num_cn: u8 = 0;
2829
let mut num_dc: u8 = 0;
2930
let mut num_uid: u8 = 0;
@@ -34,28 +35,32 @@ impl Constrained for Name {
3435

3536
let rdns = &self.0;
3637
for rdn in rdns.iter() {
37-
log::trace!(
38+
#[cfg(not(tarpaulin_include))]
39+
trace!(
3840
"[Name::validate()] Determining OID of RDN {} and performing appropriate validation",
3941
rdn.to_string()
4042
);
4143
for item in rdn.0.iter() {
4244
match item.oid.to_string().as_str() {
4345
OID_RDN_UID => {
44-
log::trace!("[Name::validate()] Found UID in RDN: {}", item.to_string());
46+
#[cfg(not(tarpaulin_include))]
47+
trace!("[Name::validate()] Found UID in RDN: {}", item.to_string());
4548
num_uid += 1;
4649
uid = rdn.clone();
4750
validate_rdn_uid(item)?;
4851
}
4952
OID_RDN_UNIQUE_IDENTIFIER => {
50-
log::trace!(
53+
#[cfg(not(tarpaulin_include))]
54+
trace!(
5155
"[Name::validate()] Found uniqueIdentifier in RDN: {}",
5256
item.to_string()
5357
);
5458
num_unique_identifier += 1;
5559
validate_rdn_unique_identifier(item)?;
5660
}
5761
OID_RDN_COMMON_NAME => {
58-
log::trace!(
62+
#[cfg(not(tarpaulin_include))]
63+
trace!(
5964
"[Name::validate()] Found Common Name in RDN: {}",
6065
item.to_string()
6166
);
@@ -71,15 +76,17 @@ impl Constrained for Name {
7176
}
7277
}
7378
OID_RDN_DOMAIN_COMPONENT => {
74-
log::trace!(
79+
#[cfg(not(tarpaulin_include))]
80+
trace!(
7581
"[Name::validate()] Found Domain Component in RDN: {}",
7682
item.to_string()
7783
);
7884
num_dc += 1;
7985
vec_dc.push(rdn.clone());
8086
}
8187
_ => {
82-
log::trace!(
88+
#[cfg(not(tarpaulin_include))]
89+
trace!(
8390
"[Name::validate()] Found unknown/non-validated component in RDN: {}",
8491
item.to_string()
8592
);
@@ -92,7 +99,8 @@ impl Constrained for Name {
9299
if let Some(target) = target {
93100
match target {
94101
Target::Actor => {
95-
log::trace!(
102+
#[cfg(not(tarpaulin_include))]
103+
trace!(
96104
"[Name::validate()] Validating DC {:?} matches DC in UID {}",
97105
vec_dc
98106
.iter()
@@ -117,13 +125,16 @@ impl Constrained for Name {
117125
} else if num_uid != 0 {
118126
validate_dc_matches_dc_in_uid(&vec_dc, &uid)?;
119127
}
120-
log::trace!(
128+
129+
#[cfg(not(tarpaulin_include))]
130+
trace!(
121131
"Encountered {} UID components and {} Common Name components",
122132
num_uid,
123133
num_cn
124134
);
125135
if num_uid != 0 && num_cn != 0 {
126-
log::trace!("Validating UID username matches Common Name");
136+
#[cfg(not(tarpaulin_include))]
137+
trace!("Validating UID username matches Common Name");
127138
validate_uid_username_matches_cn(&uid, &cn)?;
128139
}
129140
if num_dc == 0 {
@@ -196,6 +207,8 @@ fn validate_dc_matches_dc_in_uid(
196207
// Split the UID at the @
197208
let uid_without_username = uid.to_string().split_at(position_of_at + 1).1.to_string(); // +1 to not include the @
198209
let dc_normalized_uid: Vec<&str> = uid_without_username.split('.').collect();
210+
#[cfg(not(tarpaulin_include))]
211+
#[cfg(not(tarpaulin_include))]
199212
trace!("UID domain components: {:?}", dc_normalized_uid.clone());
200213
let mut index = 0u8;
201214
// Iterate over the DCs in the UID and check if they are equal to the DCs in the vec of DCs
@@ -208,6 +221,8 @@ fn validate_dc_matches_dc_in_uid(
208221
)))
209222
}
210223
};
224+
#[cfg(not(tarpaulin_include))]
225+
#[cfg(not(tarpaulin_include))]
211226
trace!("Found an equivalent domain component: {}", equivalent_dc);
212227
let equivalent_dc = equivalent_dc.to_string().split_at(3).1.to_string();
213228
if component != &equivalent_dc.to_string() {

0 commit comments

Comments
 (0)