text stringlengths 0 357 |
|---|
void dc_pgp_init(void) |
{ |
if (s_io_initialized) { |
return; |
} |
memset(&s_io, 0, sizeof(pgp_io_t)); |
s_io.outs = stdout; |
s_io.errs = stderr; |
s_io.res = stderr; |
s_io_initialized = 1; |
} |
#endif // !DC_USE_RPGP |
void dc_pgp_exit(void) |
{ |
} |
#ifdef DC_USE_RPGP |
void dc_pgp_rand_seed(dc_context_t* context, const void* buf, size_t bytes) {} |
#else // !DC_USE_RPGP |
void dc_pgp_rand_seed(dc_context_t* context, const void* buf, size_t bytes) |
{ |
if (buf==NULL || bytes<=0) { |
return; |
} |
RAND_seed(buf, bytes); |
} |
#endif // !DC_USE_RPGP |
/* Split data from PGP Armored Data as defined in https://tools.ietf.org/html/rfc4880#section-6.2. |
The given buffer is modified and the returned pointers just point inside the modified buffer, |
no additional data to free therefore. |
(NB: netpgp allows only parsing of Version, Comment, MessageID, Hash and Charset) */ |
int dc_split_armored_data(char* buf, const char** ret_headerline, const char** ret_setupcodebegin, const char** ret_preferencrypt, const char** ret_base64) |
{ |
int success = 0; |
size_t line_chars = 0; |
char* line = buf; |
char* p1 = buf; |
char* p2 = NULL; |
char* headerline = NULL; |
char* base64 = NULL; |
#define PGP_WS "\t\r\n " |
if (ret_headerline) { *ret_headerline = NULL; } |
if (ret_setupcodebegin) { *ret_setupcodebegin = NULL; } |
if (ret_preferencrypt) { *ret_preferencrypt = NULL; } |
if (ret_base64) { *ret_base64 = NULL; } |
if (buf==NULL || ret_headerline==NULL) { |
goto cleanup; |
} |
dc_remove_cr_chars(buf); |
while (*p1) { |
if (*p1=='\n') { |
/* line found ... */ |
line[line_chars] = 0; |
if (headerline==NULL) { |
/* ... headerline */ |
dc_trim(line); |
if (strncmp(line, "-----BEGIN ", 11)==0 && strncmp(&line[strlen(line)-5], "-----", 5)==0) { |
headerline = line; |
if (ret_headerline) { |
*ret_headerline = headerline; |
} |
} |
} |
else if (strspn(line, PGP_WS)==strlen(line)) { |
/* ... empty line: base64 starts on next line */ |
base64 = p1+1; |
break; |
} |
else if ((p2=strchr(line, ':'))==NULL) { |
/* ... non-standard-header without empty line: base64 starts with this line */ |
line[line_chars] = '\n'; |
base64 = line; |
break; |
} |
else { |
/* header line */ |
*p2 = 0; |
dc_trim(line); |
if (strcasecmp(line, "Passphrase-Begin")==0) { |
p2++; |
dc_trim(p2); |
if (ret_setupcodebegin) { |
*ret_setupcodebegin = p2; |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.