aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.hh
AgeCommit message (Collapse)Author
2022-04-07don't assume that rev is a SHA1 hashKasper Gałkowski
This was a problem when writing a fetcher that uses e.g. sha256 hashes for revisions. This doesn't actually do anything new, but allows for creating such fetchers in the future (perhaps when support for Git's SHA256 object format gains more popularity).
2022-02-25Remove std::string alias (for real this time)Eelco Dolstra
Also use std::string_view in a few more places.
2022-01-27return string_views from forceString*pennae
once a string has been forced we already have dynamic storage allocated for it, so we can easily reuse that storage instead of copying.
2020-12-02Sink: Use std::string_viewEelco Dolstra
2020-08-05Remove Hash::operator bool ()Carlo Nucera
Since the hash is not optional anymore
2020-08-05Add Hash::dummy to signal default valueCarlo Nucera
We did this in the same spirit of the dummy value that's present in libstore/path.hh
2020-08-01Embelish documentation of new Hash functionsJohn Ericson
2020-08-01Convert to C-style commentsJohn Ericson
2020-07-30Merge branch 'master' of github.com:NixOS/nix into better-ca-parse-errorsCarlo Nucera
2020-07-30unsigned long long -> uint64_tEelco Dolstra
2020-07-16Merge branch 'hash-always-has-type' of github.com:obsidiansystems/nix into ↵John Ericson
better-ca-parse-errors
2020-07-16Merge remote-tracking branch 'upstream/master' into hash-always-has-typeJohn Ericson
2020-07-02Write the implementation for parseNonSRIUnprefixedCarlo Nucera
2020-07-02Rename fromSRI to parseSRI for constistencyCarlo Nucera
2020-07-02Get rid of the std::pairCarlo Nucera
2020-07-01Rename two hash constructors to proper functionsCarlo Nucera
2020-07-01Inline Hash::init()Carlo Nucera
2020-07-01Correct FIXMEs in libfetchersCarlo Nucera
2020-07-01Fixed build, we still have test errorsCarlo Nucera
2020-06-30WIP initial designCarlo Nucera
2020-06-29Merge remote-tracking branch 'upstream/master' into hash-always-has-typeJohn Ericson
2020-06-26Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2020-06-25Fix empty std::optional dereference in writeDerivation()Eelco Dolstra
https://hydra.nixos.org/build/123017579
2020-06-19WIP: Make Hash always store a valid hash typeJohn Ericson
2020-06-18Revert the `enum struct` changeJohn Ericson
Not a regular git revert as there have been many merges and things.
2020-06-18Merge branch 'enum-class' into no-hash-type-unknownJohn Ericson
2020-06-18Merge remote-tracking branch 'upstream/master' into enum-classJohn Ericson
2020-06-17Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2020-06-12Use `std::string_view` in a few more placesJohn Ericson
2020-06-12Merge pull request #3674 from matthewbauer/allow-empty-hash2Eelco Dolstra
Allow empty hash in derivations
2020-06-12Add newHashAllowEmpty helper functionMatthew Bauer
This replaces the copy&paste with a helper function in hash.hh.
2020-06-03libutils/hash: remove default encodingzimbatm
This will make it easier to reason about the hash encoding and switch to SRI everywhere where possible.
2020-06-02Remove `HashType::Unknown`John Ericson
Instead, `Hash` uses `std::optional<HashType>`. In the future, we may also make `Hash` itself require a known hash type, encoraging people to use `std::optional<Hash>` instead.
2020-05-10nix: Implement basic bash completionEelco Dolstra
2020-03-29Use `enum struct` and drop prefixesJohn Ericson
This does a few enums; the rest will be gotten in subsequent commits.
2020-03-24Misc changes from the flakes branchEelco Dolstra
2019-10-21Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2019-10-21Allow content-addressable paths to have referencesEelco Dolstra
This adds a command 'nix make-content-addressable' that rewrites the specified store paths into content-addressable paths. The advantage of such paths is that 1) they can be imported without signatures; 2) they can enable deduplication in cases where derivation changes do not cause output changes (apart from store path hashes). For example, $ nix make-content-addressable -r nixpkgs.cowsay rewrote '/nix/store/g1g31ah55xdia1jdqabv1imf6mcw0nb1-glibc-2.25-49' to '/nix/store/48jfj7bg78a8n4f2nhg269rgw1936vj4-glibc-2.25-49' ... rewrote '/nix/store/qbi6rzpk0bxjw8lw6azn2mc7ynnn455q-cowsay-3.03+dfsg1-16' to '/nix/store/iq6g2x4q62xp7y7493bibx0qn5w7xz67-cowsay-3.03+dfsg1-16' We can then copy the resulting closure to another store without signatures: $ nix copy --trusted-public-keys '' ---to ~/my-nix /nix/store/iq6g2x4q62xp7y7493bibx0qn5w7xz67-cowsay-3.03+dfsg1-16 In order to support self-references in content-addressable paths, these paths are hashed "modulo" self-references, meaning that self-references are zeroed out during hashing. Somewhat annoyingly, this means that the NAR hash stored in the Nix database is no longer necessarily equal to the output of "nix hash-path"; for content-addressable paths, you need to pass the --modulo flag: $ nix path-info --json /nix/store/iq6g2x4q62xp7y7493bibx0qn5w7xz67-cowsay-3.03+dfsg1-16 | jq -r .[].narHash sha256:0ri611gdilz2c9rsibqhsipbfs9vwcqvs811a52i2bnkhv7w9mgw $ nix hash-path --type sha256 --base32 /nix/store/iq6g2x4q62xp7y7493bibx0qn5w7xz67-cowsay-3.03+dfsg1-16 1ggznh07khq0hz6id09pqws3a8q9pn03ya3c03nwck1kwq8rclzs $ nix hash-path --type sha256 --base32 /nix/store/iq6g2x4q62xp7y7493bibx0qn5w7xz67-cowsay-3.03+dfsg1-16 --modulo iq6g2x4q62xp7y7493bibx0qn5w7xz67 0ri611gdilz2c9rsibqhsipbfs9vwcqvs811a52i2bnkhv7w9mgw
2019-04-19Clean up exportGit argument handlingEelco Dolstra
2018-12-13Support SRI hashesEelco Dolstra
SRI hashes (https://www.w3.org/TR/SRI/) combine the hash algorithm and a base-64 hash. This allows more concise and standard hash specifications. For example, instead of import <nix/fetchurl.nl> { url = https://nixos.org/releases/nix/nix-2.1.3/nix-2.1.3.tar.xz; sha256 = "5d22dad058d5c800d65a115f919da22938c50dd6ba98c5e3a183172d149840a4"; }; you can write import <nix/fetchurl.nl> { url = https://nixos.org/releases/nix/nix-2.1.3/nix-2.1.3.tar.xz; hash = "sha256-XSLa0FjVyADWWhFfkZ2iKTjFDda6mMXjoYMXLRSYQKQ="; }; In fixed-output derivations, the outputHashAlgo is no longer mandatory if outputHash specifies the hash (either as an SRI or in the old "<type>:<hash>" format). 'nix hash-{file,path}' now print hashes in SRI format by default. I also reverted them to use SHA-256 by default because that's what we're using most of the time in Nixpkgs. Suggested by @zimbatm.
2017-10-30builtins.fetchgit: Support importing a working treeEelco Dolstra
For example, you can write src = fetchgit ./.; and if ./. refers to an unclean working tree, that tree will be copied to the Nix store. This removes the need for "cleanSource".
2017-07-30Replace Unicode quotes in user-facing strings by ASCIIJörg Thalheim
Relevant RFC: NixOS/rfcs#4 $ ag -l | xargs sed -i -e "/\"/s/’/'/g;/\"/s/‘/'/g"
2017-07-04Support base-64 hashesEelco Dolstra
Also simplify the Hash API. Fixes #1437.
2016-04-20Cache path info lookups in SQLiteEelco Dolstra
This re-implements the binary cache database in C++, allowing it to be used by other Store backends, in particular the S3 backend.
2016-01-27Define HashType's size to allow it to be forward-declaredEelco Dolstra
2016-01-27Make hashLength32() a method of HashEelco Dolstra
2015-11-04Support SHA-512 hashesEelco Dolstra
Fixes #679. Note: on x86_64, SHA-512 is considerably faster than SHA-256 (198 MB/s versus 131 MB/s).
2012-10-23If hashes do not match, print them in base-32 for SHA-1/SHA-256Eelco Dolstra
Fixes #57.
2012-07-18Use "#pragma once" to prevent repeated header file inclusionEelco Dolstra
2011-12-15* Refactoring: move sink/source buffering into separate classes.Eelco Dolstra
* Buffer the HashSink. This speeds up hashing a bit because it prevents lots of calls to the hash update functions (e.g. nix-hash went from 9.3s to 8.7s of user time on the closure of my /var/run/current-system).