AW: AW: AW: Key generation with GPGME and GnuPG hangs at gpgme_op_genkey

Robert J. Hansen rjh at sixdemonbag.org
Wed Jan 27 14:25:59 CET 2016


I don't have a solution for you, but --

> static gpgme_error_t passphrase_cb(void *hook, const char *uid_hint, const char *passphrase_info,
>                                    int prev_was_bad, int fd){
> 
>     std::string passphraseString;
>     std::cout<< "Enter your password:";
>     std::cin >> passphraseString;

Use std::getline(), not >>.  >> terminates at the first whitespace
character; you want to read in a full line.

>     char* passphrase = new char[passphraseLength + 1];

Don't do this.  C-style memory allocation is technically legal in C++,
but *strongly* advised against.  For that matter, you don't need to do
it at all: you can rely on the fact the string address-of-element
operator returns a char*.

Consider the following trivial C++14 program:

#include <string>
#include <iostream>

int main()
{
    std::string foo { "Zaphod Beeblebrox for President\n" };
    char* bar { &foo[0] };
    for (size_t index = 0 ; index < foo.size() ; index += 1)
    {
        std::cout << *(bar + index);
    }
    return 0;
}



More information about the Gnupg-users mailing list