Karta.Mail.Punycode (Karta v1.0.0)

Punycode encoding (RFC 3492) and the conversion of a domain name to its ASCII form (A-labels, RFC 5890), used to compare domains.

to_ascii/1 is deliberately strict. It returns :error for anything it cannot convert unambiguously, so a comparison against a known domain fails closed:

  • ASCII labels must be letters, digits and hyphens (no leading or trailing hyphen), 1 to 63 octets; they are lower-cased.
  • Labels with non-ASCII characters must already be in Unicode Normalization Form C (a different spelling of the same text is refused, not normalised), must not contain ASCII characters other than letters, digits and hyphens, or control characters; they are lower-cased and encoded as xn-- plus Punycode.
  • The whole name must be at most 253 octets in ASCII form.

Summary

Functions

Punycode-encodes a string of Unicode characters (no xn-- prefix).

The lower-case ASCII form of a domain name, or :error (see the module doc).

Functions

encode(string)

@spec encode(String.t()) :: {:ok, String.t()} | :error

Punycode-encodes a string of Unicode characters (no xn-- prefix).

to_ascii(domain)

@spec to_ascii(String.t()) :: {:ok, String.t()} | :error

The lower-case ASCII form of a domain name, or :error (see the module doc).