diff options
author | Jade Lovelace <lix@jade.fyi> | 2024-08-04 20:19:58 -0700 |
---|---|---|
committer | Jade Lovelace <lix@jade.fyi> | 2024-08-08 14:53:17 -0700 |
commit | e34833c0253340f47dc0add8609eb86cf9cba19b (patch) | |
tree | 83e196e01ed4197e8f413f21d16b93cdd60f3d63 /src/libstore/crypto.cc | |
parent | 370ac940dd7816ad4052fafa4e0f8d17784fa16b (diff) |
tree-wide: fix a pile of lints
This:
- Converts a bunch of C style casts into C++ casts.
- Removes some very silly pointer subtraction code (which is no more or
less busted on i686 than it began)
- Fixes some "technically UB" that never had to be UB in the first
place.
- Makes finally follow the noexcept status of the inner function. Maybe
in the future we should ban the function from not being noexcept, but
that is not today.
- Makes various locally-used exceptions inherit from std::exception.
Change-Id: I22e66972602604989b5e494fd940b93e0e6e9297
Diffstat (limited to 'src/libstore/crypto.cc')
-rw-r--r-- | src/libstore/crypto.cc | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libstore/crypto.cc b/src/libstore/crypto.cc index 2e0fd8ca5..e8ab15537 100644 --- a/src/libstore/crypto.cc +++ b/src/libstore/crypto.cc @@ -44,16 +44,16 @@ std::string SecretKey::signDetached(std::string_view data) const { unsigned char sig[crypto_sign_BYTES]; unsigned long long sigLen; - crypto_sign_detached(sig, &sigLen, (unsigned char *) data.data(), data.size(), - (unsigned char *) key.data()); - return name + ":" + base64Encode(std::string((char *) sig, sigLen)); + crypto_sign_detached(sig, &sigLen, reinterpret_cast<const unsigned char *>(data.data()), data.size(), + reinterpret_cast<const unsigned char *>(key.data())); + return name + ":" + base64Encode(std::string(reinterpret_cast<char *>(sig), sigLen)); } PublicKey SecretKey::toPublicKey() const { unsigned char pk[crypto_sign_PUBLICKEYBYTES]; - crypto_sign_ed25519_sk_to_pk(pk, (unsigned char *) key.data()); - return PublicKey(name, std::string((char *) pk, crypto_sign_PUBLICKEYBYTES)); + crypto_sign_ed25519_sk_to_pk(pk, reinterpret_cast<const unsigned char *>(key.data())); + return PublicKey(name, std::string(reinterpret_cast<char *>(pk), crypto_sign_PUBLICKEYBYTES)); } SecretKey SecretKey::generate(std::string_view name) @@ -63,7 +63,7 @@ SecretKey SecretKey::generate(std::string_view name) if (crypto_sign_keypair(pk, sk) != 0) throw Error("key generation failed"); - return SecretKey(name, std::string((char *) sk, crypto_sign_SECRETKEYBYTES)); + return SecretKey(name, std::string(reinterpret_cast<char *>(sk), crypto_sign_SECRETKEYBYTES)); } PublicKey::PublicKey(std::string_view s) @@ -85,9 +85,9 @@ bool verifyDetached(const std::string & data, const std::string & sig, if (sig2.size() != crypto_sign_BYTES) throw Error("signature is not valid"); - return crypto_sign_verify_detached((unsigned char *) sig2.data(), - (unsigned char *) data.data(), data.size(), - (unsigned char *) key->second.key.data()) == 0; + return crypto_sign_verify_detached(reinterpret_cast<unsigned char *>(sig2.data()), + reinterpret_cast<const unsigned char *>(data.data()), data.size(), + reinterpret_cast<const unsigned char *>(key->second.key.data())) == 0; } PublicKeys getDefaultPublicKeys() |