// Path: netsecurity/src/main/java/com/commonsware/cwac/netsecurity/conscrypt/Hex.java
// public class Hex {
//     private Hex() {}
// 
//     private final static char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
// 
//     public static String bytesToHexString(byte[] bytes) {
//         char[] buf = new char[bytes.length * 2];
//         int c = 0;
//         for (byte b : bytes) {
//             buf[c++] = DIGITS[(b >> 4) & 0xf];
//             buf[c++] = DIGITS[b & 0xf];
//         }
//         return new String(buf);
//     }
// 
//     public 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);
//     }
// 
// }


import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.security.auth.x500.X500Principal;
import com.commonsware.cwac.netsecurity.conscrypt.Hex;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
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;
                }
                certs.add(cert);
            }
        }
        return certs != null ? certs : Collections.<X509Certificate>emptySet();
    }

    private X509Certificate findCert(X500Principal subj, CertSelector selector) {
        String hash = getHash(subj);
        for (int index = 0; index >= 0; index++) {
            String fileName = hash + "." + index;
            if (!new File(mDir, fileName).exists()) {
                break;
            }
            if (isCertMarkedAsRemoved(fileName)) {
                continue;
            }
            X509Certificate cert = readCertificate(fileName);
            if (!subj.equals(cert.getSubjectX500Principal())) {
                continue;
            }
            if (selector.match(cert)) {
                return cert;
            }
        }
        return null;
    }

    private String getHash(X500Principal name) {
        int hash = /* NativeCrypto. */X509_NAME_hash_old(name);
// Path: netsecurity/src/main/java/com/commonsware/cwac/netsecurity/conscrypt/Hex.java
// public class Hex {
//     private Hex() {}
// 
//     private final static char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
// 
//     public static String bytesToHexString(byte[] bytes) {
//         char[] buf = new char[bytes.length * 2];
//         int c = 0;
//         for (byte b : bytes) {
//             buf[c++] = DIGITS[(b >> 4) & 0xf];
//             buf[c++] = DIGITS[b & 0xf];
//         }
//         return new String(buf);
//     }
// 
//     public 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);
//     }
// 
// }


// Path: netsecurity/src/main/java/com/commonsware/cwac/netsecurity/config/DirectoryCertificateSource.java
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.security.auth.x500.X500Principal;
import com.commonsware.cwac.netsecurity.conscrypt.Hex;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
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;

                }
                certs.add(cert);
            }
        }
        return certs != null ? certs : Collections.<X509Certificate>emptySet();
    }

    private X509Certificate findCert(X500Principal subj, CertSelector selector) {
        String hash = getHash(subj);
        for (int index = 0; index >= 0; index++) {
            String fileName = hash + "." + index;
            if (!new File(mDir, fileName).exists()) {
                break;
            }
            if (isCertMarkedAsRemoved(fileName)) {
                continue;
            }
            X509Certificate cert = readCertificate(fileName);
            if (!subj.equals(cert.getSubjectX500Principal())) {
                continue;
            }
            if (selector.match(cert)) {
                return cert;
            }
        }
        return null;
    }

    private String getHash(X500Principal name) {
        int hash = /* NativeCrypto. */X509_NAME_hash_old(name);
        return Hex.intToHexString(hash, 8);