std.digest

  • This module describes the digest APIs used in Phobos. All digests follow
  • these APIs. Additionally, this module contains useful helper methods which
  • can be used with every digest type. *

Category Functions
Template API isDigest  DigestType  hasPeek 

hasBlockSize  ExampleDigest  digest  hexDigest  makeDigest 

OOP API Digest 

Helper functions toHexString  secureEqual 
Implementation helpers digestLength  WrapperDigest 

  • APIs:
  • There are two APIs for digests: The template API and the OOP API. The template API uses structs
  • and template helpers like isDigest. The OOP API implements digests as classes inheriting
  • the Digest interface. All digests are named so that the template API struct is called "x"
  • and the OOP API class is called "xDigest". For example we have MD5 <--> MD5Digest,
  • CRC32 <--> CRC32Digest, etc.
  • The template API is slightly more efficient. It does not have to allocate memory dynamically,
  • all memory is allocated on the stack. The OOP API has to allocate in the finish method if no
  • buffer was provided. If you provide a buffer to the OOP APIs finish function, it doesn't allocate,
  • but the Digest classes still have to be created using new which allocates them using the GC.
  • The OOP API is useful to change the digest function and/or digest backend at 'runtime'. The benefit here
  • is that switching e.g. Phobos MD5Digest and an OpenSSLMD5Digest implementation is ABI compatible.
  • If just one specific digest type and backend is needed, the template API is usually a good fit.
  • In this simplest case, the template API can even be used without templates: Just use the "x" structs
  • directly.

    License

    Boost License 1.0.

    Authors

    Johannes Pfau
  • Source: std/digest/package.d
  • CTFE:
  • Digests do not work in CTFE
  • TODO:
  • Digesting single bits (as opposed to bytes) is not implemented. This will be done as another
  • template constraint helper (hasBitDigesting!T) and an additional interface (BitDigest)