def _generate_tls_certificates() -> _TLSCertificates:
    """Generate self-signed TLS certificates as bytes"""
    private_key = _generate_private_key()
    certificate = _generate_self_signed_certificate(private_key)

    private_key_bytes = private_key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.TraditionalOpenSSL,
        encryption_algorithm=NoEncryption(),
    )
    certificate_bytes = certificate.public_bytes(serialization.Encoding.PEM)

    return _TLSCertificates(private_key_bytes, certificate_bytes)
Generate self-signed TLS certificates as bytes
modules/mailpit/testcontainers/mailpit/__init__.py