Fix build without sodium

http://hydra.nixos.org/build/32085949
This commit is contained in:
Eelco Dolstra 2016-02-17 12:41:41 +01:00
parent c4d22997f3
commit b49d323ce2
2 changed files with 11 additions and 5 deletions

View file

@ -37,6 +37,11 @@ SecretKey::SecretKey(const string & s)
#endif #endif
} }
[[noreturn]] static void noSodium()
{
throw Error("Nix was not compiled with libsodium, required for signed binary cache support");
}
std::string SecretKey::signDetached(const std::string & data) const std::string SecretKey::signDetached(const std::string & data) const
{ {
#if HAVE_SODIUM #if HAVE_SODIUM
@ -46,7 +51,7 @@ std::string SecretKey::signDetached(const std::string & data) const
(unsigned char *) key.data()); (unsigned char *) key.data());
return name + ":" + base64Encode(std::string((char *) sig, sigLen)); return name + ":" + base64Encode(std::string((char *) sig, sigLen));
#else #else
throw Error("Nix was not compiled with libsodium, required for signed binary cache support"); noSodium();
#endif #endif
} }
@ -62,6 +67,7 @@ PublicKey::PublicKey(const string & s)
bool verifyDetached(const std::string & data, const std::string & sig, bool verifyDetached(const std::string & data, const std::string & sig,
const PublicKeys & publicKeys) const PublicKeys & publicKeys)
{ {
#if HAVE_SODIUM
auto ss = split(sig); auto ss = split(sig);
auto key = publicKeys.find(ss.first); auto key = publicKeys.find(ss.first);
@ -74,6 +80,9 @@ bool verifyDetached(const std::string & data, const std::string & sig,
return crypto_sign_verify_detached((unsigned char *) sig2.data(), return crypto_sign_verify_detached((unsigned char *) sig2.data(),
(unsigned char *) data.data(), data.size(), (unsigned char *) data.data(), data.size(),
(unsigned char *) key->second.key.data()) == 0; (unsigned char *) key->second.key.data()) == 0;
#else
noSodium();
#endif
} }
} }

View file

@ -40,10 +40,7 @@ MakeError(SQLiteError, Error);
MakeError(SQLiteBusy, SQLiteError); MakeError(SQLiteBusy, SQLiteError);
static void throwSQLiteError(sqlite3 * db, const format & f) [[noreturn]] static void throwSQLiteError(sqlite3 * db, const format & f)
__attribute__ ((noreturn));
static void throwSQLiteError(sqlite3 * db, const format & f)
{ {
int err = sqlite3_errcode(db); int err = sqlite3_errcode(db);
if (err == SQLITE_BUSY || err == SQLITE_PROTOCOL) { if (err == SQLITE_BUSY || err == SQLITE_PROTOCOL) {