Skip to content
Snippets Groups Projects
Commit c5da946e authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Adrien Béraud
Browse files

crypto: mark all operator bool as explicit


If operator bool is not marked as explicit and you try to do such:

a == b

where a and b are instances of class with overloaded bool operator,
the behavior is not the waited one: a and b are casted to bool
BEFORE the comparaison! This could lead into non waited situation.

This patch fixes all operator bool() where overloaded.
This also implements PublicKey operators == and != as needed in value.h.
This last showed a typical case explained upper.

Signed-off-by: default avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 8d23dc75
No related branches found
No related tags found
No related merge requests found
......@@ -67,7 +67,13 @@ struct PublicKey
PublicKey(PublicKey&& o) noexcept : pk(o.pk) { o.pk = nullptr; };
~PublicKey();
operator bool() const { return pk; }
explicit operator bool() const { return pk; }
bool operator ==(const PublicKey& o) const {
return pk == o.pk || getId() == o.getId();
}
bool operator !=(const PublicKey& o) const {
return !(*this == o);
}
PublicKey& operator=(PublicKey&& o) noexcept;
......@@ -114,7 +120,7 @@ struct PrivateKey
PrivateKey(const Blob& import, const std::string& password = {});
~PrivateKey();
operator bool() const { return key; }
explicit operator bool() const { return key; }
PublicKey getPublicKey() const;
Blob serialize(const std::string& password = {}) const;
......@@ -263,7 +269,7 @@ struct Certificate {
void msgpack_unpack(msgpack::object o);
operator bool() const { return cert; }
explicit operator bool() const { return cert; }
PublicKey getPublicKey() const;
/** Same as getPublicKey().getId() */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment