GPGMEPP and C++ antipatterns
Robert J. Hansen
rjh at sixdemonbag.org
Thu Nov 6 20:53:26 CET 2025
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. :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://lists.gnupg.org/pipermail/gnupg-users/attachments/20251106/6d9fae7d/attachment.sig>
More information about the Gnupg-users
mailing list