From: Pablo Rodriguez <oinos@gmx.es>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: util-sha.lua misbehaving?
Date: Thu, 28 Feb 2019 18:46:03 +0100 [thread overview]
Message-ID: <b6fc054d-7b03-6528-8748-1e91357bfee9@gmx.es> (raw)
Dear list,
I have the following sample:
\startluacode
function document.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
function document.sha512(file)
command_output= document.capture("sha512sum -b " .. file)
context(command_output:sub(0,8))
end
\stopluacode
\def\shafive#1{\ctxlua{document.sha512("#1")}}
\doif{\luaversion}{5.3}{\ctxlua{require("util-sha")}}
\def\hashfive#1{%
\ctxlua{context(
utilities.sha2.hash512("#1"):sub(0,8))}}
\def\hashfivefile#1{%
\ctxlua{context(
utilities.sha2.hash512(io.loaddata("#1")):sub(0,8))}}
\def\cB{i-context.pdf}
\starttext
\startTEXpage[offset=2em]
\tt i-context.pdf\ss:
\doifelse{\luaversion}{5.3}
{\hashfivefile{\cB}\\
{\rm text: }\hashfive{\cB}}
{\shafive{\cB}}
\stopTEXpage
\stoptext
Just accidentally, I discovered today (using latest beta from 2019.02.26
20:04) that file hashing may be wrong in ConTeXt. For the sake of
brevity, I only use the 8 first chars.
"sha512sum i-context.pdf" gives c4cc3840. Using luajittex, I get that
result. But using Lua 5.3 (and util-sha.lua), I get 44241e9d.
I don’t know whether my invocation of io.loaddata is wrong, since the
SHA512 for the text "i-context.pdf" is 2ac2778b, which is the same
result as https://duckduckgo.com/?q=sha512+i-context.pdf.
After discovering that io.loaddata is from l-io.lua, I don’t know what I
may be doing wrong.
This is an essential feature for me in ConTeXt, since it is the way of
showing the integrity of the attached files to a PDF document (mainly
digitally signed documents).
Could anyone tell me what I am missing here?
Many thanks for your help,
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next reply other threads:[~2019-02-28 17:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 17:46 Pablo Rodriguez [this message]
2019-02-28 21:36 ` Hans Hagen
2019-03-04 15:34 ` luigi scarso
2019-03-04 17:48 ` Pablo Rodriguez
2019-03-04 18:12 ` luigi scarso
2019-03-04 18:26 ` Pablo Rodriguez
2019-03-04 18:33 ` luigi scarso
2019-03-04 19:40 ` Pablo Rodriguez
2019-03-04 19:56 ` luigi scarso
2019-03-04 20:20 ` Hans Hagen
2019-03-04 20:36 ` Pablo Rodriguez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b6fc054d-7b03-6528-8748-1e91357bfee9@gmx.es \
--to=oinos@gmx.es \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).