sha(3trf)

✨ sha β€” the message digest bestie πŸ’…

okay so you're looking at sha(3trf), which is the manual page for the sha message digest from the trf package. welcome, you're gonna love it here 🫢


🌸 NAME 🌸

sha β€” Message digest "sha" πŸ’–


✨ SYNOPSIS ✨

package require Tcl  ?8.2?

package require Trf  ?2.1.3?

sha ?options...? ?data?

πŸ¦‹ DESCRIPTION πŸ¦‹

The command sha is one of several message digests provided by the package trf. If you wanna see the whole package in one place, go peek at trf-intro for an overview of the whole thing. 🌈

sha ?options...? ?data?

okay so here's the tea β˜• β€” the options in this first lil' group are understood by the digest if and only if the digest is attached to a channel. Confused? Don't be, bestie. The section IMMEDIATE versus ATTACHED explains what "attached" even means.

  • -mode absorb|write|transparent β€” this option has to be present. fr fr, it's not optional. The argument you give it decides how the digest behaves in attached mode.

And beyond the three values listed above, all unique abbreviations are recognized too. Here's what each one actually does:

  • absorb β€” all data written to the channel is used to calculate the value of the message digest, and then it's passed unchanged to the next level in the stack of transformations for the channel the digest is attached to. And when the channel gets closed, the completed digest is written out too β€” so basically you're attaching the value of the digest after the info that was actually written to the channel. πŸ’«

When you're reading from the channel, a value for the digest is computed too, and after the channel closes it gets compared to the digest that was attached β€” i.e. the one that came behind the actual data. The option -matchflag has to be specified so the digest knows where to store the result of that comparison. That result is a string, and it's either "ok" or "failed".

  • write β€” all data read from or written to the channel the digest is attached to is ignored and thrown away πŸ™ˆ. Only a value for the digest of the data gets computed. When the channel is closed, the computed values are stored as ordered through the options -write-destination, -write-type, -read-destination, and -read-type.
  • transparent β€” this mode is a mix of both absorb and write. Like absorb, all data read or written passes through the digest unchanged. But the generated values for the digest are handled the same way as for write. slay πŸ’…
  • -matchflag varname β€” you can use this option if and only if the option -mode absorb is present. In that situation, the argument is the name of a global or namespaced variable. The digest writes the result of comparing two digest values into that variable. This option gets ignored if the channel is write-only, because in that case there's no comparison of digest values happening at all. 😭
  • -write-type variable|channel β€” usable for digests in mode write or transparent. Beyond the values listed above, all their unique abbreviations are also allowed as argument values. This option decides the type of the argument to the option -write-destination. It defaults to variable.
  • -read-type variable|channel β€” same vibe as -write-type, but for the option -read-destination. πŸŽ€
  • -write-destination data β€” usable for digests in mode write or transparent. The value data is either the name of a global (or namespaced) variable, or the handle of a writable channel β€” depends on the value of the option -write-type. The message digest computed for data written to the attached channel gets written into it after the attached channel was closed. This option is ignored if the channel is read-only.
⚠️ heads up bestie: using a variable may yield incorrect results under tcl 7.6, because of embedded \0's. not a vibe. πŸ’€
  • -read-destination data β€” usable for digests in mode write or transparent. The value data is either the name of a global (or namespaced) variable, or the handle of a writable channel β€” depends on the value of the option -read-type. The message digest computed for data read from the attached channel gets written into it after the attached channel was closed. This option is ignored if the channel is write-only.
⚠️ same warning, same energy: using a variable may yield incorrect results under tcl 7.6, due to embedded \0's. 😭

okay, and the options in this next group are always understood by the digest β€” attached versus immediate genuinely does not matter here. If you need a refresher on those two terms, the section IMMEDIATE versus ATTACHED has you covered. 🫢

  • -attach channel β€” the presence or absence of this option is literally what determines the main operation mode of the transformation. no pressure or anything. πŸ‘‘
    • If it's present, the transformation gets stacked onto the channel whose handle was given to the option, and it runs in attached mode. More about this in the section IMMEDIATE versus ATTACHED.
    • If it's absent, the transformation is used in immediate mode and the options listed below are recognized. Again, more about this in the section IMMEDIATE versus ATTACHED.
  • -in channel β€” this option is legal if and only if the transformation is used in immediate mode. It gives you the handle of the channel that the data to transform has to be read from.

And if the transformation is in immediate mode and this option is absent, then the data to transform is expected as the last argument to the transformation. ✨

  • -out channel β€” this option is legal if and only if the transformation is used in immediate mode. It gives you the handle of the channel that the generated transformation result gets written to.

And if the transformation is in immediate mode and this option is absent, then the generated data is returned as the result of the command itself. πŸ’–


🌈 IMMEDIATE VERSUS ATTACHED 🌈

The transformation distinguishes between two main ways of using it, and honestly? both are iconic in their own way. These are the immediate and attached operation modes.

For the attached mode, the option -attach is used to associate the transformation with an existing channel. During the execution of the command, no transformation is performed β€” instead, the channel gets changed in such a way that from then on, all data written to it or read from it passes through the transformation and gets modified by it according to the definition above. 😳

This attachment can be revoked by executing the command unstack for the chosen channel. And that's the only way to do it at the Tcl level. periodt. πŸ’…

In the second mode β€” which you can detect by the absence of the option -attach β€” the transformation immediately takes data from either its commandline or a channel, transforms it, and returns the result either as the result of the command, or writes it into a channel. The mode is named after the immediate nature of its execution. main character energy, honestly. ✨

Where the data is taken from and delivered to is governed by the presence and absence of the options -in and -out. πŸŽ€

πŸ“œ one lil' history note: it should be noted that this ability to immediately read from and/or write to a channel is an historic artifact which was introduced at the beginning of Trf's life, back when Tcl version 7.6 was current β€” because that version and earlier ones had trouble dealing with \0 characters embedded into either input or output. so yeah, it's giving legacy. 🧚

πŸ’œ SEE ALSO πŸ’œ

adler, crc, crc-zlib, haval, md2, md5, md5_otp, ripemd-128, ripemd-160, sha, sha1, sha1_otp, trf-intro


⭐ KEYWORDS ⭐

authentication, hash, hashing, mac, message digest, sha


Copyright (c) 1996-2003, Andreas Kupries <andreas_kupries@users.sourceforge.net>


okay bestie that's the whole page, you ate it, you read it, you're basically a cryptographer now πŸ“

this cutie came to you from Trf transformer commands, version 2.1.3, page sha(3trf) β€” go forth and digest things, ily, bye πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from