Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #257636

Re: sha256sum --text generating blank spaces and hyphens?

Path csiph.com!1.us.feeder.erje.net!3.us.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!bofh.it!news.nic.it!robomod
From Jeffrey Walton <noloader@gmail.com>
Newsgroups linux.debian.user
Subject Re: sha256sum --text generating blank spaces and hyphens?
Date Wed, 26 Apr 2023 18:00:01 +0200
Message-ID <GoPIJ-4GA4-3@gated-at.bofh.it> (permalink)
References <GoI4y-4BMS-5@gated-at.bofh.it> <GoI4y-4BMS-3@gated-at.bofh.it>
X-Mailbox-Line From debian-user-request@lists.debian.org Wed Apr 26 15:53:53 2023
Old-Return-Path <noloader@gmail.com>
X-Amavis-Spam-Status No, score=-6.858 tagged_above=-10000 required=5.3 tests=[BAYES_00=-2, DIGITS_LETTERS=1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FOURLA=0.1, FREEMAIL_FROM=0.001, LDO_WHITELIST=-5, MD5_SHA1_SUM=-1, MURPHY_SCAM1=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SARE_TOCC_CONS6s=0.141] autolearn=ham autolearn_force=no
X-Policyd-Weight using cached result; rate: -5.5
X-Gm-Message-State AC+VfDzLO6XFZ12l18wwQbegaMiL0OOQBsvqdoeQLG8TV/Sczl2MI7FY Fl+vnFpRf1j5HhlXCUcEsLwd4AkFLrZ9pGIQc6vwHcplvN4=
X-Google-SMTP-Source ACHHUZ5hvfqwgivITizf8V19sFD0xaxQIhWhOek9eDZ9NN7/iMItfGfzoGHqj5Toklt2PkpfkF6fUijWjmso5+peumA=
X-Received by 2002:aca:f0d4:0:b0:389:5120:9506 with SMTP id o203-20020acaf0d4000000b0038951209506mr1313321oih.8.1682524409852; Wed, 26 Apr 2023 08:53:29 -0700 (PDT)
MIME-Version 1.0
Reply-To noloader@gmail.com
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
X-Mailing-List <debian-user@lists.debian.org> archive/latest/798988
List-ID <debian-user.lists.debian.org>
List-URL <https://lists.debian.org/debian-user/>
List-Archive https://lists.debian.org/msgid-search/CAH8yC8n_fYaVEHT91aqvSgOp9wkGgLcG0fHzYp-1hP5wf8Rwaw@mail.gmail.com
Approved robomod@news.nic.it
Lines 85
Organization linux.* mail to news gateway
Sender robomod@news.nic.it
X-Original-Cc debian-user@lists.debian.org
X-Original-Date Wed, 26 Apr 2023 11:53:18 -0400
X-Original-Message-ID <CAH8yC8n_fYaVEHT91aqvSgOp9wkGgLcG0fHzYp-1hP5wf8Rwaw@mail.gmail.com>
X-Original-References <CAFakBwhzr9e0SbwOKxb8V4eCumPOGK2FBtwWM7pPHSKF51h=fQ@mail.gmail.com> <CAFakBwj6a0N7+3hHQSX_SfQKAL4a-Peifyx9tTPZWqDLR1KS+w@mail.gmail.com>
Xref csiph.com linux.debian.user:257636

Show key headers only | View raw


