read GpgmeData
    Marcus Brinkmann 
    Marcus.Brinkmann at ruhr-uni-bochum.de
       
    Tue Apr 29 16:22:04 CEST 2003
    
    
  
On Mon, Apr 28, 2003 at 11:00:24PM +0200, Florian Lindner wrote:
> Hello, 
> I'm rather a C++ programmer than C, therefor I've little excperience with 
> malloc, free and char[].
Writing a C++ wrapper for gpgme could be an interesting project, though.
Still, you should know about new and delete, and arrays, even if you started
out with C++.  malloc and free allocate and release memory explicitely as
the C++ operators new and delete do.
> How can I get the result of gpgme_data_release_and_get_mem into a std::string 
> object?
> 
> 	GpgmeData data, output;
> 	gpgme_data_new(&data);
> 	gpgme_data_new_from_mem(&data, m_text.c_str(), m_text.size(), 1);
> 	gpgme_op_encrypt(m_ctx, rec, data, output);
> 
> 	int length;
> 	gpgme_data_release_and_get_mem(output, &length);  // get the return value
You need to add a binary 0 to the data object:
gpgme_data_write (output, "", 1);
and then the return value of gpgme_data_release_and_get_mem is a standard C string
(if the data is in armor format, of course, and does not contain binary
zeroes).
    
    
More information about the Gnupg-devel
mailing list