9front - general discussion about 9front
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: [9front] Totp in factotum
Date: Sat, 18 Mar 2023 02:42:56 +0100	[thread overview]
Message-ID: <39F03A5EA54F3F163EE649177ED2359A@felloff.net> (raw)
In-Reply-To: <9544fd2c-2389-456e-a076-8fd7a4b5ce4e@sirjofri.de>

> I guess I need a heads up there. When decoding the base32 encoded binary data,
> how would I know how many bytes I need?
> Should I just assume that a buffer of length 1024 is enough,
> or count on dec32 to give me a result and allocate more memory if I need it?

from the manpage:

         Dec16, dec32 and dec64 return the number of bytes decoded or
          -1 if the decoding fails.  The decoding fails if the output
          buffer is not large enough or, for base 32, if the input
          buffer length is not a multiple of 8.

just using the return value and a fixed 1024 sized buffer is probably fine.
my concern was about the secret containing 0x00 bytes.

otherwise, you can estimate the size by taking the string length of
the input like (strlen(input)*5+8)/8 or something and allocate it.

> For compatibility, does it make sense to write my own enc32 encoding function,
> just in case the default changes?

there is a dec32x() function that you can pass a character converting
function wich maps the alphabet.

see the HISTORY section in the manpage, if they use RFC4648 then
you should be fine. it will break with labs plan9 tho as they still use
the custom plan9 alphabet by default and also have no dec32x() function.

     HISTORY
          In Jan 2018, base 32 encoding was changed from non-standard
          to standard RFC4648 alphabet.

          old: 23456789abcdefghijkmnpqrstuvwxyz

          new: ABCDEFGHIJKLMNOPQRSTUVWXYZ234567

--
cinap

  reply	other threads:[~2023-03-18  1:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16 19:08 [9front] Totp in factotum (advice and code) sirjofri
2023-03-16 19:51 ` [9front] Totp in factotum sirjofri
2023-03-17  9:48   ` cinap_lenrek
2023-03-17 16:43     ` sirjofri
2023-03-18  1:42       ` cinap_lenrek [this message]
2023-03-21 20:10 ` [9front] Re: Totp in factotum (advice and code) sirjofri
2023-04-05  7:08   ` sirjofri

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=39F03A5EA54F3F163EE649177ED2359A@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --cc=9front@9front.org \
    /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).