email_addr.nx
buildroot/runtime/email_addr.nx
about
email_addr.nx -- RFC 5322 addr-spec validator (practical subset).
The full RFC 5322 grammar accepts obscure forms like quoted
local parts (\"foo bar\"@example.com), comments ((comment)),
and folded whitespace -- practically never seen in real email
addresses. We implement the subset that matches what users
actually type:
local@domain
local = 1+ chars from [A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]
with '.' not first, not last, not consecutive
domain = at least one DNS label separated by '.'
label = [A-Za-z0-9] with optional [A-Za-z0-9-] interior,
trailing alnum, total length 1..63
Returns (local_off, local_len, domain_off, domain_len) on
success so caller can upper-case compare, hash, etc. Zero-
alloc.
Use cases: signup form validation, mailing-list import
sanity check, abuse detection, SPF lookup prep.
Invariants:
EA1 Total length cap 320 bytes (RFC 5321 ยง4.5.3.1.3).
EA2 Local part cap 64 bytes.
EA3 Domain cap 255 bytes; per-label cap 63.
EA4 Returns EA_ERR_* negative on violation; offsets populated
even on failure up to the point of failure (useful for
error messaging).
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 50 | struct EmailAddr { |
consts
| 33 | const EA_MAX_TOTAL: i64 = 320 |
| 34 | const EA_MAX_LOCAL: i64 = 64 |
| 35 | const EA_MAX_DOMAIN: i64 = 255 |
| 36 | const EA_MAX_LABEL: i64 = 63 |
| 38 | const EA_ERR_TOTAL_LEN: i64 = -1 |
| 39 | const EA_ERR_NO_AT: i64 = -2 |
| 40 | const EA_ERR_LOCAL_EMPTY: i64 = -3 |
| 41 | const EA_ERR_LOCAL_LEN: i64 = -4 |
| 42 | const EA_ERR_LOCAL_CHAR: i64 = -5 |
| 43 | const EA_ERR_LOCAL_DOT: i64 = -6 |
| 44 | const EA_ERR_DOMAIN_EMPTY: i64 = -7 |
| 45 | const EA_ERR_DOMAIN_LEN: i64 = -8 |
| 46 | const EA_ERR_LABEL_LEN: i64 = -9 |
| 47 | const EA_ERR_LABEL_CHAR: i64 = -10 |
| 48 | const EA_ERR_LABEL_DASH: i64 = -11 |
functions
| 56 | func ea_is_local_char(b: i64) -> i64 {
called by 1: email_addr_validate |
| 92 | func ea_is_alnum(b: i64) -> i64 {
called by 1: email_addr_validate |
| 106 | func if_eq_or(a: i64, b: i64, v1: i64, v2: i64) -> i64; |
| 110 | func email_addr_validate(buf: *u8, n: i64, e: *EmailAddr) -> i64 { |
| 197 | func if_eq_or(a: i64, b: i64, v1: i64, v2: i64) -> i64 { |
| 203 | func main() -> i64 {
calls 1: email_addr_validate |