PlainBlock.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2014 by Xiao Shaun Wang <wangxiao@cs.umd.edu>
  2. package com.oblivm.backend.oram;
  3. import com.oblivm.backend.util.Utils;
  4. public class PlainBlock {
  5. public long iden;
  6. public long pos;
  7. public boolean[] data;
  8. public boolean isDummy;
  9. public PlainBlock(long iden, long pos, boolean[] data, boolean isDummy) {
  10. this.iden = iden;
  11. this.pos = pos;
  12. this.data = data;
  13. this.isDummy = isDummy;
  14. }
  15. public boolean[] toBooleanArray(int lengthOfIden, int lengthOfPos) {
  16. boolean[] result = new boolean[lengthOfIden + lengthOfPos + data.length + 1];
  17. System.arraycopy(Utils.fromLong(iden, lengthOfIden), 0, result, 0, lengthOfIden);
  18. System.arraycopy(Utils.fromLong(pos, lengthOfIden), 0, result, lengthOfIden, lengthOfPos);
  19. System.arraycopy(data, 0, result, lengthOfPos + lengthOfIden, data.length);
  20. result[result.length - 1] = isDummy;
  21. return result;
  22. }
  23. static public boolean[] toBooleanArray(PlainBlock[] blocks, int lengthOfIden, int lengthOfPos) {
  24. int blockSize = (lengthOfIden + lengthOfPos + blocks[0].data.length + 1);
  25. boolean[] result = new boolean[blockSize * blocks.length];
  26. for (int i = 0; i < blocks.length; ++i) {
  27. boolean[] tmp = blocks[i].toBooleanArray(lengthOfIden, lengthOfPos);
  28. System.arraycopy(tmp, 0, result, i * blockSize, blockSize);
  29. }
  30. return result;
  31. }
  32. }