private static Node updateTreeWithPublicPath()

in AsynchronousRatchetingTree/src/main/java/com/facebook/research/asynchronousratchetingtree/art/ART.java [162:199]


  private static Node updateTreeWithPublicPath(Node tree, int i, DHPubKey[] newPath, int pathIndex) {
    int l = leftTreeSize(tree.numLeaves());
    if (newPath.length - 1 == pathIndex) {
      return new PublicLeafNode(newPath[pathIndex]);
    }

    ParentNode result;
    ParentNode treeAsParent = (ParentNode) tree;
    Node newLeft;
    Node newRight;

    if (i < l) {
      newLeft = updateTreeWithPublicPath(treeAsParent.getLeft(), i, newPath, pathIndex + 1);
      newRight = treeAsParent.getRight();
    } else {
      newLeft = treeAsParent.getLeft();
      newRight = updateTreeWithPublicPath(treeAsParent.getRight(), i - l, newPath, pathIndex + 1);
    }

    if (newLeft instanceof SecretNode) {
      result = new SecretParentNode((SecretNode)newLeft, newRight);
    } else if (newRight instanceof SecretNode) {
      result = new SecretParentNode(newLeft, (SecretNode)newRight);
    } else {
      result = new PublicParentNode(
        newPath[pathIndex],
        newLeft,
        newRight
      );
    }

    if (!Arrays.equals(result.getPubKey().getPubKeyBytes(), newPath[pathIndex].getPubKeyBytes())) {
      Utils.printTree(result);
      Utils.except("Update operation inconsistent with provided path.");
    }

    return result;
  }