aboutsummaryrefslogtreecommitdiff
path: root/nix/libutil/hash.hh
blob: 6b5e47cd8a29c1ad8fb5c5939aa1392b0b09372b (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once

#include "types.hh"
#include "serialise.hh"


namespace nix {


typedef enum { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 } HashType;


const int md5HashSize = 16;
const int sha1HashSize = 20;
const int sha256HashSize = 32;
const int sha512HashSize = 64;

extern const string base32Chars;


struct Hash
{
    static const unsigned int maxHashSize = 64;
    unsigned int hashSize;
    unsigned char hash[maxHashSize];

    HashType type;

    /* Create an unusable hash object. */
    Hash();

    /* Create a zero-filled hash object. */
    Hash(HashType type);

    /* Check whether two hash are equal. */
    bool operator == (const Hash & h2) const;

    /* Check whether two hash are not equal. */
    bool operator != (const Hash & h2) const;

    /* For sorting. */
    bool operator < (const Hash & h) const;
};


/* Convert a hash to a hexadecimal representation. */
string printHash(const Hash & hash);

/* Parse a hexadecimal representation of a hash code. */
Hash parseHash(HashType ht, const string & s);

/* Returns the length of a base-32 hash representation. */
unsigned int hashLength32(const Hash & hash);

/* Convert a hash to a base-32 representation. */
string printHash32(const Hash & hash);

/* Print a hash in base-16 if it's MD5, or base-32 otherwise. */
string printHash16or32(const Hash & hash);

/* Parse a base-32 representation of a hash code. */
Hash parseHash32(HashType ht, const string & s);

/* Parse a base-16 or base-32 representation of a hash code. */
Hash parseHash16or32(HashType ht, const string & s);

/* Verify that the given string is a valid hash code. */
bool isHash(const string & s);

/* Compute the hash of the given string. */
Hash hashString(HashType ht, const string & s);

/* Compute the hash of the given file. */
Hash hashFile(HashType ht, const Path & path);

/* Compute the hash of the given path.  The hash is defined as
   (essentially) hashString(ht, dumpPath(path)). */
struct PathFilter;
extern PathFilter defaultPathFilter;
typedef std::pair<Hash, unsigned long long> HashResult;
HashResult hashPath(HashType ht, const Path & path,
    PathFilter & filter = defaultPathFilter);

/* Compress a hash to the specified number of bytes by cyclically
   XORing bytes together. */
Hash compressHash(const Hash & hash, unsigned int newSize);

/* Parse a string representing a hash type. */
HashType parseHashType(const string & s);

/* And the reverse. */
string printHashType(HashType ht);


struct Ctx;

class HashSink : public BufferedSink
{
private:
    HashType ht;
    Ctx * ctx;
    unsigned long long bytes;

public:
    HashSink(HashType ht);
    HashSink(const HashSink & h);
    ~HashSink();
    void write(const unsigned char * data, size_t len);
    HashResult finish();
    HashResult currentHash();
};


}
mmit/gnu/packages/textutils.scm?id=dbf3b5daf536c2dd73f6ca2d147a6daa6f259f5b'>gnu: Remove go-golang-org-x-net-html....golang.org/x/net is distributed as a single module according to provided go.mod file. This changes remove the last reference to golang.org/x/net/html. * gnu/packages/golang-build.scm (go-golang-org-x-net) [propagated-inputs]: Add go-golang-org-x-sys, go-golang-org-x-term and go-golang-org-x-text. (go-golang-org-x-net-html): Remove variable. * gnu/packages/version-control.scm (ghq) [inputs]: Remove go-golang-org-x-net-html. Add go-golang-org-x-net. * gnu/packages/textutils.scm (vale) [inputs]: Remove go-golang-org-x-net-html. Add go-golang-org-x-net. Change-Id: Ic275f2f7ccd145edfd376d65bd24599a550e849a Sharlatan Hellseher 2024-05-14gnu: utf8proc: fix cross-compilation....* gnu/packages/textutils.scm (utf8proc): fix cross-compilation. [arguments]<#:make-flags>: Use CC-FOR-TARGET. <#:phases>: When cross-compilation, Get test data from native-inputs. Change-Id: I42699e62f28585cc215a8843b5daad9c52af44c9 Zheng Junjie 2024-04-12gnu: go-github-com-gobwas-glob: Move to golang-xyz....* gnu/packages/syncthing.scm (go-github-com-gobwas-glob): Move from here ... * gnu/packages/golang-xyz.scm: ... to here. * gnu/packages/textutils.scm: Remove (gnu packages syncthing) module. Change-Id: I131830e6edcdb666aeb3cd9bbdf6982df938ccd4 Sharlatan Hellseher 2024-04-09gnu: vale: Unbundle more packages....* gnu/packages/textutils.scm (vale): [source]: Remove more vendored modules. [native-inputs]: Add go-github-com-fatih-color, go-github-com-gobwas-glob, go-github-com-mitchellh-go-homedir, go-github-com-yuin-goldmark, go-golang-org-x-net-html, go-gopkg-in-ini-v1, and go-gopkg-in-yaml-v2. Change-Id: Ia7e87888fd286b54157382d01c8a3ca8475e3cb0 Sharlatan Hellseher 2024-04-09gnu: vale: Refresh package style....* gnu/packages/textutils.scm (vale): [source]: Remove some packaged module from vendor. [arguments]: Move above native-inputs. Swap to list style, do not install source. [description]: Fix indentation. Change-Id: I3efbffc74e76ba2c88467bfc7e79b06d4d05ee18 Sharlatan Hellseher 2024-04-09gnu: csvdiff: Adjust inputs....* gnu/packages/textutils.scm (csvdiff): Adjust inputs. [arguments]: Swap to list style, do not install sources. [native-inputs]: Swap from propagated-inputs to native-inputs. Remove indirect Golang modules: go-github-com-mattn-go-colorable, go-github-com-oneofone-xxhash, go-github-com-spaolacci-murmur3, and go-golang-org-x-sys. Change-Id: I903d8869b8c468c15a2e78a565bcaaf34594e34b Sharlatan Hellseher 2024-04-09gnu: Add miller....* gnu/packages/textutils.scm (miller): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: Ic381b5e28e561382c49f843aa1baadf2d2d6f294 Wilko Meyer 2024-04-06gnu: go-github-com-mattn-go-colorable: Move to golang-xyz....* gnu/packages/golang.scm (go-github-com-mattn-go-colorable): Move from here ... * gnu/packages/golang-xyz.scm: ... to here. * gnu/packages/textutils.scm: Add (gnu packages golang-xyz) module. Change-Id: I7a9763ebd498e071b17abbde838a7cbf8fc891de Sharlatan Hellseher 2024-04-05gnu: Add java-autocomplete....* gnu/packages/textutils.scm (java-autocomplete): New variable. Change-Id: Ied62d45ab53fca84d448652cce5e82d971f41703 Ricardo Wurmus 2024-04-05gnu: java-rsyntaxtextarea: Update to 3.4.0....* gnu/packages/textutils.scm (java-rsyntaxtextarea): Update to 3.4.0. [arguments]: Disable tests; provide source-dir and test-dir; disable 'start-xorg-server phase. [native-inputs]: Remove java-junit. Change-Id: I5fbf635bc4f0a6a13ed2db4f42080ea5640f4781 Ricardo Wurmus 2024-04-01gnu: java-rsyntaxtextarea: Install resources....* gnu/packages/textutils.scm (java-rsyntaxtextarea)[arguments]: Enable tests; install resources. [native-inputs]: Add xorg-server-for-tests. Change-Id: If7c89bc6a38058b9cccd74012fa9b5ba14d560d6 Ricardo Wurmus 2024-02-13gnu: go-golang-org-x-sys: Move to golang-build....* gnu/packages/golang.scm (go-golang-org-x-sys): Move from here ... * gnu/packages/golang-build.scm: ... to here. * gnu/packages/curl.scm: Add (gnu packages golang-build) module. * gnu/packages/databases.scm: As above. * gnu/packages/docker.scm: As above. * gnu/packages/golang-build.scm: As above. * gnu/packages/golang.scm: As above. * gnu/packages/irc.scm: As above. * gnu/packages/linux.scm: As above. * gnu/packages/password-utils.scm: As above. * gnu/packages/syncthing.scm: As above. * gnu/packages/textutils.scm: As above. * gnu/packages/vpn.scm: As above. * gnu/packages/weather.scm: As above. * gnu/packages/web.scm: As above. Change-Id: I161e89cacb9aa87b4fbb643ecd9ad32cfe49c9d7 Sharlatan Hellseher 2024-02-09gnu: vale: Remove package labeles....* gnu/packages/textutils.scm (vale) [native-inputs]: Remove labeles. Change-Id: Id6ac7bcf26b90291b2ec9de18cde8078f6f8f115 Sharlatan Hellseher 2024-02-09gnu: Deprecate the go-github-com-errata-ai-vale variable....* gnu/packages/ipfs.scm (go-github-com-errata-ai-vale): Rename to "vale". (go-github-com-errata-ai-vale): Define as deprecated by "vale". Change-Id: I3c715a36295cd52e36b16e99f39455b7ad961743 Sharlatan Hellseher 2024-02-09gnu: packages: textuitils: Sort use-module alphabetically....* gnu/packages/textutils.scm: Sort use-module alphabetically to ease maintenance. Change-Id: Ia698a0b3e137ce2fc2f68d0206d209649acdad5e Sharlatan Hellseher 2024-02-09gnu: dos2unix: Update to 7.5.2....* gnu/packages/textutils.scm (dos2unix): Update to 7.5.2. Change-Id: I8b27da05c0780fe942fe19f00766cd2772c66bc0 Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Timotej Lazar 2024-01-28gnu: go-github-com-cespare-xxhash: Move to (gnu packages golang-crypto)....* gnu/packages/syncthing.scm (go-github-com-cespare-xxhash): Move from here ... * gnu/packages/golang-crypto.scm: ... to here. * gnu/packages/textutils.scm: Add (gnu packages golang-crypto) to used modules. Change-Id: Ic72cf6c4770cd3f03cc2e27c3455632ee16e7c09 Sharlatan Hellseher 2024-01-07gnu: txt2tags: Update to 3.9....* gnu/packages/textutils.scm (txt2tags): Update to 3.9. Change-Id: Ia825f5807c87941504feffdb317594f5b1fa62ef Signed-off-by: Mathieu Othacehe <othacehe@gnu.org> kiasoc5