Merge "Inline two short methods from Conscrypt"

am: 9da9b33cc2

Change-Id: I4c66064ec1a0569f7766282d6dbee5202906ae00
This commit is contained in:
Adam Vartanian
2018-09-25 02:04:57 -07:00
committed by android-build-merger

View File

@@ -16,26 +16,23 @@
package android.security.net.config;
import android.os.Environment;
import android.os.UserHandle;
import android.util.ArraySet;
import android.util.Log;
import android.util.Pair;
import libcore.io.IoUtils;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.security.cert.Certificate;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Collections;
import java.util.Set;
import libcore.io.IoUtils;
import com.android.org.conscrypt.Hex;
import com.android.org.conscrypt.NativeCrypto;
import javax.security.auth.x500.X500Principal;
@@ -192,8 +189,36 @@ abstract class DirectoryCertificateSource implements CertificateSource {
}
private String getHash(X500Principal name) {
int hash = NativeCrypto.X509_NAME_hash_old(name);
return Hex.intToHexString(hash, 8);
int hash = hashName(name);
return intToHexString(hash, 8);
}
private static final char[] DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
private static String intToHexString(int i, int minWidth) {
int bufLen = 8; // Max number of hex digits in an int
char[] buf = new char[bufLen];
int cursor = bufLen;
do {
buf[--cursor] = DIGITS[i & 0xf];
} while ((i >>>= 4) != 0 || (bufLen - cursor < minWidth));
return new String(buf, cursor, bufLen - cursor);
}
// This code matches the code in X509_NAME_hash_old() in Conscrypt, which in turn matches
// the names of certificate files. It must be kept in sync.
private static int hashName(X500Principal principal) {
try {
byte[] digest = MessageDigest.getInstance("MD5").digest(principal.getEncoded());
int offset = 0;
return (((digest[offset++] & 0xff) << 0) | ((digest[offset++] & 0xff) << 8)
| ((digest[offset++] & 0xff) << 16) | ((digest[offset] & 0xff) << 24));
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
private X509Certificate readCertificate(String file) {