0

Convert WARN_UNUSED_RESULT to [[nodiscard]] in //crypto.

This is an automated conversion produced by the script and command in
the attached bug.

Bug: 1287045
Change-Id: I2d7cd19d5ab3052af5db668457ad85967a053712
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3387500
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Adam Langley <agl@chromium.org>
Commit-Queue: Adam Langley <agl@chromium.org>
Cr-Commit-Position: refs/heads/main@{#958917}
This commit is contained in:
Daniel Cheng
2022-01-13 23:43:05 +00:00
committed by Chromium LUCI CQ
parent 517ae90803
commit 1dca8cd5da
2 changed files with 23 additions and 26 deletions

@ -15,7 +15,6 @@
#include <memory>
#include <vector>
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/strings/string_piece.h"
#include "crypto/crypto_export.h"
@ -55,21 +54,21 @@ class CRYPTO_EXPORT HMAC {
// this requirement is gone. But a system crypto library may still enforce
// this old requirement. If the key is shorter than this recommended value,
// Init() may fail.
bool Init(const unsigned char* key, size_t key_length) WARN_UNUSED_RESULT;
[[nodiscard]] bool Init(const unsigned char* key, size_t key_length);
// Initializes this instance using |key|. Call Init
// only once. It returns false on the second or later calls.
bool Init(const SymmetricKey* key) WARN_UNUSED_RESULT;
[[nodiscard]] bool Init(const SymmetricKey* key);
// Initializes this instance using |key|. Call Init only once. It returns
// false on the second or later calls.
bool Init(base::StringPiece key) WARN_UNUSED_RESULT {
[[nodiscard]] bool Init(base::StringPiece key) {
return Init(base::as_bytes(base::make_span(key)));
}
// Initializes this instance using |key|. Call Init only once. It returns
// false on the second or later calls.
bool Init(base::span<const uint8_t> key) WARN_UNUSED_RESULT {
[[nodiscard]] bool Init(base::span<const uint8_t> key) {
return Init(key.data(), key.size());
}
@ -78,11 +77,11 @@ class CRYPTO_EXPORT HMAC {
// returned in |digest|, which has |digest_length| bytes of storage available.
// If |digest_length| is smaller than DigestLength(), the output will be
// truncated. If it is larger, this method will fail.
bool Sign(base::StringPiece data,
unsigned char* digest,
size_t digest_length) const WARN_UNUSED_RESULT;
bool Sign(base::span<const uint8_t> data,
base::span<uint8_t> digest) const WARN_UNUSED_RESULT;
[[nodiscard]] bool Sign(base::StringPiece data,
unsigned char* digest,
size_t digest_length) const;
[[nodiscard]] bool Sign(base::span<const uint8_t> data,
base::span<uint8_t> digest) const;
// Verifies that the HMAC for the message in |data| equals the HMAC provided
// in |digest|, using the algorithm supplied to the constructor and the key
@ -91,18 +90,17 @@ class CRYPTO_EXPORT HMAC {
// comparisons may result in side-channel disclosures, such as timing, that
// undermine the cryptographic integrity. |digest| must be exactly
// |DigestLength()| bytes long.
bool Verify(base::StringPiece data,
base::StringPiece digest) const WARN_UNUSED_RESULT;
bool Verify(base::span<const uint8_t> data,
base::span<const uint8_t> digest) const WARN_UNUSED_RESULT;
[[nodiscard]] bool Verify(base::StringPiece data,
base::StringPiece digest) const;
[[nodiscard]] bool Verify(base::span<const uint8_t> data,
base::span<const uint8_t> digest) const;
// Verifies a truncated HMAC, behaving identical to Verify(), except
// that |digest| is allowed to be smaller than |DigestLength()|.
bool VerifyTruncated(base::StringPiece data,
base::StringPiece digest) const WARN_UNUSED_RESULT;
bool VerifyTruncated(base::span<const uint8_t> data,
base::span<const uint8_t> digest) const
WARN_UNUSED_RESULT;
[[nodiscard]] bool VerifyTruncated(base::StringPiece data,
base::StringPiece digest) const;
[[nodiscard]] bool VerifyTruncated(base::span<const uint8_t> data,
base::span<const uint8_t> digest) const;
private:
HashAlgorithm hash_alg_;

@ -10,7 +10,6 @@
#include <string>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "build/chromeos_buildflags.h"
#include "crypto/crypto_export.h"
#include "crypto/scoped_nss_types.h"
@ -84,8 +83,8 @@ CRYPTO_EXPORT bool InitializeNSSForChromeOSUser(
// true is returned, the caller can proceed to initialize TPM slot for the
// user, but should call |WillInitializeTPMForChromeOSUser| first.
// |InitializeNSSForChromeOSUser| must have been called first.
CRYPTO_EXPORT bool ShouldInitializeTPMForChromeOSUser(
const std::string& username_hash) WARN_UNUSED_RESULT;
[[nodiscard]] CRYPTO_EXPORT bool ShouldInitializeTPMForChromeOSUser(
const std::string& username_hash);
// Makes |ShouldInitializeTPMForChromeOSUser| start returning false.
// Should be called before starting TPM initialization for the user.
@ -105,15 +104,15 @@ CRYPTO_EXPORT void InitializePrivateSoftwareSlotForChromeOSUser(
const std::string& username_hash);
// Returns a reference to the public slot for user.
CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser(
const std::string& username_hash) WARN_UNUSED_RESULT;
[[nodiscard]] CRYPTO_EXPORT ScopedPK11Slot
GetPublicSlotForChromeOSUser(const std::string& username_hash);
// Returns the private slot for |username_hash| if it is loaded. If it is not
// loaded and |callback| is non-null, the |callback| will be run once the slot
// is loaded.
CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser(
[[nodiscard]] CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser(
const std::string& username_hash,
base::OnceCallback<void(ScopedPK11Slot)> callback) WARN_UNUSED_RESULT;
base::OnceCallback<void(ScopedPK11Slot)> callback);
// Closes the NSS DB for |username_hash| that was previously opened by the
// *Initialize*ForChromeOSUser functions.