I'm currently writing a C++ application and would like to use GPGME for message signing, encryption and key management. I know I can encrypt data in this way:
err = gpgme_op_encrypt(mContext, recipients,...);
if(err) {
// .. error handling
}
result = gpgme_op_encrypt_result(mContext);
if(result->invalid_recipients){
//error handling
}
nbytes = gpgme_data_seek(encrypted_text, 0, SEEK_SET);
if(nbytes == -1) {
//error handling
}
buffer = malloc(MAXLEN);
nbytes = gpgme_data_read(encrypted_text, buffer, MAXLEN);
But as one can see I would have to use MAXLEN as limit for reading the encrypted data in my buffer. Is there a way to determine how long my encrypted data result will be in advance (given the plaintex)? Or will I have to accept the static limit?
I'm not familiar with this particular API but the
gpgme_data_seek
andgpgme_data_read
call look like they may behave likeread()
andseek()
from the file I/O system.(1) Simply allocate as much buffer as you can effort (lets say N).
(2) Call
n=gpgme_data_read(...,N)
untilN!=n
.(3) Check for error conditions (my guess is n<0)
proceed until you have processed all data you are interested in.