From b442dada5d57732ce8be55083caa6a10bd0d64e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Mon, 25 Jun 2007 17:24:43 +0000 Subject: [PATCH] Use hx509_pem_write. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21306 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/hx509/ks_file.c | 48 +++------------------------------------------ 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/lib/hx509/ks_file.c b/lib/hx509/ks_file.c index 87a57b682..ae8d1ef0e 100644 --- a/lib/hx509/ks_file.c +++ b/lib/hx509/ks_file.c @@ -610,48 +610,6 @@ file_free(hx509_certs certs, void *data) return 0; } -static void -pem_header(FILE *f, const char *type, const char *str) -{ - fprintf(f, "-----%s %s-----\n", type, str); -} - -static int -dump_pem_file(hx509_context context, const char *header, - FILE *f, const void *data, size_t size) -{ - const char *p = data; - size_t length; - char *line; - -#define ENCODE_LINE_LENGTH 54 - - pem_header(f, "BEGIN", header); - - while (size > 0) { - ssize_t l; - - length = size; - if (length > ENCODE_LINE_LENGTH) - length = ENCODE_LINE_LENGTH; - - l = base64_encode(p, length, &line); - if (l < 0) { - hx509_set_error_string(context, 0, ENOMEM, - "malloc - out of memory"); - return ENOMEM; - } - size -= length; - fprintf(f, "%s\n", line); - p += length; - free(line); - } - - pem_header(f, "END", header); - - return 0; -} - static int store_private_key(hx509_context context, FILE *f, hx509_private_key key) { @@ -660,8 +618,8 @@ store_private_key(hx509_context context, FILE *f, hx509_private_key key) ret = _hx509_private_key_export(context, key, &data); if (ret == 0) - dump_pem_file(context, _hx509_private_pem_name(key), f, - data.data, data.length); + hx509_pem_write(context, _hx509_private_pem_name(key), NULL, f, + data.data, data.length); free(data.data); return ret; } @@ -677,7 +635,7 @@ store_func(hx509_context context, void *ctx, hx509_cert c) if (ret) return ret; - dump_pem_file(context, "CERTIFICATE", f, data.data, data.length); + hx509_pem_write(context, "CERTIFICATE", NULL, f, data.data, data.length); free(data.data); if (_hx509_cert_private_key_exportable(c))