structured-pkix 0.3.0

Borrowed X.509 certificates and provider-neutral certification path validation
Documentation
#[test]
fn every_identifier_renders_as_the_dotted_form_it_is_documented_with() {
    // The bytes are what a document carries and what identity is compared
    // on, so a mistyped one would silently fail to match the extension or
    // attribute it names. Rendering each back is what catches that.
    for (identifier, dotted) in [
        (super::COMMON_NAME, "2.5.4.3"),
        (super::SURNAME, "2.5.4.4"),
        (super::SERIAL_NUMBER, "2.5.4.5"),
        (super::COUNTRY, "2.5.4.6"),
        (super::LOCALITY, "2.5.4.7"),
        (super::STATE_OR_PROVINCE, "2.5.4.8"),
        (super::STREET_ADDRESS, "2.5.4.9"),
        (super::ORGANIZATION, "2.5.4.10"),
        (super::ORGANIZATIONAL_UNIT, "2.5.4.11"),
        (super::TITLE, "2.5.4.12"),
        (super::GIVEN_NAME, "2.5.4.42"),
        (super::INITIALS, "2.5.4.43"),
        (super::GENERATION_QUALIFIER, "2.5.4.44"),
        (super::DN_QUALIFIER, "2.5.4.46"),
        (super::PSEUDONYM, "2.5.4.65"),
        (super::ORGANIZATION_IDENTIFIER, "2.5.4.97"),
        (super::EMAIL_ADDRESS, "1.2.840.113549.1.9.1"),
        (super::DOMAIN_COMPONENT, "0.9.2342.19200300.100.1.25"),
        (super::USER_ID, "0.9.2342.19200300.100.1.1"),
        (super::SUBJECT_DIRECTORY_ATTRIBUTES, "2.5.29.9"),
        (super::SUBJECT_KEY_IDENTIFIER, "2.5.29.14"),
        (super::KEY_USAGE, "2.5.29.15"),
        (super::PRIVATE_KEY_USAGE_PERIOD, "2.5.29.16"),
        (super::SUBJECT_ALT_NAME, "2.5.29.17"),
        (super::ISSUER_ALT_NAME, "2.5.29.18"),
        (super::BASIC_CONSTRAINTS, "2.5.29.19"),
        (super::NAME_CONSTRAINTS, "2.5.29.30"),
        (super::CRL_DISTRIBUTION_POINTS, "2.5.29.31"),
        (super::CERTIFICATE_POLICIES, "2.5.29.32"),
        (super::POLICY_MAPPINGS, "2.5.29.33"),
        (super::AUTHORITY_KEY_IDENTIFIER, "2.5.29.35"),
        (super::POLICY_CONSTRAINTS, "2.5.29.36"),
        (super::EXT_KEY_USAGE, "2.5.29.37"),
        (super::FRESHEST_CRL, "2.5.29.46"),
        (super::INHIBIT_ANY_POLICY, "2.5.29.54"),
        (super::AUTHORITY_INFO_ACCESS, "1.3.6.1.5.5.7.1.1"),
        (super::SUBJECT_INFO_ACCESS, "1.3.6.1.5.5.7.1.11"),
        (super::QC_STATEMENTS, "1.3.6.1.5.5.7.1.3"),
        (super::OCSP, "1.3.6.1.5.5.7.48.1"),
        (super::CA_ISSUERS, "1.3.6.1.5.5.7.48.2"),
        (super::TIME_STAMPING_ACCESS, "1.3.6.1.5.5.7.48.3"),
        (super::CA_REPOSITORY, "1.3.6.1.5.5.7.48.5"),
        (super::ANY_EXTENDED_KEY_USAGE, "2.5.29.37.0"),
        (super::SERVER_AUTH, "1.3.6.1.5.5.7.3.1"),
        (super::CLIENT_AUTH, "1.3.6.1.5.5.7.3.2"),
        (super::CODE_SIGNING, "1.3.6.1.5.5.7.3.3"),
        (super::EMAIL_PROTECTION, "1.3.6.1.5.5.7.3.4"),
        (super::TIME_STAMPING, "1.3.6.1.5.5.7.3.8"),
        (super::OCSP_SIGNING, "1.3.6.1.5.5.7.3.9"),
        (super::ANY_POLICY, "2.5.29.32.0"),
        (super::CPS_QUALIFIER, "1.3.6.1.5.5.7.2.1"),
        (super::USER_NOTICE_QUALIFIER, "1.3.6.1.5.5.7.2.2"),
        (super::QC_COMPLIANCE, "0.4.0.1862.1.1"),
        (super::QC_LIMIT_VALUE, "0.4.0.1862.1.2"),
        (super::QC_RETENTION_PERIOD, "0.4.0.1862.1.3"),
        (super::QC_SSCD, "0.4.0.1862.1.4"),
        (super::QC_PDS, "0.4.0.1862.1.5"),
        (super::QC_TYPE, "0.4.0.1862.1.6"),
        (super::QC_CC_LEGISLATION, "0.4.0.1862.1.7"),
        (super::QCT_ESIGN, "0.4.0.1862.1.6.1"),
        (super::QCT_ESEAL, "0.4.0.1862.1.6.2"),
        (super::QCT_WEB, "0.4.0.1862.1.6.3"),
        (super::PKIX_QC_SYNTAX_V1, "1.3.6.1.5.5.7.11.1"),
        (super::PKIX_QC_SYNTAX_V2, "1.3.6.1.5.5.7.11.2"),
        (super::SEMANTICS_NATURAL_PERSON, "0.4.0.194121.1.1"),
        (super::SEMANTICS_LEGAL_PERSON, "0.4.0.194121.1.2"),
        (super::RSA_ENCRYPTION, "1.2.840.113549.1.1.1"),
        (super::RSASSA_PSS, "1.2.840.113549.1.1.10"),
        (super::EC_PUBLIC_KEY, "1.2.840.10045.2.1"),
        (super::ED25519, "1.3.101.112"),
        (super::ED448, "1.3.101.113"),
    ] {
        let execution = crate::fixtures::memory();
        let text = identifier.text(&execution).unwrap();
        assert_eq!(text.as_str(&execution).unwrap(), dotted);
    }
}

