GPGMEPP and C++ antipatterns
"Robert J. Hansen via Gnupg-users" <[email protected]>
| Newsgroups | gmane.comp.encryption.gpg.user |
|---|---|
| Message-ID | <[email protected]> |
After using GPGMEPP for a week or so, I'm pleased with it. Somebody
clearly put some thought into how to make it a properly C++ library,
rather than just a thin wrapper around a C one. Whoever's responsible
for that (Ingo?), thank you.
However, I do have a couple of minor nits. (Of course I do. It's me.)
First, a number of functions accept unsigned ints as a parameter. This
involves a minor pain point for those of us working in environments that
require us to follow the MISRA C++ guidelines. Admittedly, it's a
one-letter fix:
(*ctx).setKeyListMode(0);
|
becomes
|
V
(*ctx).setKeyListMode(0U);
but it would be nice if we could find some way to avoid one letter of
syntactic sugar and let us express code in the most natural way.
Second, MISRA has … I can only call them _opinions_, shall we say … on
the subject of pointers. Look at, e.g., creating a new Context:
auto ctx = unique_ptr<Context>(OpenPGP);
if (nullptr == ctx) {
// handle the error
}
Here there are two problems. The first is that GPGMEPP is using
old-style enums rather than modern C++ class enums, which means they're
not typesafe and it's harder for static analysis tools to detect when
you're feeding in garbage. The second is that per MISRA, unique_ptrs and
shared_ptrs should be created only by calls to make_unique and/or
make_shared, not by direct application of the constructor.
Hence, two more suggestions. First, replace all enums with C++ class
enums, and second, make createForProtocol take a template parameter of
the type of pointer to return, whether unique, shared, or raw.
These minor problems aren't creating any obstacles to my development,
just requiring me to fill out a small amount of paperwork documenting
the deviations from MISRA. All in all I quite like GPGMEPP. Thanks for
the code, guys. :)
_______________________________________________
Gnupg-users mailing list
[email protected]
https://lists.gnupg.org/mailman/listinfo/gnupg-users
OpenPGP_signature.asc
(application/pgp-signature, 236 B)
-----BEGIN PGP SIGNATURE----- wnsEABYIACMWIQR9jsS4W2/t1sENPHkeepTU6H+R1QUCaQz8tgUDAAAAAAAKCRAeepTU6H+R1SuB AQD76M7xbQAgKt2Xmj4NvJI3kleyp2/tiZ4uiIrrx6jD4wD/TxKyghwppsSgESS3/5wDZ5gZnAhz wKmLsmePi2HbuAI= =jVA3 -----END PGP SIGNATURE-----