В расширении Chrome NaCl, которое шифрует данные, полученные от браузера, и должно возвращать зашифрованный текст через PostMessage()
, у меня возникают проблемы с отправкой типа данных unsigned char*
для ciphertext
. Спецификация pp::Var ничего не говорит о такой форме данные. Я попытался преобразовать unsigned char
в std::string
, но не нашел подходящего способа сделать это. Мой фрагмент кода выглядит следующим образом:
if(action == "encryption")
{
pp::Var var_content = dict_message.Get("content");
if (!var_action.is_string())
return;
std::string content = var_content.AsString();
//encryption code starts here
const char *password = "password";
unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
int len = content.length()+EVP_MAX_BLOCK_LENGTH;
unsigned char *ciphertext = (unsigned char*)malloc(len*sizeof(unsigned char));
aes_init(password, (int)strlen(password), key, iv);
len = encrypt((unsigned char*)(content.c_str()), (int)strlen(content.c_str()), key, iv, ciphertext);
pp::Var var_reply(ciphertext);
PostMessage(var_reply);
free(ciphertext);
}
Это возвращает ошибку времени компиляции:
crest.cc:55:15: error: calling a private constructor of class 'pp::Var'
pp::Var var_reply(ciphertext);
^
/home/kunal/Downloads/nacl_sdk/pepper_41/include/ppapi/cpp/var.h:318:3: note: declared private here
Var(void* non_scriptable_object_pointer);
^
1 error generated.
make: *** [pnacl/Release/crest.o] Error 1