query
On this page

hashString

lib.hashString

Primop
Docs pulled from | This Revision | 15 minutes ago


Nix manual

Takes 2 arguments

type, s

Return a base-16 representation of the cryptographic hash of string s. The hash algorithm specified by type must be one of "md5", "sha1", "sha256" or "sha512".

Noogle detected

Aliases

Detected Type
hashString :: String -> String -> String

Implementation

This function is implemented in c++ and is part of the native nix runtime.

src/libexpr/primops.cc:4688

static void prim_hashString(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
    auto algo =
        state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.hashString");
    std::optional<HashAlgorithm> ha = parseHashAlgo(algo);
    if (!ha)
        state.error<EvalError>("unknown hash algorithm '%1%'", algo).atPos(pos).debugThrow();

    NixStringContext context; // discarded
    auto s =
        state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.hashString");

    v.mkString(hashString(*ha, s).to_string(HashFormat::Base16, false), state.mem);
}

Implementation

The following is the current implementation of this function.

hashString