text
stringlengths 0
357
|
|---|
Filename: dc_aheader.c
|
```c
|
#include <ctype.h>
|
#include "dc_context.h"
|
#include "dc_aheader.h"
|
#include "dc_apeerstate.h"
|
#include "dc_mimeparser.h"
|
/**
|
* Empty an Autocrypt-header object and free all data associated with it.
|
*
|
* @private @memberof dc_aheader_t
|
* @param aheader The Autocrypt-header object. If you pass NULL here, the function does nothing.
|
* @return None.
|
*/
|
void dc_aheader_empty(dc_aheader_t* aheader)
|
{
|
if (aheader==NULL) {
|
return;
|
}
|
aheader->prefer_encrypt = 0;
|
free(aheader->addr);
|
aheader->addr = NULL;
|
if (aheader->public_key->binary) {
|
dc_key_unref(aheader->public_key);
|
aheader->public_key = dc_key_new();
|
}
|
}
|
/*******************************************************************************
|
* Render Autocrypt Header
|
******************************************************************************/
|
/**
|
* @memberof dc_aheader_t
|
*/
|
char* dc_aheader_render(const dc_aheader_t* aheader)
|
{
|
int success = 0;
|
char* keybase64_wrapped = NULL;
|
dc_strbuilder_t ret;
|
dc_strbuilder_init(&ret, 0);
|
if (aheader==NULL || aheader->addr==NULL || aheader->public_key->binary==NULL || aheader->public_key->type!=DC_KEY_PUBLIC) {
|
goto cleanup;
|
}
|
dc_strbuilder_cat(&ret, "addr=");
|
dc_strbuilder_cat(&ret, aheader->addr);
|
dc_strbuilder_cat(&ret, "; ");
|
if (aheader->prefer_encrypt==DC_PE_MUTUAL) {
|
dc_strbuilder_cat(&ret, "prefer-encrypt=mutual; ");
|
}
|
dc_strbuilder_cat(&ret, "keydata= "); /* the trailing space together with dc_insert_breaks() allows a proper transport */
|
/* adds a whitespace every 78 characters, this allows libEtPan to wrap the lines according to RFC 5322
|
(which may insert a linebreak before every whitespace) */
|
if ((keybase64_wrapped = dc_key_render_base64(aheader->public_key, 78, " ", 0/*no checksum*/))==NULL) {
|
goto cleanup;
|
}
|
dc_strbuilder_cat(&ret, keybase64_wrapped);
|
success = 1;
|
cleanup:
|
if (!success) { free(ret.buf); ret.buf = NULL; }
|
free(keybase64_wrapped);
|
return ret.buf; /* NULL on errors, this may happen for various reasons */
|
}
|
/*******************************************************************************
|
* Parse Autocrypt Header
|
******************************************************************************/
|
static int add_attribute(dc_aheader_t* aheader, const char* name, const char* value /*may be NULL*/)
|
{
|
/* returns 0 if the attribute will result in an invalid header, 1 if the attribute is okay */
|
if (strcasecmp(name, "addr")==0)
|
{
|
if (value==NULL
|
|| !dc_may_be_valid_addr(value)
|
|| aheader->addr /* email already given */) {
|
return 0;
|
}
|
aheader->addr = dc_addr_normalize(value);
|
return 1;
|
}
|
#if 0 /* autocrypt 11/2017 no longer uses the type attribute and it will make the autocrypt header invalid */
|
else if (strcasecmp(name, "type")==0)
|
End of preview. Expand
in Data Studio
No dataset card yet
- Downloads last month
- 6