static int KeyLocator_key_to_ndn(struct ndn_charbuf *keylocator, PyObject *py_key) { struct ndn_pkey *key; int r; if (!NDNObject_IsValid(PKEY_PUB, py_key)) { PyErr_SetString(PyExc_TypeError, "Argument needs to be of type NDN Key"); return -1; } key = NDNObject_Get(PKEY_PUB, py_key); r = ndn_charbuf_append_tt(keylocator, NDN_DTAG_Key, NDN_DTAG); JUMP_IF_NEG_MEM(r, error); r = ndn_append_pubkey_blob(keylocator, key); JUMP_IF_NEG_MEM(r, error); r = ndn_charbuf_append_closer(keylocator); /* </Key> */ JUMP_IF_NEG_MEM(r, error); r = 0; error: return r; }
int build_keylocator_from_key(struct ndn_charbuf** keylocator, struct ndn_pkey* key) { int res = 0; *keylocator = ndn_charbuf_create(); ndn_charbuf_append_tt(*keylocator, NDN_DTAG_KeyLocator, NDN_DTAG); ndn_charbuf_append_tt(*keylocator, NDN_DTAG_Key, NDN_DTAG); res = ndn_append_pubkey_blob(*keylocator, key); ndn_charbuf_append_closer(*keylocator); /* </Key> */ ndn_charbuf_append_closer(*keylocator); /* </KeyLocator> */ return(res); }