Py_TYPE(self)->tp_free((PyObject *)self);
}
+static uint64_t Key_id_to_int(const pakfire_key_id* id) {
+ uint64_t i = 0;
+
+ for (unsigned int j = 0; j < sizeof(*id); j++) {
+ // Shift i by one byte & append the next byte
+ i = (i << 8) | (*id)[j];
+ }
+
+ return i;
+}
+
static PyObject* Key_repr(KeyObject* self) {
const pakfire_key_id* id = pakfire_key_get_id(self->key);
- return PyUnicode_FromFormat("<_pakfire.Key (%lu)>", *id);
+ return PyUnicode_FromFormat("<_pakfire.Key (%lu)>", Key_id_to_int(id));
}
static PyObject* Key_str(KeyObject* self) {
static PyObject* Key_get_id(KeyObject* self) {
const pakfire_key_id* id = pakfire_key_get_id(self->key);
- return PyLong_FromUnsignedLong(*id);
+ uint64_t i = Key_id_to_int(id);
+
+ return PyLong_FromUnsignedLong(i);
}
static PyObject* Key_get_algorithm(KeyObject* self) {
with open(path, "rb") as f:
return self.pakfire.import_key(f)
- def test_import(self):
+ def test_import_public_key(self):
# Import a public key
key = self._import("keys/key1.pub")
+ # Check for the correct key ID
+ self.assertEqual(key.id, 13863674484496905947)
+
+ def test_import_secret_key(self):
# Import a secret key
key = self._import("keys/key1.sec")
+ # Check for the correct key ID
+ self.assertEqual(key.id, 13863674484496905947)
+
if __name__ == "__main__":
unittest.main()