bitblob 2.2.0

A small library to represent hash types as value types

To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:


DUB Package codecov

A lightweight wrapper to represent hashes as value types.


/// Alias for a 256 bits / 32 byte hash type
alias Hash = BitBlob!32;

/// Used in the following tests
enum BTCGenesisStr = `0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f`;

// Most functions are anotated as `nothrow`/`@nogc`/`pure`/`@safe`,
// except for the two `toString` overloads
@nogc @safe pure nothrow unittest
    import std.digest.sha;
    // Can be initialized from an `ubyte[32]`
    // (or `ubyte[]` of length 32)
    const Hash fromSha = sha256Of("Hello World");

    // Or from a string
    const Hash genesis = BTCGenesisStr;


    ubyte[5] empty;
    assert(Hash.init < genesis);
    assert(genesis[0 .. 5] == empty);

// This cannot be nothrow/@nogc because format is not allocated as such
// However, Bitblob has tests that it does not allocate
    // This does not allocate
    char[Hash.StringBufferSize] buff;
    const Hash genesis = BTCGenesisStr;
    formattedWrite(buff[], "%s", genesis);
    assert(buff[] == BTCGenesisStr);

Note on design

BitBlob is intended for convenient representation of fully computed / finalized hashes.

String representation, comparison, and seamless conversion from string or binary representation are the focus.

Byte-level manipulation of the underlying data is not prefered, although possible through opSlice.

  • Mathias 'Geod24' Lang
2.3.0 2021-Dec-08
2.2.0 2021-Apr-08
2.1.0 2021-Mar-16
2.0.0 2021-Mar-12
1.1.4 2019-Aug-30
Show all 12 versions
Download Stats:
  • 0 downloads today

  • 5 downloads this week

  • 45 downloads this month

  • 4535 downloads total

Short URL: