diff options
| author | Chih-Hung Hsieh <chh@google.com> | 2019-01-02 13:34:23 -0800 |
|---|---|---|
| committer | Chih-Hung Hsieh <chh@google.com> | 2019-01-11 13:58:16 -0800 |
| commit | 82ac34109e10967f2da900f7e8bb8f10b0ac8b74 (patch) | |
| tree | b0404ffee1be9d57a2012df59da4543833016eba | |
| parent | 2b4d64806cb46d6a11fe8f1ccb9a6e2df18cb435 (diff) | |
| download | android_system_keymaster-82ac34109e10967f2da900f7e8bb8f10b0ac8b74.tar.gz android_system_keymaster-82ac34109e10967f2da900f7e8bb8f10b0ac8b74.tar.bz2 android_system_keymaster-82ac34109e10967f2da900f7e8bb8f10b0ac8b74.zip | |
Fix/suppress system/keymaster google-explicit-constructor warnings
* Add explicit to conversion constructors/operators
* Use NOLINT or NOLINTNEXTLINE to suppress warnings on intended converters
* Some source code format changed by clang-format
Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: Icd9fbdb0ea7bc5b75015b07d73aaa21ae5ee8be7
| -rw-r--r-- | contexts/soft_keymaster_device.cpp | 1 | ||||
| -rw-r--r-- | include/keymaster/UniquePtr.h | 9 | ||||
| -rw-r--r-- | include/keymaster/contexts/keymaster0_passthrough_context.h | 11 | ||||
| -rw-r--r-- | include/keymaster/contexts/keymaster1_passthrough_context.h | 30 | ||||
| -rw-r--r-- | include/keymaster/contexts/keymaster2_passthrough_context.h | 14 | ||||
| -rw-r--r-- | include/keymaster/keymaster_tags.h | 2 | ||||
| -rw-r--r-- | include/keymaster/legacy_support/keymaster1_legacy_support.h | 1 | ||||
| -rw-r--r-- | include/keymaster/soft_key_factory.h | 14 | ||||
| -rw-r--r-- | km_openssl/aes_operation.h | 3 | ||||
| -rw-r--r-- | km_openssl/block_cipher_operation.h | 2 | ||||
| -rw-r--r-- | km_openssl/triple_des_operation.h | 3 | ||||
| -rw-r--r-- | legacy_support/keymaster1_legacy_support.cpp | 1 | ||||
| -rw-r--r-- | ng/AndroidKeymaster3Device.cpp | 2 | ||||
| -rw-r--r-- | ng/AndroidKeymaster4Device.cpp | 2 | ||||
| -rw-r--r-- | ng/include/AndroidKeymaster4Device.h | 2 | ||||
| -rw-r--r-- | ng/include/authorization_set.h | 4 | ||||
| -rw-r--r-- | ng/include/keymaster_tags.h | 2 |
17 files changed, 56 insertions, 47 deletions
diff --git a/contexts/soft_keymaster_device.cpp b/contexts/soft_keymaster_device.cpp index 23a6eda..455c40a 100644 --- a/contexts/soft_keymaster_device.cpp +++ b/contexts/soft_keymaster_device.cpp @@ -89,6 +89,7 @@ template <typename T> std::vector<T> make_vector(const T* array, size_t len) { // size of a set intersection. struct PushbackCounter { struct value_type { + // NOLINTNEXTLINE(google-explicit-constructor) template <typename T> value_type(const T&) {} }; void push_back(const value_type&) { ++count; } diff --git a/include/keymaster/UniquePtr.h b/include/keymaster/UniquePtr.h index 0cfbe08..20ff446 100644 --- a/include/keymaster/UniquePtr.h +++ b/include/keymaster/UniquePtr.h @@ -58,14 +58,16 @@ public: // Construct a new UniquePtr, taking ownership of the given raw pointer. explicit UniquePtr(T* ptr) : mPtr(ptr) { } + // NOLINTNEXTLINE(google-explicit-constructor) UniquePtr(const decltype(nullptr)&) : mPtr(nullptr) {} UniquePtr(UniquePtr && other): mPtr(other.mPtr) { other.mPtr = nullptr; } - template<typename U> - UniquePtr(UniquePtr<U> && other): mPtr(other.mPtr) { + template <typename U> + // NOLINTNEXTLINE(google-explicit-constructor) + UniquePtr(UniquePtr<U>&& other) : mPtr(other.mPtr) { other.mPtr = nullptr; } UniquePtr& operator=(UniquePtr && other) { @@ -85,6 +87,7 @@ public: T* operator->() const { return mPtr; } T* get() const { return mPtr; } + // NOLINTNEXTLINE(google-explicit-constructor) operator bool() const { return mPtr != nullptr; } // Returns the raw pointer and hands over ownership to the caller. @@ -125,6 +128,7 @@ public: UniquePtr() : mPtr(nullptr) {} explicit UniquePtr(T* ptr) : mPtr(ptr) { } + // NOLINTNEXTLINE(google-explicit-constructor) UniquePtr(const decltype(nullptr)&) : mPtr(nullptr) {} UniquePtr(UniquePtr && other): mPtr(other.mPtr) { @@ -153,6 +157,7 @@ public: return result; } + // NOLINTNEXTLINE(google-explicit-constructor) operator bool() const { return mPtr != nullptr; } void reset(T* ptr = nullptr) { diff --git a/include/keymaster/contexts/keymaster0_passthrough_context.h b/include/keymaster/contexts/keymaster0_passthrough_context.h index 395c757..cad9df6 100644 --- a/include/keymaster/contexts/keymaster0_passthrough_context.h +++ b/include/keymaster/contexts/keymaster0_passthrough_context.h @@ -18,28 +18,27 @@ #ifndef CONTEXTS_KEYMASTER0_PASSTHROUGH_CONTEXT_H_ #define CONTEXTS_KEYMASTER0_PASSTHROUGH_CONTEXT_H_ - #include <hardware/keymaster0.h> #include <keymaster/contexts/pure_soft_keymaster_context.h> -#include <keymaster/legacy_support/keymaster0_engine.h> #include <keymaster/legacy_support/ec_keymaster0_key.h> +#include <keymaster/legacy_support/keymaster0_engine.h> #include <keymaster/legacy_support/rsa_keymaster0_key.h> namespace keymaster { class Keymaster0PassthroughContext : public PureSoftKeymasterContext { -public: - Keymaster0PassthroughContext(keymaster0_device_t *dev) : PureSoftKeymasterContext() { + public: + explicit Keymaster0PassthroughContext(keymaster0_device_t* dev) : PureSoftKeymasterContext() { km0_engine_.reset(new Keymaster0Engine(dev)); rsa_factory_.reset(new RsaKeymaster0KeyFactory(this, km0_engine_.get())); ec_factory_.reset(new EcdsaKeymaster0KeyFactory(this, km0_engine_.get())); } -private: + private: UniquePtr<Keymaster0Engine> km0_engine_; }; -} // namespace keymaster +} // namespace keymaster #endif // CONTEXTS_KEYMASTER0_PASSTHROUGH_CONTEXT_H_ diff --git a/include/keymaster/contexts/keymaster1_passthrough_context.h b/include/keymaster/contexts/keymaster1_passthrough_context.h index 36ee847..820e01c 100644 --- a/include/keymaster/contexts/keymaster1_passthrough_context.h +++ b/include/keymaster/contexts/keymaster1_passthrough_context.h @@ -27,18 +27,18 @@ #include <keymaster/keymaster_context.h> #include <keymaster/km_openssl/software_random_source.h> #include <keymaster/legacy_support/keymaster1_engine.h> -#include <keymaster/legacy_support/keymaster_passthrough_key.h> #include <keymaster/legacy_support/keymaster_passthrough_engine.h> +#include <keymaster/legacy_support/keymaster_passthrough_key.h> #include <keymaster/soft_key_factory.h> namespace keymaster { class Keymaster1PassthroughContext : public KeymasterContext, - AttestationRecordContext, - public SoftwareRandomSource, - public SoftwareKeyBlobMaker{ -public: - Keymaster1PassthroughContext(keymaster1_device_t* dev); + AttestationRecordContext, + public SoftwareRandomSource, + public SoftwareKeyBlobMaker { + public: + explicit Keymaster1PassthroughContext(keymaster1_device_t* dev); /** * Sets the system version as reported by the system *itself*. This is used to verify that the @@ -59,7 +59,7 @@ public: KeyFactory* GetKeyFactory(keymaster_algorithm_t algorithm) const override; OperationFactory* GetOperationFactory(keymaster_algorithm_t algorithm, - keymaster_purpose_t purpose) const override; + keymaster_purpose_t purpose) const override; keymaster_algorithm_t* GetSupportedAlgorithms(size_t* algorithms_count) const override; /** @@ -67,8 +67,8 @@ public: * the current format and OS version info. */ keymaster_error_t UpgradeKeyBlob(const KeymasterKeyBlob& key_to_upgrade, - const AuthorizationSet& upgrade_params, - KeymasterKeyBlob* upgraded_key) const override; + const AuthorizationSet& upgrade_params, + KeymasterKeyBlob* upgraded_key) const override; /** * ParseKeyBlob takes a blob and extracts authorization sets and key material, returning an @@ -78,8 +78,8 @@ public: * This method is called by AndroidKeymaster. */ keymaster_error_t ParseKeyBlob(const KeymasterKeyBlob& blob, - const AuthorizationSet& additional_params, - UniquePtr<Key>* key) const override; + const AuthorizationSet& additional_params, + UniquePtr<Key>* key) const override; /** * Take whatever environment-specific action is appropriate (if any) to delete the specified @@ -106,14 +106,12 @@ public: */ KeymasterEnforcement* enforcement_policy() override; - keymaster_error_t GenerateAttestation(const Key& key, - const AuthorizationSet& attest_params, + keymaster_error_t GenerateAttestation(const Key& key, const AuthorizationSet& attest_params, CertChainPtr* cert_chain) const override; keymaster_error_t CreateKeyBlob(const AuthorizationSet& key_description, const keymaster_key_origin_t origin, - const KeymasterKeyBlob& key_material, - KeymasterKeyBlob* blob, + const KeymasterKeyBlob& key_material, KeymasterKeyBlob* blob, AuthorizationSet* hw_enforced, AuthorizationSet* sw_enforced) const override; @@ -133,6 +131,6 @@ public: uint32_t os_patchlevel_; }; -} // namespace keymaster +} // namespace keymaster #endif // SOFTWARE_CONTEXT_KEYMASTER1_PASSTHROUGH_CONTEXT_H_ diff --git a/include/keymaster/contexts/keymaster2_passthrough_context.h b/include/keymaster/contexts/keymaster2_passthrough_context.h index 1209b20..8b889f3 100644 --- a/include/keymaster/contexts/keymaster2_passthrough_context.h +++ b/include/keymaster/contexts/keymaster2_passthrough_context.h @@ -24,14 +24,14 @@ #include <hardware/keymaster_defs.h> #include <keymaster/keymaster_context.h> -#include <keymaster/legacy_support/keymaster_passthrough_key.h> #include <keymaster/legacy_support/keymaster_passthrough_engine.h> +#include <keymaster/legacy_support/keymaster_passthrough_key.h> namespace keymaster { class Keymaster2PassthroughContext : public KeymasterContext { -public: - Keymaster2PassthroughContext(keymaster2_device_t* dev); + public: + explicit Keymaster2PassthroughContext(keymaster2_device_t* dev); /** * Sets the system version as reported by the system *itself*. This is used to verify that the @@ -99,8 +99,7 @@ public: */ KeymasterEnforcement* enforcement_policy() override; - keymaster_error_t GenerateAttestation(const Key& key, - const AuthorizationSet& attest_params, + keymaster_error_t GenerateAttestation(const Key& key, const AuthorizationSet& attest_params, CertChainPtr* cert_chain) const override; keymaster_error_t @@ -111,12 +110,13 @@ public: private: keymaster2_device_t* device_; - mutable std::unordered_map<keymaster_algorithm_t, UniquePtr<KeymasterPassthroughKeyFactory>> factories_; + mutable std::unordered_map<keymaster_algorithm_t, UniquePtr<KeymasterPassthroughKeyFactory>> + factories_; UniquePtr<KeymasterPassthroughEngine> engine_; uint32_t os_version_; uint32_t os_patchlevel_; }; -} // namespace keymaster +} // namespace keymaster #endif // SOFTWARE_CONTEXT_KEYMASTER2_PASSTHROUGH_CONTEXT_H_ diff --git a/include/keymaster/keymaster_tags.h b/include/keymaster/keymaster_tags.h index 9908119..ac614fe 100644 --- a/include/keymaster/keymaster_tags.h +++ b/include/keymaster/keymaster_tags.h @@ -105,6 +105,7 @@ template <keymaster_tag_type_t tag_type, keymaster_tag_t tag> class TypedTag { StaticAssert<(tag & tag_type) == tag_type>::check(); StaticAssert<(tag_type != KM_ENUM) && (tag_type != KM_ENUM_REP)>::check(); } + // NOLINTNEXTLINE(google-explicit-constructor) inline operator keymaster_tag_t() { return tag; } inline long masked_tag() { return static_cast<long>(keymaster_tag_mask_type(tag)); } }; @@ -121,6 +122,7 @@ class TypedEnumTag { StaticAssert<(tag & tag_type) == tag_type>::check(); StaticAssert<(tag_type == KM_ENUM) || (tag_type == KM_ENUM_REP)>::check(); } + // NOLINTNEXTLINE(google-explicit-constructor) inline operator keymaster_tag_t() { return tag; } inline long masked_tag() { return static_cast<long>(keymaster_tag_mask_type(tag)); } }; diff --git a/include/keymaster/legacy_support/keymaster1_legacy_support.h b/include/keymaster/legacy_support/keymaster1_legacy_support.h index 576a9b9..5ecc4b8 100644 --- a/include/keymaster/legacy_support/keymaster1_legacy_support.h +++ b/include/keymaster/legacy_support/keymaster1_legacy_support.h @@ -42,6 +42,7 @@ public: typedef std::pair<keymaster_algorithm_t, keymaster_purpose_t> AlgPurposePair; typedef std::map<AlgPurposePair, std::vector<keymaster_digest_t>> DigestMap; + // NOLINTNEXTLINE(google-explicit-constructor) Keymaster1LegacySupport(const keymaster1_device_t* dev); bool RequiresSoftwareDigesting(const AuthorizationSet& key_description) const; diff --git a/include/keymaster/soft_key_factory.h b/include/keymaster/soft_key_factory.h index 7361ce8..ee494cb 100644 --- a/include/keymaster/soft_key_factory.h +++ b/include/keymaster/soft_key_factory.h @@ -23,11 +23,11 @@ namespace keymaster { class SoftwareKeyBlobMaker { -protected: + protected: // make destructor protected so only implementers can destroy instances. virtual ~SoftwareKeyBlobMaker() {} -public: + public: /** * CreateKeyBlob takes authorization sets and key material and produces a key blob and hardware * and software authorization lists ready to be returned to the AndroidKeymaster client @@ -39,15 +39,15 @@ public: const KeymasterKeyBlob& key_material, KeymasterKeyBlob* blob, AuthorizationSet* hw_enforced, AuthorizationSet* sw_enforced) const = 0; - }; class SoftKeyFactoryMixin { -public: - SoftKeyFactoryMixin(const SoftwareKeyBlobMaker* blob_maker) : - blob_maker_(*blob_maker) {} + public: + explicit SoftKeyFactoryMixin(const SoftwareKeyBlobMaker* blob_maker) + : blob_maker_(*blob_maker) {} virtual ~SoftKeyFactoryMixin() {} -protected: + + protected: const SoftwareKeyBlobMaker& blob_maker_; }; diff --git a/km_openssl/aes_operation.h b/km_openssl/aes_operation.h index b18d49a..816ffa7 100644 --- a/km_openssl/aes_operation.h +++ b/km_openssl/aes_operation.h @@ -37,7 +37,8 @@ class AesEvpCipherDescription : public EvpCipherDescription { class AesOperationFactory : public BlockCipherOperationFactory { public: - AesOperationFactory(keymaster_purpose_t purpose) : BlockCipherOperationFactory(purpose) {} + explicit AesOperationFactory(keymaster_purpose_t purpose) + : BlockCipherOperationFactory(purpose) {} const EvpCipherDescription& GetCipherDescription() const override; }; diff --git a/km_openssl/block_cipher_operation.h b/km_openssl/block_cipher_operation.h index 2707b4e..1da94eb 100644 --- a/km_openssl/block_cipher_operation.h +++ b/km_openssl/block_cipher_operation.h @@ -45,7 +45,7 @@ class EvpCipherDescription { */ class BlockCipherOperationFactory : public OperationFactory { public: - BlockCipherOperationFactory(keymaster_purpose_t purpose) : purpose_(purpose) {} + explicit BlockCipherOperationFactory(keymaster_purpose_t purpose) : purpose_(purpose) {} KeyType registry_key() const override { return KeyType(GetCipherDescription().algorithm(), purpose_); diff --git a/km_openssl/triple_des_operation.h b/km_openssl/triple_des_operation.h index cc69bc7..6a14715 100644 --- a/km_openssl/triple_des_operation.h +++ b/km_openssl/triple_des_operation.h @@ -37,7 +37,8 @@ class TripleDesEvpCipherDescription : public EvpCipherDescription { class TripleDesOperationFactory : public BlockCipherOperationFactory { public: - TripleDesOperationFactory(keymaster_purpose_t purpose) : BlockCipherOperationFactory(purpose) {} + explicit TripleDesOperationFactory(keymaster_purpose_t purpose) + : BlockCipherOperationFactory(purpose) {} const EvpCipherDescription& GetCipherDescription() const override; }; diff --git a/legacy_support/keymaster1_legacy_support.cpp b/legacy_support/keymaster1_legacy_support.cpp index 75663b7..b0fe3f2 100644 --- a/legacy_support/keymaster1_legacy_support.cpp +++ b/legacy_support/keymaster1_legacy_support.cpp @@ -36,6 +36,7 @@ template <typename T> std::vector<T> make_vector(const T* array, size_t len) { // size of a set intersection. struct PushbackCounter { struct value_type { + // NOLINTNEXTLINE(google-explicit-constructor) template <typename T> value_type(const T&) {} }; void push_back(const value_type&) { ++count; } diff --git a/ng/AndroidKeymaster3Device.cpp b/ng/AndroidKeymaster3Device.cpp index c95db0c..93ef72b 100644 --- a/ng/AndroidKeymaster3Device.cpp +++ b/ng/AndroidKeymaster3Device.cpp @@ -85,7 +85,7 @@ inline keymaster_tag_type_t typeFromTag(const keymaster_tag_t tag) { 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/ng/AndroidKeymaster4Device.cpp b/ng/AndroidKeymaster4Device.cpp index 69cb6c9..70060d6 100644 --- a/ng/AndroidKeymaster4Device.cpp +++ b/ng/AndroidKeymaster4Device.cpp @@ -72,7 +72,7 @@ inline keymaster_tag_type_t typeFromTag(const keymaster_tag_t tag) { 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/ng/include/AndroidKeymaster4Device.h b/ng/include/AndroidKeymaster4Device.h index 069bb7c..688d08a 100644 --- a/ng/include/AndroidKeymaster4Device.h +++ b/ng/include/AndroidKeymaster4Device.h @@ -48,7 +48,7 @@ using ::android::hardware::keymaster::V4_0::VerificationToken; class AndroidKeymaster4Device : public IKeymasterDevice { public: - AndroidKeymaster4Device(SecurityLevel securityLevel); + explicit AndroidKeymaster4Device(SecurityLevel securityLevel); virtual ~AndroidKeymaster4Device(); Return<void> getHardwareInfo(getHardwareInfo_cb _hidl_cb) override; diff --git a/ng/include/authorization_set.h b/ng/include/authorization_set.h index d4cb76a..5367696 100644 --- a/ng/include/authorization_set.h +++ b/ng/include/authorization_set.h @@ -44,9 +44,7 @@ class AuthorizationSet { AuthorizationSet(AuthorizationSet&& other) : data_(std::move(other.data_)) {} // Constructor from hidl_vec<KeyParameter> - AuthorizationSet(const hidl_vec<KeyParameter>& other) { - *this = other; - } + explicit AuthorizationSet(const hidl_vec<KeyParameter>& other) { *this = other; } // Copy assignment. AuthorizationSet& operator=(const AuthorizationSet& other) { diff --git a/ng/include/keymaster_tags.h b/ng/include/keymaster_tags.h index d5fdefd..be6c11c 100644 --- a/ng/include/keymaster_tags.h +++ b/ng/include/keymaster_tags.h @@ -111,6 +111,7 @@ template <TagType tag_type, Tag tag> struct TypedTag { // error (no match for template specialization StaticAssert<false>), with no run-time cost. static_assert(typeFromTag(tag) == tag_type, "mismatch between tag and tag_type"); } + // NOLINTNEXTLINE(google-explicit-constructor) operator Tag() const { return tag; } }; @@ -308,6 +309,7 @@ template <typename ValueT> class NullOr { public: NullOr() : value_(initializer_t<ValueT>::init()), null_(true) {} + // NOLINTNEXTLINE(google-explicit-constructor) NullOr(ValueT&& value) : value_(std::forward<ValueT>(value)), null_(false) {} bool isOk() const { return !null_; } |
