Skip to content
Jennifer Programming Language

transport - shared connection-security mode

Import with import "transport.j" as transport;. A single shared enum for the connection security mode used by every network-client module that opens a socket - smtp, pop, imap, ldap, redis, amqp, mqtt. One typed value instead of a stringly-typed security field per module, so a typo is a compile-time error, not a silent plaintext downgrade. Pure .j (an enum, two helpers and a constant); runs on both binaries.

jennifer
import "transport.j" as transport;
import "smtp.j" as smtp;

def o as smtp.Options init smtp.Options{
    host: "smtp.example.com", port: 587,
    security: transport.Security.Starttls,
    clientName: "me", user: "u", pass: "p", auth: "", allowInsecureAuth: false};

The Security enum

transport.Security has three variants:

VariantMeaning
Security.NonePlaintext - no encryption.
Security.TlsImplicit TLS negotiated on connect (SMTPS / POP3S / IMAPS / rediss / AMQPS / mqtts).
Security.StarttlsConnect in plaintext, then upgrade in-band (SMTP STARTTLS, POP3 STLS, IMAP STARTTLS).

The zero value is Security.None (the first variant), so a zero-value Options is plaintext.

Only the protocols with an in-band upgrade command accept Starttls: smtp, pop, imap and ldap. redis, amqp, and mqtt have no such command and reject Security.Starttls with a catchable Error (their match handles the variant explicitly rather than silently treating it as plaintext) - use Security.Tls for the TLS-on-connect port instead.

Helper

CallReturns
transport.encrypted(s)booltrue for Tls / Starttls, false for None

encrypted is the "is this connection protected?" test - e.g. smtp uses it to refuse sending SASL credentials over a None connection unless allowInsecureAuth is set.

Received-data cap

transport.MAX_RECEIVED_BYTES (64 MiB) is the tree-wide ceiling on a single received payload, and transport.checkReceiveSize(n, what) enforces it: it raises a catchable Error{kind: "limit"} naming what when n is over the cap, and kind "transport" when it is negative (a malformed declared size). A wire client calls it on a peer-declared body / literal size before reading, and on an accumulating buffer's length inside a read loop, so a hostile or desynced server cannot drive the interpreter to an unbounded allocation, and every client caps identically.

jennifer
import "transport.j" as transport;

def bodySize as int init 4096;                                # as the peer declared it
transport.checkReceiveSize($bodySize, "amqp message body");   # throws if > 64 MiB

Why a separate module

The security mode is the one field shared verbatim across every socket client, so it lives in one place rather than duplicated as seven sibling enums (the one-way-per-thing stance). Because Jennifer has no re-export, a program that builds a client Options imports transport alongside the client module - the small cost of a single shared type.

See also

Academy talks

TalkWhat it shows
Email with Jennifer: SMTP, IMAP and POP3TLS and STARTTLS settings for SMTP, IMAP and POP3

API reference

Every exported function, struct and constant of transport, with its signature, generated from the module's doc comments: the transport API reference.