Digest32

Holds an N-bit digest (or any fixed-size bit sequence). This is the pure-Kotlin port of libtorrent's digest32<N> (sha1_hash.hpp). In libtorrent this is used for info-hashes, piece hashes, peer IDs, DHT node IDs, etc.

Backed by a ByteArray in big-endian (network) byte order, which is how all these values travel on the wire and in .torrent files. The type is immutable: every bit operation returns a fresh Digest32.

libtorrent fixes the width at compile time via the N template parameter; here the width is carried by the instance and the Sha1Hash/Sha256Hash aliases plus the sha1/sha256 factories document intent at call sites.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val size: Int

Size of the digest in bytes.

Functions

Link copied to clipboard
infix fun and(o: Digest32): Digest32
Link copied to clipboard
open operator override fun compareTo(other: Digest32): Int

Unsigned lexicographic comparison, MSB first. libtorrent reaches the same ordering by interpreting each 32-bit word in network byte order; on a byte-backed digest that is simply comparing the bytes as unsigned values.

Link copied to clipboard

Number of leading zero bits, counted MSB first. Used by the DHT.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
operator fun get(i: Int): Int

Returns the unsigned value of byte i (0..255).

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun inv(): Digest32

Bit-wise NOT: every bit flipped.

Link copied to clipboard

True if every byte is zero. This is the additive identity and the "unset" sentinel.

Link copied to clipboard
infix fun or(o: Digest32): Digest32
Link copied to clipboard
fun shl(bits: Int): Digest32

Shift the whole digest left by bits, zero-filling the low end.

Link copied to clipboard
fun shr(bits: Int): Digest32

Shift the whole digest right by bits, zero-filling the high end.

Link copied to clipboard

A defensive copy of the raw bytes, big-endian.

Link copied to clipboard
fun toHex(): String

The 2*size lowercase hex representation (40 chars for SHA-1, 64 for SHA-256).

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
infix fun xor(o: Digest32): Digest32