Fix/suppress system/security google-explicit-constructor warnings
* Add explicit to conversion constructors/operators
* Use NOLINT or NOLINTNEXTLINE to suppress warnings on intended converters
Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: I4ed5aea36fcdcd8dbda9a4be9607c5af606f2a08
diff --git a/keystore/blob.cpp b/keystore/blob.cpp
index f887e80..a636065 100644
--- a/keystore/blob.cpp
+++ b/keystore/blob.cpp
@@ -139,7 +139,7 @@
class ArrayStreamBuffer : public std::streambuf {
public:
- template <typename T, size_t size> ArrayStreamBuffer(const T (&data)[size]) {
+ template <typename T, size_t size> explicit ArrayStreamBuffer(const T (&data)[size]) {
static_assert(sizeof(T) == 1, "Array element size too large");
std::streambuf::char_type* d = const_cast<std::streambuf::char_type*>(
reinterpret_cast<const std::streambuf::char_type*>(&data[0]));
diff --git a/keystore/blob.h b/keystore/blob.h
index 92e4514..ff9195d 100644
--- a/keystore/blob.h
+++ b/keystore/blob.h
@@ -115,7 +115,7 @@
Blob& operator=(const Blob& rhs);
Blob& operator=(Blob&& rhs);
- operator bool() const { return bool(mBlob); }
+ explicit operator bool() const { return bool(mBlob); }
const uint8_t* getValue() const { return mBlob->value; }
@@ -239,6 +239,7 @@
static std::condition_variable locked_blobs_mutex_cond_var_;
const KeyBlobEntry* entry_;
+ // NOLINTNEXTLINE(google-explicit-constructor)
LockedKeyBlobEntry(const KeyBlobEntry& entry) : entry_(&entry) {}
static void put(const KeyBlobEntry& entry);
@@ -267,7 +268,7 @@
std::tuple<ResponseCode, Blob, Blob> readBlobs(const uint8_t* aes_key, State state) const;
ResponseCode deleteBlobs() const;
- inline operator bool() const { return entry_ != nullptr; }
+ inline explicit operator bool() const { return entry_ != nullptr; }
inline const KeyBlobEntry& operator*() const { return *entry_; }
inline const KeyBlobEntry* operator->() const { return entry_; }
};
diff --git a/keystore/grant_store.h b/keystore/grant_store.h
index f8e4f91..1baf32c 100644
--- a/keystore/grant_store.h
+++ b/keystore/grant_store.h
@@ -48,6 +48,7 @@
uint64_t grant_no_; ///< numeric grant identifier - randomly assigned
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator const uint64_t&() const { return grant_no_; }
};
diff --git a/keystore/include/keystore/KeyAttestationApplicationId.h b/keystore/include/keystore/KeyAttestationApplicationId.h
index dc914c1..861c2e1 100644
--- a/keystore/include/keystore/KeyAttestationApplicationId.h
+++ b/keystore/include/keystore/KeyAttestationApplicationId.h
@@ -33,8 +33,8 @@
typedef std::vector<std::unique_ptr<KeyAttestationPackageInfo>> PackageInfoVector;
KeyAttestationApplicationId();
// Following c'tors are for initializing instances containing test data.
- KeyAttestationApplicationId(std::unique_ptr<KeyAttestationPackageInfo> package);
- KeyAttestationApplicationId(PackageInfoVector packages);
+ explicit KeyAttestationApplicationId(std::unique_ptr<KeyAttestationPackageInfo> package);
+ explicit KeyAttestationApplicationId(PackageInfoVector packages);
status_t writeToParcel(Parcel*) const override;
status_t readFromParcel(const Parcel* parcel) override;
diff --git a/keystore/include/keystore/KeyCharacteristics.h b/keystore/include/keystore/KeyCharacteristics.h
index 40d495c..9c90b8a 100644
--- a/keystore/include/keystore/KeyCharacteristics.h
+++ b/keystore/include/keystore/KeyCharacteristics.h
@@ -27,7 +27,7 @@
// Parcelable version of keystore::KeyCharacteristics
struct KeyCharacteristics : public ::android::Parcelable {
KeyCharacteristics(){};
- KeyCharacteristics(::keystore::KeyCharacteristics&& other) {
+ explicit KeyCharacteristics(::keystore::KeyCharacteristics&& other) {
softwareEnforced = std::move(other.softwareEnforced);
hardwareEnforced = std::move(other.hardwareEnforced);
}
diff --git a/keystore/include/keystore/KeymasterArguments.h b/keystore/include/keystore/KeymasterArguments.h
index b453b11..3d22f5f 100644
--- a/keystore/include/keystore/KeymasterArguments.h
+++ b/keystore/include/keystore/KeymasterArguments.h
@@ -26,6 +26,7 @@
// struct for serializing/deserializing a list of KeyParameters
struct KeymasterArguments : public Parcelable {
KeymasterArguments(){};
+ // NOLINTNEXTLINE(google-explicit-constructor)
KeymasterArguments(hardware::hidl_vec<::keystore::KeyParameter>&& other);
explicit KeymasterArguments(const hardware::hidl_vec<::keystore::KeyParameter>& other);
diff --git a/keystore/include/keystore/KeystoreResponse.h b/keystore/include/keystore/KeystoreResponse.h
index 5ad260d..20f7274 100644
--- a/keystore/include/keystore/KeystoreResponse.h
+++ b/keystore/include/keystore/KeystoreResponse.h
@@ -34,6 +34,7 @@
: response_code_(response_code), error_msg_(std::make_unique<String16>(error_msg)) {}
explicit KeystoreResponse(const int response_code)
: response_code_(response_code), error_msg_() {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
KeystoreResponse(const ::keystore::KeyStoreServiceReturnCode& rc)
: response_code_(rc.getErrorCode()), error_msg_() {}
KeystoreResponse(const KeystoreResponse& other)
diff --git a/keystore/include/keystore/Signature.h b/keystore/include/keystore/Signature.h
index 31ecdef..f39acec 100644
--- a/keystore/include/keystore/Signature.h
+++ b/keystore/include/keystore/Signature.h
@@ -27,7 +27,7 @@
public:
Signature() = default;
// Intended for initializing instances containing test data.
- Signature(std::vector<uint8_t> signature_data);
+ explicit Signature(std::vector<uint8_t> signature_data);
status_t writeToParcel(Parcel*) const override;
status_t readFromParcel(const Parcel* parcel) override;
diff --git a/keystore/include/keystore/keystore_concurrency.h b/keystore/include/keystore/keystore_concurrency.h
index b60b7a6..039ca31 100644
--- a/keystore/include/keystore/keystore_concurrency.h
+++ b/keystore/include/keystore/keystore_concurrency.h
@@ -85,9 +85,10 @@
public:
ProxyLock() : impl_() {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
template <typename... Args> ProxyLock(Args&&... args) : impl_{std::forward<Args>(args)...} {}
- ProxyLock(Implementation&& impl) : impl_(std::move(impl)) {}
- operator bool() const { return impl_.value() != nullptr; }
+ explicit ProxyLock(Implementation&& impl) : impl_(std::move(impl)) {}
+ explicit operator bool() const { return impl_.value() != nullptr; }
template <typename T = typename Implementation::lockedType>
std::enable_if_t<!std::is_const<typename Implementation::lockedType>::value, T*> operator->() {
diff --git a/keystore/include/keystore/keystore_return_types.h b/keystore/include/keystore/keystore_return_types.h
index e091447..f8cf1cc 100644
--- a/keystore/include/keystore/keystore_return_types.h
+++ b/keystore/include/keystore/keystore_return_types.h
@@ -41,10 +41,13 @@
class KeyStoreServiceReturnCode {
public:
KeyStoreServiceReturnCode() : errorCode_(0) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
KeyStoreServiceReturnCode(const ErrorCode& errorCode) : errorCode_(int32_t(errorCode)) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
KeyStoreServiceReturnCode(const ResponseCode& errorCode) : errorCode_(int32_t(errorCode)) {}
KeyStoreServiceReturnCode(const KeyStoreServiceReturnCode& errorCode)
: errorCode_(errorCode.errorCode_) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
KeyStoreServiceReturnCode(const KeyStoreNativeReturnCode& errorCode);
explicit inline KeyStoreServiceReturnCode(const int32_t& errorCode) : errorCode_(errorCode) {}
inline KeyStoreServiceReturnCode& operator=(const ErrorCode& errorCode) {
@@ -115,11 +118,14 @@
class KeyStoreNativeReturnCode {
public:
KeyStoreNativeReturnCode() : errorCode_(0) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
KeyStoreNativeReturnCode(const ErrorCode& errorCode) : errorCode_(int32_t(errorCode)) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
KeyStoreNativeReturnCode(const ResponseCode& errorCode) : errorCode_(int32_t(errorCode)) {}
KeyStoreNativeReturnCode(const KeyStoreNativeReturnCode& errorCode)
: errorCode_(errorCode.errorCode_) {}
explicit inline KeyStoreNativeReturnCode(const int32_t& errorCode) : errorCode_(errorCode) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
KeyStoreNativeReturnCode(const KeyStoreServiceReturnCode& errorcode);
inline KeyStoreNativeReturnCode& operator=(const ErrorCode& errorCode) {
errorCode_ = int32_t(errorCode);
diff --git a/keystore/include/keystore/utils.h b/keystore/include/keystore/utils.h
index 1d8208a..544dd21 100644
--- a/keystore/include/keystore/utils.h
+++ b/keystore/include/keystore/utils.h
@@ -29,8 +29,12 @@
typedef std::shared_ptr<CollectionType> CollectionPtr;
SharedNullableIterator() {}
- SharedNullableIterator(const std::shared_ptr<CollectionType>& coll) : coll_(coll) { init(); }
- SharedNullableIterator(std::shared_ptr<CollectionType>&& coll) : coll_(coll) { init(); }
+ explicit SharedNullableIterator(const std::shared_ptr<CollectionType>& coll) : coll_(coll) {
+ init();
+ }
+ explicit SharedNullableIterator(std::shared_ptr<CollectionType>&& coll) : coll_(coll) {
+ init();
+ }
SharedNullableIterator(const SharedNullableIterator& other)
: coll_(other.coll_), cur_(other.cur_) {}
diff --git a/keystore/keymaster_worker.cpp b/keystore/keymaster_worker.cpp
index fd07e86..d2175b8 100644
--- a/keystore/keymaster_worker.cpp
+++ b/keystore/keymaster_worker.cpp
@@ -535,7 +535,7 @@
std::function<void()> f_;
public:
- Finalize(std::function<void()> f) : f_(f) {}
+ explicit Finalize(std::function<void()> f) : f_(f) {}
~Finalize() {
if (f_) f_();
}
diff --git a/keystore/keymaster_worker.h b/keystore/keymaster_worker.h
index 2a35977..c02d389 100644
--- a/keystore/keymaster_worker.h
+++ b/keystore/keymaster_worker.h
@@ -95,6 +95,7 @@
public:
NonCopyableFunction() = default;
+ // NOLINTNEXTLINE(google-explicit-constructor)
template <typename F> NonCopyableFunction(F f) {
f_ = std::make_unique<NonCopyableFunctionTypeEraser<F>>(std::move(f));
}
diff --git a/keystore/keystore_attestation_id.h b/keystore/keystore_attestation_id.h
index f45d5be..63015ee 100644
--- a/keystore/keystore_attestation_id.h
+++ b/keystore/keystore_attestation_id.h
@@ -33,12 +33,18 @@
template <typename T> class StatusOr {
public:
+ // NOLINTNEXTLINE(google-explicit-constructor)
StatusOr(const status_t error) : _status(error), _value() {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
StatusOr(const T& value) : _status(NO_ERROR), _value(value) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
StatusOr(T&& value) : _status(NO_ERROR), _value(value) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator const T&() const { return _value; }
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator T&() { return _value; }
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator T &&() && { return std::move(_value); }
bool isOk() const { return NO_ERROR == _status; }
diff --git a/keystore/legacy_keymaster_device_wrapper.cpp b/keystore/legacy_keymaster_device_wrapper.cpp
index 4073b42..86d286e 100644
--- a/keystore/legacy_keymaster_device_wrapper.cpp
+++ b/keystore/legacy_keymaster_device_wrapper.cpp
@@ -66,7 +66,7 @@
class KmParamSet : public keymaster_key_param_set_t {
public:
- KmParamSet(const hidl_vec<KeyParameter>& keyParams) {
+ explicit KmParamSet(const hidl_vec<KeyParameter>& keyParams) {
params = new keymaster_key_param_t[keyParams.size()];
length = keyParams.size();
for (size_t i = 0; i < keyParams.size(); ++i) {
diff --git a/keystore/legacy_keymaster_device_wrapper.h b/keystore/legacy_keymaster_device_wrapper.h
index ad26221..cd2e5a7 100644
--- a/keystore/legacy_keymaster_device_wrapper.h
+++ b/keystore/legacy_keymaster_device_wrapper.h
@@ -43,7 +43,7 @@
class LegacyKeymasterDeviceWrapper : public IKeymasterDevice {
public:
- LegacyKeymasterDeviceWrapper(keymaster2_device_t* dev);
+ explicit LegacyKeymasterDeviceWrapper(keymaster2_device_t* dev);
virtual ~LegacyKeymasterDeviceWrapper();
// Methods from ::android::hardware::keymaster::V3_0::IKeymasterDevice follow.