/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.facebook.buck.cxx.toolchain.objectfile;

import com.facebook.buck.io.file.FileContentsScrubber;
import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Arrays;

public class LcUuidContentsScrubber implements FileContentsScrubber {

  private static final int UUID_LENGTH = 16;
  private static final byte[] ZERO_UUID = new byte[UUID_LENGTH];

  @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);

    resetUuidIfPresent(map);
    map.rewind();

    Hasher hasher = Hashing.sha1().newHasher();
    hasher.putBytes(map);

    map.rewind();
    try {
      Machos.setUuidIfPresent(map, Arrays.copyOf(hasher.hash().asBytes(), UUID_LENGTH));
    } catch (Machos.MachoException e) {
      throw new ScrubException(e.getMessage());
    }
  }

  /** Sets the LC_UUID to all zeroes if it's part of the Mach-O file. */
  protected static void resetUuidIfPresent(MappedByteBuffer map) throws ScrubException {
    try {
      Machos.setUuidIfPresent(map, ZERO_UUID);
    } catch (Machos.MachoException e) {
      throw new ScrubException(e.getMessage());
    }
  }
}

@@ -1437,12 +1437,19 @@
 ing.
-sha1
+murmur3_128
 ().n

Switch Mach-O file hashing to Murmur3