@Test(expected = IllegalArgumentException.class) public void pinWithControlChars() { final String pinString = "\tAB:cd\u1234"; Pin.fromString("SHA256:" + pinString); }
public static Pin fromString(String string) { String[] pin = string.split(":", 2); if (pin.length != 2) { throw new IllegalArgumentException("Invalid pin string, expected: 'format-specifier:hex-string'."); } String type = pin[0]; String pinHex = pin[1]; switch (type) { case "SHA256": return new Sha256Pin(pinHex); case "PLAIN": return new PlainPin(pinHex); case "CERTSHA256": return new CertSha256Pin(pinHex); case "CERTPLAIN": return new CertPlainPin(pinHex); default: throw new IllegalArgumentException(); } }
Pin { public static Pin fromString(String string) { String[] pin = string.split(":", 2); if (pin.length != 2) { throw new IllegalArgumentException("Invalid pin string, expected: 'format-specifier:hex-string'."); } String type = pin[0]; String pinHex = pin[1]; switch (type) { case "SHA256": return new Sha256Pin(pinHex); case "PLAIN": return new PlainPin(pinHex); case "CERTSHA256": return new CertSha256Pin(pinHex); case "CERTPLAIN": return new CertPlainPin(pinHex); default: throw new IllegalArgumentException(); } } }
Pin { public static Pin fromString(String string) { String[] pin = string.split(":", 2); if (pin.length != 2) { throw new IllegalArgumentException("Invalid pin string, expected: 'format-specifier:hex-string'."); } String type = pin[0]; String pinHex = pin[1]; switch (type) { case "SHA256": return new Sha256Pin(pinHex); case "PLAIN": return new PlainPin(pinHex); case "CERTSHA256": return new CertSha256Pin(pinHex); case "CERTPLAIN": return new CertPlainPin(pinHex); default: throw new IllegalArgumentException(); } } protected  Pin(byte[] pinBytes); protected  Pin(String pinHexString); }
Pin { public static Pin fromString(String string) { String[] pin = string.split(":", 2); if (pin.length != 2) { throw new IllegalArgumentException("Invalid pin string, expected: 'format-specifier:hex-string'."); } String type = pin[0]; String pinHex = pin[1]; switch (type) { case "SHA256": return new Sha256Pin(pinHex); case "PLAIN": return new PlainPin(pinHex); case "CERTSHA256": return new CertSha256Pin(pinHex); case "CERTPLAIN": return new CertPlainPin(pinHex); default: throw new IllegalArgumentException(); } } protected  Pin(byte[] pinBytes); protected  Pin(String pinHexString); abstract boolean pinsCertificate(X509Certificate x509certificate); static Pin fromString(String string); }
Pin { public static Pin fromString(String string) { String[] pin = string.split(":", 2); if (pin.length != 2) { throw new IllegalArgumentException("Invalid pin string, expected: 'format-specifier:hex-string'."); } String type = pin[0]; String pinHex = pin[1]; switch (type) { case "SHA256": return new Sha256Pin(pinHex); case "PLAIN": return new PlainPin(pinHex); case "CERTSHA256": return new CertSha256Pin(pinHex); case "CERTPLAIN": return new CertPlainPin(pinHex); default: throw new IllegalArgumentException(); } } protected  Pin(byte[] pinBytes); protected  Pin(String pinHexString); abstract boolean pinsCertificate(X509Certificate x509certificate); static Pin fromString(String string);  }