Skip to content

Commit 89ba1c1

Browse files
committed
Remove low-value abstraction layer
1 parent 8e0cede commit 89ba1c1

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

src/subject_name/dns_name.rs

+6-26
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a> DnsNameRef<'a> {
9999
_ => return None,
100100
};
101101

102-
match presented_id_matches_reference_id(presented_id, dns_name) {
102+
match presented_id_matches_reference_id(presented_id, IdRole::Reference, dns_name) {
103103
Ok(true) => Some(Ok(())),
104104
Ok(false) | Err(Error::MalformedDnsIdentifier) => None,
105105
Err(e) => Some(Err(e)),
@@ -205,28 +205,6 @@ impl core::fmt::Display for InvalidDnsNameError {
205205
#[cfg(feature = "std")]
206206
impl ::std::error::Error for InvalidDnsNameError {}
207207

208-
fn presented_id_matches_reference_id(
209-
presented_dns_id: untrusted::Input,
210-
reference_dns_id: untrusted::Input,
211-
) -> Result<bool, Error> {
212-
presented_id_matches_reference_id_internal(
213-
presented_dns_id,
214-
IdRole::Reference,
215-
reference_dns_id,
216-
)
217-
}
218-
219-
pub(super) fn presented_id_matches_constraint(
220-
presented_dns_id: untrusted::Input,
221-
reference_dns_id: untrusted::Input,
222-
) -> Result<bool, Error> {
223-
presented_id_matches_reference_id_internal(
224-
presented_dns_id,
225-
IdRole::NameConstraint,
226-
reference_dns_id,
227-
)
228-
}
229-
230208
// We assume that both presented_dns_id and reference_dns_id are encoded in
231209
// such a way that US-ASCII (7-bit) characters are encoded in one byte and no
232210
// encoding of a non-US-ASCII character contains a code point in the range
@@ -343,7 +321,7 @@ pub(super) fn presented_id_matches_constraint(
343321
// [4] Feedback on the lack of clarify in the definition that never got
344322
// incorporated into the spec:
345323
// https://www.ietf.org/mail-archive/web/pkix/current/msg21192.html
346-
fn presented_id_matches_reference_id_internal(
324+
pub(super) fn presented_id_matches_reference_id(
347325
presented_dns_id: untrusted::Input,
348326
reference_dns_id_role: IdRole,
349327
reference_dns_id: untrusted::Input,
@@ -489,7 +467,7 @@ enum Wildcards {
489467
}
490468

491469
#[derive(Clone, Copy, PartialEq)]
492-
enum IdRole {
470+
pub(super) enum IdRole {
493471
Reference,
494472
Presented,
495473
NameConstraint,
@@ -1000,6 +978,7 @@ mod tests {
1000978
for &(presented, reference, expected_result) in PRESENTED_MATCHES_REFERENCE {
1001979
let actual_result = presented_id_matches_reference_id(
1002980
untrusted::Input::from(presented),
981+
IdRole::Reference,
1003982
untrusted::Input::from(reference),
1004983
);
1005984
assert_eq!(
@@ -1074,8 +1053,9 @@ mod tests {
10741053
#[test]
10751054
fn presented_matches_constraint_test() {
10761055
for &(presented, constraint, expected_result) in PRESENTED_MATCHES_CONSTRAINT {
1077-
let actual_result = presented_id_matches_constraint(
1056+
let actual_result = presented_id_matches_reference_id(
10781057
untrusted::Input::from(presented),
1058+
IdRole::NameConstraint,
10791059
untrusted::Input::from(constraint),
10801060
);
10811061
assert_eq!(

src/subject_name/verify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1313
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1414

15-
use super::dns_name;
15+
use super::dns_name::{self, IdRole};
1616
use super::ip_address;
1717
use crate::der::{self, FromDer};
1818
use crate::error::{DerTypeId, Error};
@@ -108,7 +108,7 @@ fn check_presented_id_conforms_to_constraints(
108108

109109
let matches = match (name, base) {
110110
(GeneralName::DnsName(name), GeneralName::DnsName(base)) => {
111-
dns_name::presented_id_matches_constraint(name, base)
111+
dns_name::presented_id_matches_reference_id(name, IdRole::NameConstraint, base)
112112
}
113113

114114
(GeneralName::DirectoryName(_), GeneralName::DirectoryName(_)) => Ok(

0 commit comments

Comments
 (0)