Documentation
¶
Overview ¶
Package digest is a pure-Go (no cgo) reimplementation of Ruby's Digest standard library — the deterministic, interpreter-independent message-digest core of MRI 4.0.5's digest, digest/md5, digest/sha1, digest/sha2, digest/rmd160 and digest/bubblebabble.
Each algorithm (MD5, SHA1, SHA256, SHA384, SHA512, RMD160) is exposed as an incremental Digest — an accumulating hasher fed through Update and read with Finish / HexFinish / Base64Finish — mirroring Ruby's Digest::Instance protocol (#update / #<< / #digest / #hexdigest / #base64digest / #reset). The class-level one-shots Digest::SHA256.digest(s) / .hexdigest(s) / .base64digest(s) map to Sum / HexSum / Base64Sum, and the digest/bubblebabble extension maps to BubbleBabble.
The computation is backed by Go's crypto/* (MD5/SHA1/SHA2) and golang.org/x/crypto/ripemd160 (RMD160) — both pure Go — so every digest is byte-identical to MRI's, with no Ruby runtime and no cgo. The one-shot and finish paths sum and hex/Base64-encode through stack buffers so a full hexdigest allocates only its result string (see fastSum / hexEncode). It is the digest backend for go-embedded-ruby, but is a standalone, reusable module, a sibling of go-ruby-regexp (the Onigmo engine), go-ruby-erb (the ERB compiler) and go-ruby-yaml (the Psych emitter/loader).
Index ¶
- func Base64Sum(name string, data []byte) (string, error)
- func Base64SumFile(name, path string) (string, error)
- func BubbleBabble(data []byte) string
- func HexSum(name string, data []byte) (string, error)
- func HexSumFile(name, path string) (string, error)
- func Sum(name string, data []byte) ([]byte, error)
- func SumBubbleBabble(name string, data []byte) (string, error)
- func SumFile(name, path string) ([]byte, error)
- type Digest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64Sum ¶
Base64Sum is the class one-shot Digest::ALGO.base64digest(data), with the same stack-buffered single-allocation strategy as HexSum.
func Base64SumFile ¶
Base64SumFile is Digest::ALGO.file(path).base64digest.
func BubbleBabble ¶
BubbleBabble encodes data with the Bubble Babble algorithm, the deterministic pronounceable digest format used by Digest.bubblebabble. The output begins and ends with 'x' and reads as a string of CV/CVC tuples separated by hyphens — the same bytes MRI emits.
func HexSum ¶
HexSum is the class one-shot Digest::ALGO.hexdigest(data). This is the exact Go analogue of Ruby's Digest::SHA256.hexdigest(s) — the hot path the parity benchmark exercises. For the crypto algorithms it sums into a stack array and hex-encodes (inline, so the array never escapes) into a second stack buffer, leaving the returned string as the sole allocation.
func HexSumFile ¶
HexSumFile is Digest::ALGO.file(path).hexdigest.
func Sum ¶
Sum is the binary class one-shot Digest::ALGO.digest(data): the raw digest of data under the named algorithm. For the built-in crypto algorithms it uses the allocation-free stack hasher (fastSum), copying out only the exact-length result slice it must return; RMD160 falls back to the streaming hasher.
func SumBubbleBabble ¶
SumBubbleBabble is the class/instance one-shot Digest::ALGO.bubblebabble(data) and #bubblebabble: the Bubble Babble encoding of the algorithm's binary digest of data (not of data itself).
Types ¶
type Digest ¶
type Digest interface {
// Update appends data to the message being digested.
Update(data []byte)
// Reset discards the accumulated state, as if freshly constructed.
Reset()
// Finish returns the binary digest of the bytes fed so far.
Finish() []byte
// HexFinish returns the lowercase hexadecimal digest.
HexFinish() string
// Base64Finish returns the standard-Base64 (padded) digest.
Base64Finish() string
// BlockLength is the algorithm's internal block size in bytes
// (Digest::Instance#block_length).
BlockLength() int
// DigestLength is the size of the produced digest in bytes
// (Digest::Instance#digest_length / #length / #size).
DigestLength() int
}
Digest is an incremental message-digest hasher, the Go analogue of Ruby's Digest::Instance protocol. Update feeds bytes (Digest::Instance#update / #<<), Reset returns the hasher to its initial state (#reset), and the three Finish methods read the running digest in binary, hex and Base64 form (#digest, #hexdigest, #base64digest). Reading the digest does not reset it, matching MRI's no-argument finalizers.
