Hello! I'm new to gpgme and have some understanding problems:
I'm trying to export a key: -------------------------------------------------------------------------------- err = gpgme_data_new(&data); err = gpgme_op_export(ceofcontext,NULL,0,data); /* returns no error */ read_bytes = gpgme_data_seek (data, 0, SEEK_END); /* returns -1 */ p = gpgme_strerror(errno); /* returns "Invalid encoding method" */ -------------------------------------------------------------------------------- So I added more code to my test: -------------------------------------------------------------------------------- setlocale (LC_ALL, ""); gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); gpgme_set_textmode(ceofcontext,0); gpgme_set_armor(ceofcontext, 1); err = gpgme_data_set_encoding(data,GPGME_DATA_ENCODING_ARMOR); if(err != GPG_ERR_NO_ERROR) return 11; tmp = gpgme_data_get_encoding(data); if(tmp == GPGME_DATA_ENCODING_ARMOR) { printf("encode ok\n"); /* matches / is printed out */ } -------------------------------------------------------------------------------- Still the same error. Then I tried t-export.c from the test directory from gpgme. Result: -------------------------------------------------------------------------------- [23:47] denkbrett:gpg% LANG=C ./t-export Begin Result: t-support.h:56: Unspecified source: Invalid argument -------------------------------------------------------------------------------- I searched for examples for using gpgme, but there seem to be more or less none available. Does anyone have a hint for me, what I am doing wrong? I attached the whole testprogram. Sincerly Nico -- Think about Free and Open Source Software (FOSS). http://nico.schottelius.org/documentations/foss/the-term-foss/ PGP: BFE4 C736 ABE5 406F 8F42 F7CF B8BE F92A 9885 188C
#include <gpgme.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <locale.h> #define SIZE 1024 int main() { char *p; char buf[SIZE]; gpgme_ctx_t ceofcontext; gpgme_engine_info_t enginfo; gpgme_error_t err; gpgme_data_t data; size_t read_bytes; int tmp; /* The function `gpgme_check_version' must be called before any other * function in the library, because it initializes the thread support * subsystem in GPGME. (from the info page) */ setlocale (LC_ALL, ""); p = gpgme_check_version(NULL); printf("version=%s\n",p); /* set locale, because tests do also */ gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); err = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); if(err != GPG_ERR_NO_ERROR) return 10; p = gpgme_get_protocol_name(GPGME_PROTOCOL_OpenPGP); printf("Version: %s\n",p); /* get engine information */ err = gpgme_get_engine_info(&enginfo); if(err != GPG_ERR_NO_ERROR) return 3; printf("file=%s, home=%s\n",enginfo->file_name,enginfo->home_dir); /* create our own context */ err = gpgme_new(&ceofcontext); if(err != GPG_ERR_NO_ERROR) return 1; /* FIXME: check protocol availbility before! */ err = gpgme_set_protocol(ceofcontext,GPGME_PROTOCOL_OpenPGP); if(err != GPG_ERR_NO_ERROR) return 2; gpgme_set_textmode(ceofcontext,0); /* FIXME: both needed? */ /* FIXME: why is the path (FILE_NAME) needed? */ /* FIXME: /usr/bin/gpg must be changed to ~/.ceof/gpg/binary or similar */ err = gpgme_ctx_set_engine_info (ceofcontext, GPGME_PROTOCOL_OpenPGP, "/usr/bin/gpg","/home/user/nico/.ceof/gpg/"); if(err != GPG_ERR_NO_ERROR) return 4; /* do not ascii armor data */ //gpgme_set_armor(ceofcontext, 0); gpgme_set_armor(ceofcontext, 1); /* create buffer */ err = gpgme_data_new(&data); if(err != GPG_ERR_NO_ERROR) return 6; /* set encoding for the buffer... */ err = gpgme_data_set_encoding(data,GPGME_DATA_ENCODING_ARMOR); if(err != GPG_ERR_NO_ERROR) return 11; tmp = gpgme_data_get_encoding(data); if(tmp == GPGME_DATA_ENCODING_ARMOR) { printf("encode ok\n"); } else { printf("encode broken\n"); } /* export public key: WARNING: need to create buffer before! */ //err = gpgme_op_export(ceofcontext,"nico schottelius",0,data); // /* FIXME: gpgme_op_export vs. gpgme_op_export_ext vs. gpgme_op_export_start */ err = gpgme_op_export(ceofcontext,NULL,0,data); if(err != GPG_ERR_NO_ERROR) return 7; //err = gpgme_op_export_ext(ceofcontext,NULL,0,data); // err = gpgme_op_export_start(ceofcontext,NULL,0,data); // if(err != GPG_ERR_NO_ERROR) return 5; //gpgme_wait(ceofcontext,&err,1); /* from the t-exports.c file */ read_bytes = gpgme_data_seek (data, 0, SEEK_END); printf("end is=%d\n",read_bytes); if(read_bytes == -1) { p = gpgme_strerror(errno); printf("data-seek-err: %s\n",p); } read_bytes = gpgme_data_seek (data, 0, SEEK_SET); printf("start is=%d\n",read_bytes); while ((read_bytes = gpgme_data_read (data, buf, SIZE)) > 0) { write(1,buf,read_bytes); } write(1,"\n",1); /* FIXME: as developers to documentate how to use tha data buffer! */ read_bytes = gpgme_data_read(data, buf, sizeof (buf)); printf("Bytes: %d, bufsize=%d\n",read_bytes,sizeof(buf)); /* list keys */ // err = gpgpme_op_keylist_start(ceofcontext,NULL,0); //gpgme_op_keylist_next(ceofcontext, /* free data */ gpgme_data_release(data); /* free context */ gpgme_release(ceofcontext); // to ceof-dir? // gpgme_set_engine_info // (gpgme_protocol_t PROTO, const char *FILE_NAME, const char *HOME_DIR) // GPGME_PROTOCOL_OpenPGP // /* 4.1 Public Key Algorithms * GPGME_PK_RSA * 4.2 Hash Algorithms * 6.1.1 Memory Based Data Buffers * gpgme_error_t gpgme_data_new (gpgme_data_t *DH) * * 7 Contexts * -- Data type: gpgme_ctx_t * gpgme_error_t gpgme_new (gpgme_ctx_t *CTX) * GPG_ERR_NO_ERROR * * -- Function: gpgme_error_t gpgme_set_protocol (gpgme_ctx_t CTX, * gpgme_protocol_t PROTO) * * -- Function: gpgme_error_t gpgme_ctx_set_engine_info (gpgme_ctx_t CTX, * gpgme_protocol_t PROTO, const char *FILE_NAME, * const char *HOME_DIR) * */ return 0; }
signature.asc
Description: Digital signature
_______________________________________________ Gnupg-users mailing list Gnupg-users@gnupg.org http://lists.gnupg.org/mailman/listinfo/gnupg-users