trying to figure out how to get the email address in here with op_createkey. gnupg-2.1
authorKrista Bennett <krista@pep-project.org>
Thu, 13 Jul 2017 13:27:44 +0200
branchgnupg-2.1
changeset 19212bbb3d83c7c1
parent 1920 c7e8570c9d25
child 1922 0d9f147a763f
trying to figure out how to get the email address in here with op_createkey.
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Wed Jul 12 19:46:30 2017 +0200
     1.2 +++ b/src/pgp_gpg.c	Thu Jul 13 13:27:44 2017 +0200
     1.3 @@ -279,14 +279,15 @@
     1.4              = (gpgme_get_key_t) (intptr_t) dlsym(gpgme, "gpgme_get_key");
     1.5          assert(gpg.gpgme_get_key);
     1.6          
     1.7 -#ifdef GPGME_VERSION_NUMBER 
     1.8 -#if (GPGME_VERSION_NUMBER >= 0x010700)
     1.9 -        gpg.gpgme_op_createkey
    1.10 -            = (gpgme_op_createkey_t) (intptr_t) dlsym(gpgme,
    1.11 -            "gpgme_op_createkey");
    1.12 -        assert(gpg.gpgme_op_createkey);        
    1.13 -#endif
    1.14 -#endif
    1.15 +        #ifdef GPGME_VERSION_NUMBER 
    1.16 +        #if (GPGME_VERSION_NUMBER >= 0x010700)
    1.17 +                gpg.gpgme_op_createkey
    1.18 +                    = (gpgme_op_createkey_t) (intptr_t) dlsym(gpgme,
    1.19 +                    "gpgme_op_createkey");
    1.20 +                assert(gpg.gpgme_op_createkey);
    1.21 +        #endif
    1.22 +        #endif
    1.23 +        
    1.24          gpg.gpgme_op_genkey
    1.25              = (gpgme_op_genkey_t) (intptr_t) dlsym(gpgme,
    1.26              "gpgme_op_genkey");
    1.27 @@ -1075,13 +1076,26 @@
    1.28  #ifdef GPGME_VERSION_NUMBER 
    1.29  #if (GPGME_VERSION_NUMBER >= 0x010700)
    1.30          gpgme_error_t gpgme_error;
    1.31 -        gpgme_error = gpg.gpgme_op_createkey(session->ctx, identity->address, "RSA", 
    1.32 +        /* "name <address>" adds 3 chars + NUL */
    1.33 +        int userid_size = strlen(identity->username) + strlen(identity->address) + 4;
    1.34 +        char* userid = (char*)(calloc(1, userid_size));
    1.35 +        if (!userid)
    1.36 +            return PEP_OUT_OF_MEMORY;
    1.37 +        /* sprintf... so tempting... */    
    1.38 +        strlcpy(userid, identity->username, userid_size);
    1.39 +        strlcat(userid, " <", userid_size);
    1.40 +        strlcat(userid, identity->address, userid_size);
    1.41 +        strlcat(userid, ">", userid_size);
    1.42 +        gpgme_error = gpg.gpgme_op_createkey(session->ctx, userid, "RSA", 
    1.43                                               0, 31536000, NULL, GPGME_CREATE_NOPASSWD);
    1.44          gpgme_error = _GPGERR(gpgme_error);
    1.45 +
    1.46 +        free(userid);
    1.47 +
    1.48          if (gpgme_error != GPG_ERR_NOT_SUPPORTED) {
    1.49              switch (gpgme_error) {
    1.50              case GPG_ERR_NO_ERROR:
    1.51 -                return PEP_STATUS_OK;
    1.52 +                break;
    1.53              case GPG_ERR_INV_VALUE:
    1.54                  return PEP_ILLEGAL_VALUE;
    1.55              case GPG_ERR_GENERAL: