sourceextensions/digest/lib/Digest.xtl
1⍝# Digest.xtl -- the facade of the digest extension: SHA-256 and CRC-32
2⍝# of text and of files, to check that content is what it should be.
3⍝# Import: "dg:" u_se< "Digest"
4⍝# Files are named by paths under the working directory (or
5⍝# XETAL_DIGEST_ROOT), relative, with no ..
6⍝# Run with xetal-x (xetal-x --ext DIR puts this directory on XETAL_PATH).
7⍝# Each signature line is written out by the binding macro (lib/Ffi.xtlm).
8
9ᶠᶠⁱ⁼u̲se< "Ffi"
10
11⍝# dg:s_ha256 t: the SHA-256 of a text (its UTF-8 bytes), 64 hex digits.
12"s_ha256 : text -> text" ᶠᶠⁱb̲ind< "digest/sha256"
13⍝# dg:s_ha256File path: the SHA-256 of a file, 64 hex digits.
14"s_ha256File : text -> text" ᶠᶠⁱb̲ind< "digest/sha256_file"
15⍝# dg:c_rc32 t: the CRC-32 (IEEE, as zip and PNG use) of a text.
16"c_rc32 : text -> int" ᶠᶠⁱb̲ind< "digest/crc32"
17⍝# dg:c_rc32File path: the CRC-32 of a file.
18"c_rc32File : text -> int" ᶠᶠⁱb̲ind< "digest/crc32_file"
19
20⍝# The native package behind these functions.
21ˡpackage ← "digest"
ᶠᶠⁱb̲ind< expands to
ˡs̲ha256 ← { a → pa ← a ⎕N̲PUT "ext:digest/sha256?text" ⎕N̲GET "ext:digest/sha256" }
ᶠᶠⁱb̲ind< expands to
ˡs̲ha256File ← { a → pa ← a ⎕N̲PUT "ext:digest/sha256_file?text" ⎕N̲GET "ext:digest/sha256_file" }
ᶠᶠⁱb̲ind< expands to
ˡc̲rc32 ← { a → pa ← a ⎕N̲PUT "ext:digest/crc32?text" f̲loor f̲irst n̲umbers ⎕N̲GET "ext:digest/crc32" }
ᶠᶠⁱb̲ind< expands to
ˡc̲rc32File ← { a → pa ← a ⎕N̲PUT "ext:digest/crc32_file?text" f̲loor f̲irst n̲umbers ⎕N̲GET "ext:digest/crc32_file" }