On Wed, Apr 26, 2023 at 3:42 AM Albretch Mueller <lbrtchx@gmail.com> wrote:
>
>  This is not a debian question per se (more like a Linux bash one),
> but I wasn't able to find an answer on the Internet.
>
>  Here is first the problem I am having before you start reading a
> conspiracy theory into it ;-)
>
>  I need to somehow map URL on the web to a local file, but you can't
> do that for two main reasons:
>
>  1) URLs are free text
>  2) which people take to their heart's content.
>
>  Take for example:
>
>  https://dokumen.pub/qdownload/nietzsche-und-der-deutsche-geist-band-4-ausbreitung-und-wirkung-des-nietzscheschen-werkes-im-deutschen-sprachraum-bis-zum-ende-des-zweiten-weltkrieges-ein-schrifttumsverzeichnis-der-jahre-1867-1945-ergnzungen-berichtigungen-und-gesamtverzeichnisse-zu-den-bnden-i-iii-9783110202861-9783110189865-3110189860.html
>
>  that file and the pdf you would download I need to map to a local
> directory looking like: ... /pub/dokumen/qdownload/ ...
>
>  but the file name (excluding the extension) is 306 characters long,
> which Windows NTFS would not swallow. There may be also funky rules
> regarding character sets and where in a string certain chars may be
> used; so, as a way to work around those kinds of problems I:
>
>  a) encode the string name as base64
>  b) calculate the sha256sum of §a
>  c) use §b as file name (of course, leaving the original extension as it is)
>  d) include a "§b_file_name.txt" plain text file decriptor which only
> content is the actual prehash name of that file.
>
>
>  https://dokumen.pub/qdownload/nietzsche-und-der-deutsche-geist-band-4-ausbreitung-und-wirkung-des-nietzscheschen-werkes-im-deutschen-sprachraum-bis-zum-ende-des-zweiten-weltkrieges-ein-schrifttumsverzeichnis-der-jahre-1867-1945-ergnzungen-berichtigungen-und-gesamtverzeichnisse-zu-den-bnden-i-iii-9783110202861-9783110189865-3110189860.html
>  _TXT="nietzsche-und-der-deutsche-geist-band-4-ausbreitung-und-wirkung-des-nietzscheschen-werkes-im-deutschen-sprachraum-bis-zum-ende-des-zweiten-weltkrieges-ein-schrifttumsverzeichnis-der-jahre-1867-1945-ergnzungen-berichtigungen-und-gesamtverzeichnisse-zu-den-bnden-i-iii-9783110202861-9783110189865-3110189860"
>  _B64TXTENC=$(printf '%s' "${_TXT}" | base64 )
>  echo "// __ \$_B64TXTENC: |${_B64TXTENC}|"
>  _B64TXTDEC=$(printf '%s' "${_B64TXTENC}" | base64 --decode)
>  echo "// __ \$_B64TXTDEC: |${_B64TXTDEC}|"
>  if [[ "${_TXT}" == "${_B64TXTDEC}" ]]; then
>   echo "// __ [[ \${_TXT} == \${_B64TXTDEC} ]]: |${_TXT}|"
>   _SHA256=$(printf '%s' "${_TXT}" | sha256sum --text )
>   echo "// __ \$_SHA256: |${_SHA256}|"
>  fi
>
> // __ $_SHA256:
> |7d5895cb24ab49692a8ad495e036074fec8e61b22040544f02a9b69c926dbdeb  -|
>
>  I am trying to avoid funky characters and sha256sum --text still
> generates them!?!
>
>  I work like this because I need replicate the original URL as a local
> path in a way that would be compatible any file system.
>
>  Do you know of a better way to deal with such issues?

There's no guarantee a URL will map onto a filesystem. I seem to
recall Stunnel tried to do that in a caching mode, but it had weird
corner cases. (In addition to problems with filesystems that had
character set and path limitations).

I think your best bet is to digest the URL into a representation. I
suggest using SipHash+Base64 or Base64URL. SipHash provides collision
resistance, a uniform distribution, and its fast. SipHash has a very
good pedigree since it was designed by Jean-Philippe Aumasson and
Daniel J. Bernstein. The final Base64 or Base64URL encoding ensures
you stay within printable character range without reserved file system
characters.

Jeff

Back to linux.debian.user | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

