def on_key(request, id): for i in range(0, len(key_id)): if compare(key_id[i], id): return dps.set_key(request, dps.KeySymmetric(key_data[i])) if compare(network_key_id, id): return dps.set_key(request, dps.KeySymmetric(network_key)) if compare(publisher_id, id): return dps.set_key(request, dps.KeyCert(publisher_cert)); if compare(subscriber_id, id): return dps.set_key(request, dps.KeyCert(subscriber_cert, subscriber_private_key, subscriber_password)); return dps.ERR_MISSING
def on_ephemeral_key(request, key): if key.type == dps.KEY_SYMMETRIC: return dps.set_key(request, dps.KeySymmetric(os.urandom(32))) elif key.type == dps.KEY_EC: if key.curve == dps.EC_CURVE_P384: curve = ec.SECP384R1() n = 48 elif key.curve == dps.EC_CURVE_P521: curve = ec.SECP521R1() n = 66 k = ec.generate_private_key(curve, default_backend()) x = int_to_bytes(k.public_key().public_numbers().x, n) y = int_to_bytes(k.public_key().public_numbers().y, n) d = int_to_bytes(k.private_numbers().private_value, n) return dps.set_key(request, dps.KeyEC(key.curve, x, y, d)) else: return dps.ERR_MISSING