Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions boring/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl fmt::Display for Asn1TimeRef {

impl fmt::Debug for Asn1TimeRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_string())
fmt::Display::fmt(self, f)
}
}

Expand Down Expand Up @@ -626,7 +626,7 @@ impl fmt::Display for Asn1ObjectRef {

impl fmt::Debug for Asn1ObjectRef {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str(self.to_string().as_str())
fmt::Display::fmt(self, fmt)
}
}

Expand Down
12 changes: 6 additions & 6 deletions boring/src/x509/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl BasicConstraints {
value.push_str("FALSE");
}
if let Some(pathlen) = self.pathlen {
write!(value, ",pathlen:{pathlen}").unwrap();
write!(value, ",pathlen:{pathlen}").map_err(ErrorStack::internal_error)?;
}
X509Extension::new_nid(None, None, Nid::BASIC_CONSTRAINTS, &value)
}
Expand Down Expand Up @@ -454,31 +454,31 @@ impl SubjectAlternativeName {

/// Sets the `email` flag.
pub fn email(&mut self, email: &str) -> &mut SubjectAlternativeName {
self.items.push(RustGeneralName::Email(email.to_string()));
self.items.push(RustGeneralName::Email(email.to_owned()));
self
}

/// Sets the `uri` flag.
pub fn uri(&mut self, uri: &str) -> &mut SubjectAlternativeName {
self.items.push(RustGeneralName::Uri(uri.to_string()));
self.items.push(RustGeneralName::Uri(uri.to_owned()));
self
}

/// Sets the `dns` flag.
pub fn dns(&mut self, dns: &str) -> &mut SubjectAlternativeName {
self.items.push(RustGeneralName::Dns(dns.to_string()));
self.items.push(RustGeneralName::Dns(dns.to_owned()));
self
}

/// Sets the `rid` flag.
pub fn rid(&mut self, rid: &str) -> &mut SubjectAlternativeName {
self.items.push(RustGeneralName::Rid(rid.to_string()));
self.items.push(RustGeneralName::Rid(rid.to_owned()));
self
}

/// Sets the `ip` flag.
pub fn ip(&mut self, ip: &str) -> &mut SubjectAlternativeName {
self.items.push(RustGeneralName::Ip(ip.to_string()));
self.items.push(RustGeneralName::Ip(ip.to_owned()));
self
}

Expand Down
10 changes: 7 additions & 3 deletions boring/src/x509/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ impl X509StoreBuilderRef {
unsafe { cvt(ffi::X509_STORE_set_default_paths(self.as_ptr())) }
}

/// Sets certificate chain validation related flags.
#[corresponds(X509_STORE_set_flags)]
pub fn try_set_flags(&mut self, flags: X509VerifyFlags) -> Result<(), ErrorStack> {
unsafe { cvt(ffi::X509_STORE_set_flags(self.as_ptr(), flags.bits())) }
}

/// Sets certificate chain validation related flags.
#[corresponds(X509_STORE_set_flags)]
pub fn set_flags(&mut self, flags: X509VerifyFlags) {
unsafe {
cvt(ffi::X509_STORE_set_flags(self.as_ptr(), flags.bits())).unwrap();
}
self.try_set_flags(flags).expect("use try_set_flags");
}

/// Returns a mutable reference to the X509 verification configuration.
Expand Down
6 changes: 4 additions & 2 deletions boring/src/x509/tests/trusted_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn test_verify_cert() {
&leaf,
&[&root1, &root2],
&[&intermediate, &root1_cross],
|param| param.set_flags(X509VerifyFlags::TRUSTED_FIRST),
|param| param.try_set_flags(X509VerifyFlags::TRUSTED_FIRST).unwrap(),
)
);

Expand All @@ -60,7 +60,9 @@ fn test_verify_cert() {
assert_eq!(
Ok(()),
verify(&leaf, &[&root1], &[&intermediate, &root1_cross], |param| {
param.clear_flags(X509VerifyFlags::TRUSTED_FIRST);
param
.try_clear_flags(X509VerifyFlags::TRUSTED_FIRST)
.unwrap();
})
);
}
Expand Down
15 changes: 12 additions & 3 deletions boring/src/x509/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,37 @@ impl X509VerifyParamRef {
/// Set verification flags.
#[corresponds(X509_VERIFY_PARAM_set_flags)]
pub fn set_flags(&mut self, flags: X509VerifyFlags) {
self.try_set_flags(flags).expect("use try_set_flags");
}

/// Set verification flags.
#[corresponds(X509_VERIFY_PARAM_set_flags)]
pub fn try_set_flags(&mut self, flags: X509VerifyFlags) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::X509_VERIFY_PARAM_set_flags(
self.as_ptr(),
flags.bits(),
))
.unwrap();
}
}

/// Clear verification flags.
#[corresponds(X509_VERIFY_PARAM_clear_flags)]
pub fn clear_flags(&mut self, flags: X509VerifyFlags) {
self.try_clear_flags(flags).expect("use try_clear_flags");
}

/// Clear verification flags.
#[corresponds(X509_VERIFY_PARAM_clear_flags)]
pub fn try_clear_flags(&mut self, flags: X509VerifyFlags) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::X509_VERIFY_PARAM_clear_flags(
self.as_ptr(),
flags.bits(),
))
.unwrap();
}
}

///
/// Set the host flags.
#[corresponds(X509_VERIFY_PARAM_set_hostflags)]
pub fn set_hostflags(&mut self, hostflags: X509CheckFlags) {
Expand Down
Loading