From 2fcf2d0d20f7e67a80c2cb5b2d0a437faed6efb7 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Thu, 23 Jul 2020 17:18:00 -0400 Subject: refactor(3p/nix): Remove custom base64 implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the custom, rather questionable base64 implementation with absl::Base64{Une,E}scape. To make sure that the custom implementation was doing the same thing I've also added a test covering nix::Hash::to_string, which was one function that used it - the test passed prior to the replacement, and continued to pass afterwards. The previous base64Decode function threw an exception on failure - to avoid going too far down the rabbit hole I've replicated that functionality at all call sites, but this should be replaced with more sensible error handling such as StatusOr eventually. Also, before this change: ❯ nix eval -f . users.tazjin.emacs.outPath "/nix/store/g6ri2q8nra96ix20bcsc734r1yyaylb1-tazjins-emacs" And after: ❯ ./result/bin/nix eval -f . users.tazjin.emacs.outPath "/nix/store/g6ri2q8nra96ix20bcsc734r1yyaylb1-tazjins-emacs" Change-Id: Id292ffbb82fe808f3f1b34670afbe7b8c13ad615 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1385 Reviewed-by: tazjin Tested-by: BuildkiteCI --- third_party/nix/src/nix-store/nix-store.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'third_party/nix/src/nix-store') diff --git a/third_party/nix/src/nix-store/nix-store.cc b/third_party/nix/src/nix-store/nix-store.cc index 7729945b1307..1f1e221fc39c 100644 --- a/third_party/nix/src/nix-store/nix-store.cc +++ b/third_party/nix/src/nix-store/nix-store.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -1170,11 +1171,11 @@ static void opGenerateBinaryCacheKey(Strings opFlags, Strings opArgs) { } writeFile(publicKeyFile, keyName + ":" + - base64Encode(std::string( + absl::Base64Escape(std::string( (char*)pk, crypto_sign_PUBLICKEYBYTES))); umask(0077); writeFile(secretKeyFile, keyName + ":" + - base64Encode(std::string( + absl::Base64Escape(std::string( (char*)sk, crypto_sign_SECRETKEYBYTES))); #else throw Error( -- cgit 1.4.1