sha256sum --text generating blank spaces and hyphens? Albretch Mueller <lbrtchx@gmail.com> - 2023-04-26 09:50 +0200
  Re: sha256sum --text generating blank spaces and hyphens? <tomas@tuxteam.de> - 2023-04-26 10:20 +0200
    Re: sha256sum --text generating blank spaces and hyphens? Albretch Mueller <lbrtchx@gmail.com> - 2023-04-26 16:40 +0200
      Re: sha256sum --text generating blank spaces and hyphens? Nicolas George <george@nsup.org> - 2023-04-26 16:50 +0200
        Re: sha256sum --text generating blank spaces and hyphens? Max Nikulin <manikulin@gmail.com> - 2023-04-28 04:30 +0200
          Re: sha256sum --text generating blank spaces and hyphens? Nicolas George <george@nsup.org> - 2023-04-28 10:10 +0200
            Re: sha256sum --text generating blank spaces and hyphens? Max Nikulin <manikulin@gmail.com> - 2023-04-28 18:50 +0200
              Re: sha256sum --text generating blank spaces and hyphens? Nicolas George <george@nsup.org> - 2023-04-29 11:00 +0200
                Re: sha256sum --text generating blank spaces and hyphens? Max Nikulin <manikulin@gmail.com> - 2023-04-29 14:20 +0200
                Re: sha256sum --text generating blank spaces and hyphens? Nicolas George <george@nsup.org> - 2023-04-29 14:30 +0200
      Re: sha256sum --text generating blank spaces and hyphens? Dan Ritter <dsr@randomstring.org> - 2023-04-26 17:10 +0200
      Re: sha256sum --text generating blank spaces and hyphens? David Wright <deblis@lionunicorn.co.uk> - 2023-04-26 17:10 +0200
      Re: sha256sum --text generating blank spaces and hyphens? "Thomas Schmitt" <scdbackup@gmx.net> - 2023-04-26 17:10 +0200
      Re: sha256sum --text generating blank spaces and hyphens? <tomas@tuxteam.de> - 2023-04-26 19:00 +0200
        Re: sha256sum --text generating blank spaces and hyphens? Albretch Mueller <lbrtchx@gmail.com> - 2023-04-26 22:40 +0200
          Re: sha256sum --text generating blank spaces and hyphens? Albretch Mueller <lbrtchx@gmail.com> - 2023-04-26 23:10 +0200
          Re: sha256sum --text generating blank spaces and hyphens? Andy Smith <andy@strugglers.net> - 2023-04-26 23:50 +0200
  Re: sha256sum --text generating blank spaces and hyphens? Andy Smith <andy@strugglers.net> - 2023-04-26 12:50 +0200
  Re: sha256sum --text generating blank spaces and hyphens? Jeffrey Walton <noloader@gmail.com> - 2023-04-26 18:00 +0200
  Re: sha256sum --text generating blank spaces and hyphens? David Christensen <dpchrist@holgerdanske.com> - 2023-04-27 00:50 +0200
    Re: sha256sum --text generating blank spaces and hyphens? Nicolas George <george@nsup.org> - 2023-04-27 00:50 +0200
      Re: sha256sum --text generating blank spaces and hyphens? David Christensen <dpchrist@holgerdanske.com> - 2023-04-27 06:10 +0200
        Re: sha256sum --text generating blank spaces and hyphens? Max Nikulin <manikulin@gmail.com> - 2023-04-27 08:00 +0200
          Re: sha256sum --text generating blank spaces and hyphens? Albretch Mueller <lbrtchx@gmail.com> - 2023-04-27 09:30 +0200
        Re: sha256sum --text generating blank spaces and hyphens? Nicolas George <george@nsup.org> - 2023-04-27 10:10 +0200
          Re: sha256sum --text generating blank spaces and hyphens? David Christensen <dpchrist@holgerdanske.com> - 2023-04-27 17:20 +0200
            Re: sha256sum --text generating blank spaces and hyphens? Albretch Mueller <lbrtchx@gmail.com> - 2023-05-02 02:10 +0200
    Re: sha256sum --text generating blank spaces and hyphens? Albretch Mueller <lbrtchx@gmail.com> - 2023-04-27 01:30 +0200
      Re: sha256sum --text generating blank spaces and hyphens? David Christensen <dpchrist@holgerdanske.com> - 2023-04-27 06:30 +0200

csiph-web