@VisibleForTesting
 static Sha1HashCode computeAbiKey(ImmutableSortedMap<String, HashCode> classNames) {
   Hasher hasher = Hashing.sha1().newHasher();
   for (Map.Entry<String, HashCode> entry : classNames.entrySet()) {
     hasher.putUnencodedChars(entry.getKey());
     hasher.putByte((byte) 0);
     hasher.putUnencodedChars(entry.getValue().toString());
     hasher.putByte((byte) 0);
   }
   return Sha1HashCode.fromHashCode(hasher.hash());
 }
  @Override
  public void scrubFile(FileChannel file) throws IOException, ScrubException {
    if (!Machos.isMacho(file)) {
      return;
    }

    long size = file.size();
    MappedByteBuffer map = file.map(FileChannel.MapMode.READ_WRITE, 0, size);

    try {
      Machos.setUuid(map, ZERO_UUID);
    } catch (Machos.MachoException e) {
      throw new ScrubException(e.getMessage());
    }
    map.rewind();

    Hasher hasher = Hashing.sha1().newHasher();
    while (map.hasRemaining()) {
      hasher.putByte(map.get());
    }

    map.rewind();
    try {
      Machos.setUuid(map, Arrays.copyOf(hasher.hash().asBytes(), 16));
    } catch (Machos.MachoException e) {
      throw new ScrubException(e.getMessage());
    }
  }
 @Override
 public int read() throws IOException {
   int b = in.read();
   if (b != -1) {
     for (Hasher hasher : hashers.values()) {
       hasher.putByte((byte) b);
     }
     count++;
   }
   return b;
 }
示例#4
0
文件: RuleKey.java 项目: Nouhi/buck
 private Builder separate() {
   hasher.putByte(SEPARATOR);
   return this;
 }