util.encodings API

Provides an interface for translating a string into various common encodings.

Currently provided are: base64, idna, stringprep.

Usage

Reference

base64

encode(string)

Returns a base64-encoded equivalent of a string.

decode(string)

Returns a decoded equivalent of a base64 string, or nil if the string is invalid base64.

idna

IDNA provides a way to safely convert unicode domain names to an ASCII equivalent, and back again.

to_ascii(string)

Returns an ASCII-safe version of a unicode domain name, or nil for an invalid domain.

Example:

   xn--hgi.ws
 

to_unicode(string)

Returns the original unicode version of an ASCII IDNA-encoded domain.

Example:

   ➡.ws
 

stringprep

Stringprep defines a way of processing and normalizing strings according to a set of rules (a profile). Prosody implements 4 profiles:

  • nodeprep (for usernames, the node part of a JID)
  • resourceprep (for resources and MUC nicknames)
  • saslprep (for applying to strings prior to calculating SASL challenges)
  • nameprep (for applying to hostnames/domains)

Example:

  helloworld
 

All stringprep functions return nil when the input is not a valid string in that particular profile.

utf8

UTF-8 is the character encoding used in XMPP. Prosody has a function for validating that a string is a valid UTF-8 encoded string, primarily used internally in util.encodings before passing data to the libidn library.

valid(string)
Returns boolean true if the string passed is a valid UTF-8 encoded string, false otherwise.