/*
- Copyright 2015 IoT.bzh
+ Copyright 2015, 2016, 2017 IoT.bzh
author: José Bollo <jose.bollo@iot.bzh>
#include <openssl/x509.h>
#include "verbose.h"
-#include "wgtpkg.h"
+#include "wgtpkg-certs.h"
+#include "wgtpkg-base64.h"
struct x509l {
- int count;
+ unsigned count;
X509 **certs;
};
static int add_certificate_x509(X509 *x)
{
- X509 **p = realloc(certificates.certs, (certificates.count + 1) * sizeof(X509*));
+ X509 **p = realloc(certificates.certs,
+ (certificates.count + 1) * sizeof(X509*));
if (!p) {
ERROR("reallocation failed for certificate");
return -1;
return 0;
}
-static int add_certificate_bin(const char *bin, int len)
+static int add_certificate_bin(const char *bin, size_t len)
{
int rc;
const char *b, *e;
int add_certificate_b64(const char *b64)
{
char *d;
- int l = base64dec(b64, &d);
- if (l > 0) {
- l = add_certificate_bin(d, l);
+ ssize_t l = base64dec(b64, &d);
+ int rc;
+ if (l < 0)
+ rc = -1;
+ else {
+ rc = add_certificate_bin(d, (size_t)l);
free(d);
}
- return l;
+ return rc;
}
void clear_certificates()