- //use OpenPGP
- err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP);
- if (err != GPG_ERR_NO_ERROR) {
- ERR << err << endl;
- gpgme_release(ctx);
- return shared_ptr<KeyManagerCtx>();
+KeyManagerCtx KeyManagerCtx::createForOpenPGP( const Pathname & keyring_r )
+{
+ DBG << "createForOpenPGP(" << keyring_r << ")" << endl;
+
+ KeyManagerCtx ret;
+ gpgme_ctx_t & ctx { ret._pimpl->_ctx };
+
+ // create the context
+ GpgmeErr err = gpgme_new( &ctx );
+ if ( err != GPG_ERR_NO_ERROR )
+ ZYPP_THROW( GpgmeException( "gpgme_new", err ) );
+
+ // use OpenPGP
+ err = gpgme_set_protocol( ctx, GPGME_PROTOCOL_OpenPGP );
+ if ( err != GPG_ERR_NO_ERROR )
+ ZYPP_THROW( GpgmeException( "gpgme_set_protocol", err ) );
+
+ if ( !keyring_r.empty() ) {
+ // get engine information to read current state
+ gpgme_engine_info_t enginfo = gpgme_ctx_get_engine_info( ctx );
+ if ( !enginfo )
+ ZYPP_THROW( GpgmeException( "gpgme_ctx_get_engine_info", err ) );
+
+ err = gpgme_ctx_set_engine_info( ctx, GPGME_PROTOCOL_OpenPGP, enginfo->file_name, keyring_r.c_str() );
+ if ( err != GPG_ERR_NO_ERROR )
+ ZYPP_THROW( GpgmeException( "gpgme_ctx_set_engine_info", err ) );