Files
kumomta/docs/reference/kumo.digest/_index.md
T
Wez Furlong 42bf5c5e61 docs: adjust reference to improve search terms
We've been hoping that mkdocs-material will ship the much anticipated
search enhancements for some time, but it's time to recognize that
we need to do something to improve the search results with how
things work right now.

This is a big commit that changes the titles of the various pages
from the code-annotated synopsis to just the name of the function.

This makes it much easier now to match things like `kumo.reject`
directly, but `reject` remains awkward to find.

I think this is the best that we can do at this time.

A few functions have been annotated with the `status: deprecated` to
show as deprecated in the toc/nav (shows with a little trash can next
to the name).
2025-05-16 14:02:19 -07:00

2.1 KiB

Module kumo.digest

This module provides functions for hashing/digesting data.

The Digest Object

The functions in this module return a Digest object.

Printing or otherwise explicitly converting a Digest object as a string will produce the digest bytes encoded in hex.

The following fields are available to return the bytes encoded in various ways.

  • bytes - returns the data as a binary byte string. This is the most compact representation, but is difficult to pass into other systems without encoding in some way. Case sensitive.
  • hex - returns the data encoded as lowercase hexadecimal. This is the largest representation. Case insensitive.
  • base32 - returns the data encoded as base32. Case insensitive.
  • base32_nopad - same as base32, but does not include padding characters.
  • base32hex - returns the data encoded as base32hex. This is similar to base32, but the encoded version preserve the sort order of the input data. Case insensitive.
  • base32hex_nopad - same as base32hex, but does not include padding characters.
  • base64 - returns the data encoded as base64. Case sensitive.
  • base64_nopad - same as base64, but does not include padding characters.
  • base64url - returns the data encoded as base64, with a URL-safe alphabet. Case sensitive.
  • base64url_nopad - same as base64url, but does not include padding characters.
-- Compute the digest of 'hello'
local d = kumo.digest.sha1 'hello'
-- Demonstrate the various output properties of the digest object
assert(tostring(d) == d.hex)
assert(d.hex == 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d')
assert(
  d.bytes
    == '\xaa\xf4\xc6\x1d\xdc\xc5\xe8\xa2\xda\xbe\xde\x0f\x3b\x48\x2c\xd9\xae\xa9\x43\x4d'
)
assert(d.base32 == 'VL2MMHO4YXUKFWV63YHTWSBM3GXKSQ2N')
assert(d.base32_nopad == 'VL2MMHO4YXUKFWV63YHTWSBM3GXKSQ2N')
assert(d.base32hex == 'LBQCC7ESONKA5MLURO7JMI1CR6NAIGQD')
assert(d.base64 == 'qvTGHdzF6KLavt4PO0gs2a6pQ00=')
assert(d.base64_nopad == 'qvTGHdzF6KLavt4PO0gs2a6pQ00')
assert(d.base64url == 'qvTGHdzF6KLavt4PO0gs2a6pQ00=')
assert(d.base64url_nopad == 'qvTGHdzF6KLavt4PO0gs2a6pQ00')

Available Functions { data-search-exclude }