1 // This file is under GNU General Public License 3.0
6 #include "pEp_internal.h"
7 #include "internal_format.h"
9 static struct _internal_message_type {
12 const char *mime_type;
15 { 'K', 0, "application/keys" },
18 { 'K', 2, "application/pgp-keys" },
21 { 'K', 3, "application/pkcs10" },
22 { 'K', 4, "application/pkix-cert" },
23 { 'K', 5, "application/pkix-crl" },
24 { 'K', 6, "application/pkcs7-mime" },
25 { 'K', 7, "application/x-x509-ca-cert" },
26 { 'K', 8, "application/x-x509-user-cert" },
27 { 'K', 9, "application/x-pkcs7-crl" },
28 { 'K', 10, "application/x-pem-file" },
29 { 'K', 11, "application/x-pkcs12" },
30 { 'K', 12, "application/x-pkcs7-certificates" },
31 { 'K', 13, "application/x-pkcs7-certreqresp" },
34 { 'S', 0, "application/pEp.sync" },
37 { 'D', 0, "application/pEp.distribution" },
38 { 'D', 0, "application/pEp.keyreset" },
41 { 'A', 0, "application/auth" },
42 { 'A', 1, "application/signature" },
45 { 'A', 2, "application/pgp-signature" },
48 { 'A', 3, "application/pkcs7-signature" },
49 { 'A', 3, "application/x-pkcs7-signature" },
55 DYNAMIC_API PEP_STATUS encode_internal(
58 const char *mime_type,
63 assert(value && size && mime_type && code && code_size);
64 if (!(value && size && mime_type && code && code_size))
65 return PEP_ILLEGAL_VALUE;
73 struct _internal_message_type *mt;
74 for (mt = message_type; mt->type; ++mt) {
75 if (strcasecmp(mime_type, mt->mime_type) == 0) {
77 subtype = mt->subtype;
82 // unsupported MIME type
86 // those are more BSOBs than BLOBS, so we copy
87 char *result = malloc(size + 4);
90 return PEP_OUT_OF_MEMORY;
97 memcpy(result + 4, value, size);
100 *code_size = size + 4;
102 return PEP_STATUS_OK;
105 DYNAMIC_API PEP_STATUS decode_internal(
113 assert(value && size && mime_type && code && !code[0] && code_size);
114 if (!(value && size && mime_type && code && !code[0] && code_size))
115 return PEP_ILLEGAL_VALUE;
121 // elevated attachments have at least 5 bytes
122 assert(code_size > 4);
124 return PEP_ILLEGAL_VALUE;
128 char subtype = code[2];
129 // char reserved = code[3];
131 char *_mime_type = NULL;
133 struct _internal_message_type *mt;
134 for (mt = message_type; mt->type; ++mt) {
135 if (type == mt->type && subtype == mt->subtype) {
136 assert(mt->mime_type);
137 _mime_type = strdup(mt->mime_type);
140 return PEP_OUT_OF_MEMORY;
147 return PEP_ILLEGAL_VALUE;
149 char *result = malloc(code_size - 4);
153 return PEP_OUT_OF_MEMORY;
156 memcpy(result, code + 4, code_size - 4);
159 *size = code_size - 4;
160 *mime_type = _mime_type;
162 return PEP_STATUS_OK;