#[test]
fn no_two_identifiers_are_the_same_bytes() {
    // Two names for one identifier would make a lookup answer with
    // whichever was asked first, and the mistake would look like a
    // certificate that does not carry the extension.
    let all = [
        super::COMMON_NAME,
        super::SURNAME,
        super::SERIAL_NUMBER,
        super::COUNTRY,
        super::LOCALITY,
        super::STATE_OR_PROVINCE,
        super::STREET_ADDRESS,
        super::ORGANIZATION,
        super::ORGANIZATIONAL_UNIT,
        super::TITLE,
        super::GIVEN_NAME,
        super::INITIALS,
        super::GENERATION_QUALIFIER,
        super::DN_QUALIFIER,
        super::PSEUDONYM,
        super::ORGANIZATION_IDENTIFIER,
        super::EMAIL_ADDRESS,
        super::DOMAIN_COMPONENT,
        super::USER_ID,
        super::SUBJECT_DIRECTORY_ATTRIBUTES,
        super::SUBJECT_KEY_IDENTIFIER,
        super::KEY_USAGE,
        super::PRIVATE_KEY_USAGE_PERIOD,
        super::SUBJECT_ALT_NAME,
        super::ISSUER_ALT_NAME,
        super::BASIC_CONSTRAINTS,
        super::NAME_CONSTRAINTS,
        super::CRL_DISTRIBUTION_POINTS,
        super::CERTIFICATE_POLICIES,
        super::POLICY_MAPPINGS,
        super::AUTHORITY_KEY_IDENTIFIER,
        super::POLICY_CONSTRAINTS,
        super::EXT_KEY_USAGE,
        super::FRESHEST_CRL,
        super::INHIBIT_ANY_POLICY,
        super::AUTHORITY_INFO_ACCESS,
        super::SUBJECT_INFO_ACCESS,
        super::QC_STATEMENTS,
        super::OCSP,
        super::CA_ISSUERS,
        super::TIME_STAMPING_ACCESS,
        super::CA_REPOSITORY,
        super::ANY_EXTENDED_KEY_USAGE,
        super::SERVER_AUTH,
        super::CLIENT_AUTH,
        super::CODE_SIGNING,
        super::EMAIL_PROTECTION,
        super::TIME_STAMPING,
        super::OCSP_SIGNING,
        super::ANY_POLICY,
        super::CPS_QUALIFIER,
        super::USER_NOTICE_QUALIFIER,
        super::QC_COMPLIANCE,
        super::QC_LIMIT_VALUE,
        super::QC_RETENTION_PERIOD,
        super::QC_SSCD,
        super::QC_PDS,
        super::QC_TYPE,
        super::QC_CC_LEGISLATION,
        super::QCT_ESIGN,
        super::QCT_ESEAL,
        super::QCT_WEB,
        super::PKIX_QC_SYNTAX_V1,
        super::PKIX_QC_SYNTAX_V2,
        super::SEMANTICS_NATURAL_PERSON,
        super::SEMANTICS_LEGAL_PERSON,
        super::RSA_ENCRYPTION,
        super::RSASSA_PSS,
        super::EC_PUBLIC_KEY,
        super::ED25519,
        super::ED448,
    ];
    for (position, identifier) in all.iter().enumerate() {
        assert!(
            !all[..position].contains(identifier),
            "{identifier:?} appears twice"
        );
    }
}