BIO を char 配列に保存 (パイプ/コピー) したい。サイズがわかっている場合は機能しますが、そうでない場合は機能しません。
たとえば、これを使用して char* の内容を BIO に保存できます。
const unsigned char* data = ...
myBio = BIO_new_mem_buf((void*)data, strlen(data));
しかし、BIO (以前に作成したもの) を出力に使用する SMIME_write_CMS を使用しようとすると、機能しません。
const int SIZE = 50000;
unsigned char *temp = malloc(SIZE);
memset(temp, 0, SIZE);
out = BIO_new_mem_buf((void*)temp, SIZE);
if (!out) {
NSLog(@"Couldn't create new file!");
assert(false);
}
int finished = SMIME_write_CMS(out, cms, in, flags);
if (!finished) {
NSLog(@"SMIME write CMS didn't succeed!");
assert(false);
}
printf("cms encrypted: %s\n", temp);
NSLog(@"All succeeded!");
OpenSSL リファレンスは、BIO で直接ファイル出力を使用します。これは機能しますが、objective-c で BIO_new_file() を使用できません... :-/
out = BIO_new_file("smencr.txt", "w");
if (!out)
goto err;
/* Write out S/MIME message */
if (!SMIME_write_CMS(out, cms, in, flags))
goto err;
何か提案はありますか?