From 1164d876337e54baea97c77c51e02c9df45223cd Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 19 May 2020 12:11:37 +0000 Subject: [PATCH] python: Support passing two signing keys Signed-off-by: Michael Tremer --- src/python/location-importer.in | 3 ++- src/python/writer.c | 45 +++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/python/location-importer.in b/src/python/location-importer.in index eb4a303..3b7e37f 100644 --- a/src/python/location-importer.in +++ b/src/python/location-importer.in @@ -67,6 +67,7 @@ class CLI(object): write.set_defaults(func=self.handle_write) write.add_argument("file", nargs=1, help=_("Database File")) write.add_argument("--signing-key", nargs="?", type=open, help=_("Signing Key")) + write.add_argument("--backup-signing-key", nargs="?", type=open, help=_("Backup Signing Key")) write.add_argument("--vendor", nargs="?", help=_("Sets the vendor")) write.add_argument("--description", nargs="?", help=_("Sets a description")) write.add_argument("--license", nargs="?", help=_("Sets the license")) @@ -182,7 +183,7 @@ class CLI(object): Compiles a database in libloc format out of what is in the database """ # Allocate a writer - writer = location.Writer(ns.signing_key) + writer = location.Writer(ns.signing_key, ns.backup_signing_key) # Set all metadata if ns.vendor: diff --git a/src/python/writer.c b/src/python/writer.c index 557f3e1..a3ceae6 100644 --- a/src/python/writer.c +++ b/src/python/writer.c @@ -39,31 +39,56 @@ static void Writer_dealloc(WriterObject* self) { } static int Writer_init(WriterObject* self, PyObject* args, PyObject* kwargs) { - PyObject* private_key = NULL; - FILE* f = NULL; + PyObject* private_key1 = NULL; + PyObject* private_key2 = NULL; + FILE* f1 = NULL; + FILE* f2 = NULL; + int fd; // Parse arguments - if (!PyArg_ParseTuple(args, "|O", &private_key)) + if (!PyArg_ParseTuple(args, "|OO", &private_key1, &private_key2)) return -1; + // Ignore None + if (private_key1 == Py_None) { + Py_DECREF(private_key1); + private_key1 = NULL; + } + + if (private_key2 == Py_None) { + Py_DECREF(private_key2); + private_key2 = NULL; + } + // Convert into FILE* - if (private_key && private_key != Py_None) { - int fd = PyObject_AsFileDescriptor(private_key); + if (private_key1) { + fd = PyObject_AsFileDescriptor(private_key1); if (fd < 0) return -1; // Re-open file descriptor - f = fdopen(fd, "r"); - if (!f) { + f2 = fdopen(fd, "r"); + if (!f2) { PyErr_SetFromErrno(PyExc_IOError); return -1; } } - // Create the writer object - int r = loc_writer_new(loc_ctx, &self->writer, f, NULL); + if (private_key2) { + fd = PyObject_AsFileDescriptor(private_key2); + if (fd < 0) + return -1; - return r; + // Re-open file descriptor + f2 = fdopen(fd, "r"); + if (!f2) { + PyErr_SetFromErrno(PyExc_IOError); + return -1; + } + } + + // Create the writer object + return loc_writer_new(loc_ctx, &self->writer, f1, f2); } static PyObject* Writer_get_vendor(WriterObject* self) { -- 2.39.2