From c4d22997f364a7fc2e5a8150c0a4a55590a92df5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 16 Feb 2016 16:38:44 +0100 Subject: Add C++ functions for .narinfo processing / signing This is currently only used by the Hydra queue runner rework, but like eff5021eaa6dc69f65ea1a8abe8f3ab11ef5eb0a it presumably will be useful for the C++ rewrite of nix-push and download-from-binary-cache. (@shlevy) --- perl/lib/Nix/Store.xs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'perl') diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs index beac53ebf42f..44c88a87bfc6 100644 --- a/perl/lib/Nix/Store.xs +++ b/perl/lib/Nix/Store.xs @@ -10,6 +10,7 @@ #include "globals.hh" #include "store-api.hh" #include "util.hh" +#include "crypto.hh" #if HAVE_SODIUM #include @@ -235,19 +236,12 @@ SV * convertHash(char * algo, char * s, int toBase32) } -SV * signString(SV * secretKey_, char * msg) +SV * signString(char * secretKey_, char * msg) PPCODE: try { #if HAVE_SODIUM - STRLEN secretKeyLen; - unsigned char * secretKey = (unsigned char *) SvPV(secretKey_, secretKeyLen); - if (secretKeyLen != crypto_sign_SECRETKEYBYTES) - throw Error("secret key is not valid"); - - unsigned char sig[crypto_sign_BYTES]; - unsigned long long sigLen; - crypto_sign_detached(sig, &sigLen, (unsigned char *) msg, strlen(msg), secretKey); - XPUSHs(sv_2mortal(newSVpv((char *) sig, sigLen))); + auto sig = SecretKey(secretKey_).signDetached(msg); + XPUSHs(sv_2mortal(newSVpv(sig.c_str(), sig.size()))); #else throw Error("Nix was not compiled with libsodium, required for signed binary cache support"); #endif -- cgit 1.4.1