ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Max Chernoff via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Max Chernoff <mseven@telus.net>, oinos@gmx.es
Subject: Re: new hash for buffer (as file)
Date: Thu, 22 Sep 2022 22:01:25 -0600	[thread overview]
Message-ID: <6ebdfae4256fb8b52e941e66ced7a5e7f4b016f8.camel@telus.net> (raw)
In-Reply-To: <1e089d8f-2503-d06d-57af-c5ac60256596@gmx.es>

Hi Pablo,

> I mean, to get hash of the file attached to the document, I need to save
> the buffer for "context(utilities.sha2.hash256(io.loaddata(buffer)))".
> 
> But I don’t need to save the buffer to attach it to the PDF document.
> 
> My question is how to define \shabufferfile to avoid \savebuffer (only
> required to get the hash).

The SHA calculation isn't working properly because of a weird newline
issue. Try this:

   \setupinteraction[state=start]
   \setupinteractionscreen[option={attachment}]
   
   \startbuffer[test]
   just a test
   and another one
   \stopbuffer
   
   \starttext
   \startluacode
       require("util-sha")
   
       function sha256(str)
           return utilities.sha2.hash256(
               str:gsub(string.char(0x0D), string.char(0x0A))
           )
       end
   \stopluacode
   
   \def\shabuffer#1%
   {\cldcontext{sha256(buffers.raw("#1"))}}
   
   \def\shafile#1%
   {\cldcontext{sha256(io.loaddata("#1"))}}
   
   \shabuffer{test}
   
   \savebuffer[test][temporary-αβγ, prefix=no]
   
   \shafile{temporary-αβγ}
   
   \attachment[buffer=test, name=\shabuffer{test}, method=hidden]
   \stoptext
   
You can remove the "\savebuffer" and the "\shafile"; I just kept that in to
show that the two hashes are now the same.

-- Max
> 
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2022-09-23  4:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22 17:25 Pablo Rodriguez via ntg-context
2022-09-23  4:01 ` Max Chernoff via ntg-context [this message]
2022-09-23 15:06   ` Pablo Rodriguez via ntg-context
2022-09-25 17:59     ` Pablo Rodriguez via ntg-context
2022-09-26  0:05       ` Max Chernoff via ntg-context
2022-09-26  8:47         ` Hans Hagen via ntg-context
2022-09-26 23:01           ` Max Chernoff via ntg-context
2022-09-26 17:24         ` Pablo Rodriguez via ntg-context
2022-09-26 18:07           ` Hans Hagen via ntg-context

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=6ebdfae4256fb8b52e941e66ced7a5e7f4b016f8.camel@telus.net \
    --to=ntg-context@ntg.nl \
    --cc=mseven@telus.net \
    --cc=oinos@gmx.es \
    /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).