def enc_tree_node()

in src/ppxgboost/PPBooster.py [0:0]


def enc_tree_node(he_pub_key, prf_hash_key, ope, tree_node, metaData):
    """
    Process the node
    :param metaData:
    :param he_pub_key: the homomorphic key
    :param prf_hash_key: hash key for hmac
    :param ope: ope object for encrypting the comparison value
    :param tree_node: the Interier object (node) in the decision tree.
    :return: ope encrypted tree
    """
    # If it is not leaf, then encode the comp_val using OPE.
    if not isinstance(tree_node, bs.Leaf):

        num = metaData.affine_transform(tree_node.cmp_val)

        if num > MAX_NUM_OPE_ENC or num < 0:
            raise Exception("Invalid input: input is out of range (0, " + MAX_NUM_OPE_ENC +
                            "), system cannot encrypt", num)

        tree_node.cmp_val = ope.encrypt(num)

        hmac_code = hmac_msg(prf_hash_key, tree_node.feature_name)
        tree_node.feature_name = hmac_code

        # Recurse to the if true tree_node
        enc_tree_node(he_pub_key, prf_hash_key, ope, tree_node.if_true_child, metaData)
        # Recurse to the if false tree_node
        enc_tree_node(he_pub_key, prf_hash_key, ope, tree_node.if_false_child, metaData)
    # else it is the bs.Leaf
    else:
        # Value....
        tree_node.value = paillier.encrypt(he_pub_key, tree_node.value)