Commit 1164d876 authored by Michael Tremer's avatar Michael Tremer

python: Support passing two signing keys

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 5ce881d4
......@@ -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:
......
......@@ -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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment