private static CipherSuitePredicate parseAndPredicate(CipherSuitePredicate item, final CodePointIterator i) { final ArrayList<CipherSuitePredicate> list = new ArrayList<>(); list.add(item); do { list.add(getSimplePredicateByName(i.delimitedBy('+', ':', ',', ' ').drainToString())); } while (i.hasNext() && i.next() == '+'); return CipherSuitePredicate.matchAll(list.toArray(new CipherSuitePredicate[list.size()])); }
private static CipherSuitePredicate parsePredicate(final CodePointIterator i) { return parsePredicate(i, i.delimitedBy('+', ':', ',', ' ').drainToString()); }
private String nameFor(Path path) { String fileName = path.toString(); fileName = fileName.substring(0, fileName.length() - 4); // remove ".xml" if (encoded) { CodePointIterator it = CodePointIterator.ofString(fileName); it.delimitedBy('-').skipAll(); it.next(); // skip '-' fileName = it.base32Decode(Base32Alphabet.STANDARD, false) .asUtf8String().drainToString(); } return fileName; }
static String[] dictionaryPropertyToArray(String property) throws SaslException { String[] dictionary = new String[OTP.DICTIONARY_SIZE]; CodePointIterator cpi = CodePointIterator.ofString(property); CodePointIterator di = cpi.delimitedBy(OTP.DICTIONARY_DELIMITER); for (int i = 0; i < dictionary.length; i++) { dictionary[i] = di.drainToString(); skipDelims(di, cpi, OTP.DICTIONARY_DELIMITER); } return dictionary; } }
private static boolean checkContentType(HttpURLConnection connection, String expectedMediaType) throws AcmeException { String contentType = connection.getContentType(); if (contentType == null) { return false; } CodePointIterator cpi = CodePointIterator.ofString(contentType); CodePointIterator di = cpi.delimitedBy(CONTENT_TYPE_DELIMS); String mediaType = di.drainToString().trim(); skipDelims(di, cpi, CONTENT_TYPE_DELIMS); while (di.hasNext()) { String parameter = di.drainToString().trim(); skipDelims(di, cpi, CONTENT_TYPE_DELIMS); if (parameter.equalsIgnoreCase(CHARSET)) { String value = di.drainToString().trim(); if (! value.equalsIgnoreCase(UTF_8)) { return false; } } } return mediaType.equalsIgnoreCase(expectedMediaType); }
static String[] realmListPropertyToArray(String realmList, int escapeCharacter, int... delims) { if (realmList == null) { return null; } final int[] escapeCharacterAndDelims = Arrays.copyOf(delims, delims.length + 1); escapeCharacterAndDelims[escapeCharacterAndDelims.length - 1] = escapeCharacter; final CodePointIterator cpi = CodePointIterator.ofString(realmList); final CodePointIterator di = cpi.delimitedBy(escapeCharacterAndDelims); final ArrayList<String> realms = new ArrayList<>(); StringBuilder realm = new StringBuilder(); while (cpi.hasNext()) { if (di.hasNext()) { di.drainTo(realm); } else { if (cpi.peekNext() == escapeCharacter) { cpi.next(); // skip the escape character if (cpi.hasNext()) { realm.append((char) cpi.next()); } } else { // reached the end of a realm name realms.add(realm.toString()); skipDelims(di, cpi, delims); realm = new StringBuilder(); } } } realms.add(realm.toString()); return realms.toArray(new String[realms.size()]); }
static String arrayToRealmListProperty(String[] realms, int escapeCharacter, int... delims) { if (realms == null) { return null; } final int[] escapeCharacterAndDelims = Arrays.copyOf(delims, delims.length + 1); escapeCharacterAndDelims[escapeCharacterAndDelims.length - 1] = escapeCharacter; StringBuilder realmList = new StringBuilder(); for (int i = 0; i < realms.length; i++) { if (i != 0) { addDelims(realmList, delims); } CodePointIterator cpi = CodePointIterator.ofString(realms[i]); CodePointIterator di = cpi.delimitedBy(escapeCharacterAndDelims); while (cpi.hasNext()) { if (di.hasNext()) { di.drainTo(realmList); } else { realmList.append((char) escapeCharacter); // escape the delimiter or escape character realmList.append((char) cpi.next()); } } } return realmList.toString(); }
private static String getKeyValue(final String requiredKey, final String keyAndValue) throws IllegalArgumentException { // key:value final CodePointIterator cpi = CodePointIterator.ofString(keyAndValue); final CodePointIterator di = cpi.delimitedBy(':'); if (! requiredKey.equalsIgnoreCase(di.drainToString())) { throw log.invalidCertificateExtensionStringValue(keyAndValue); } skipDelims(di, cpi, ':'); return di.drainToString(); }
private static List<AccessDescription> getAccessDescriptions(final String extensionValue) throws IllegalArgumentException { // method:location-type:location-value(,method:location-type:location-value)* final CodePointIterator cpi = CodePointIterator.ofString(extensionValue); final CodePointIterator di = cpi.delimitedBy(DELIMS); if (! di.hasNext()) { throw log.invalidCertificateExtensionStringValue(extensionValue); } List<AccessDescription> accessDescriptions = new ArrayList<>(); while (di.hasNext()) { accessDescriptions.add(getAccessDescription(di.drainToString())); skipDelims(di, cpi, DELIMS); } return accessDescriptions; }
private static List<GeneralName> getGeneralNames(final String extensionValue) throws IllegalArgumentException { // type:val(,type:val)* final CodePointIterator cpi = CodePointIterator.ofString(extensionValue); final CodePointIterator di = cpi.delimitedBy(DELIMS); if (! di.hasNext()) { throw log.invalidCertificateExtensionStringValue(extensionValue); } List<GeneralName> generalNames = new ArrayList<>(); while (di.hasNext()) { generalNames.add(getGeneralName(di.drainToString())); skipDelims(di, cpi, DELIMS); } return generalNames; }
/** * Convert the given hexadecimal OTP value into a hash. * * @param otp the OTP in hexadecimal format * @return the OTP hash that corresponds to the given hexadecimal value * @throws SaslException if an error occurs while parsing the hexadecimal value */ public static byte[] convertFromHex(String otp) throws SaslException { final CodePointIterator cpi = CodePointIterator.ofString(otp); final CodePointIterator di = cpi.delimitedBy(DELIMS); // Remove any white space final StringBuilder sb = new StringBuilder(); while (di.hasNext()) { di.drainTo(sb); skipDelims(di, cpi); } return CodePointIterator.ofString(sb.toString()).hexDecode().drain(); }
private static GeneralName getGeneralName(final String typeAndValue) throws IllegalArgumentException { // type:val final CodePointIterator cpi = CodePointIterator.ofString(typeAndValue); final CodePointIterator di = cpi.delimitedBy(':'); final String type = di.drainToString(); for (String requiredType : ALT_NAMES_TYPES) { if (requiredType.equalsIgnoreCase(type)) { skipDelims(di, cpi, ':'); final String value = cpi.drainToString(); switch (type.toUpperCase(Locale.ENGLISH)) { case EMAIL: return new GeneralName.RFC822Name(value); case URI: return new GeneralName.URIName(value); case DNS: return new GeneralName.DNSName(value); case IP: return new GeneralName.IPAddress(value); case OID: return new GeneralName.RegisteredID(value); default: throw log.invalidCertificateExtensionStringValue(typeAndValue); } } } throw log.invalidCertificateExtensionStringValue(typeAndValue); }
final CodePointIterator di = cpi.delimitedBy(DELIMS); final boolean ca = Boolean.parseBoolean(getKeyValue(CA, di.drainToString())); skipDelims(di, cpi, DELIMS); final CodePointIterator di = cpi.delimitedBy(DELIMS); if (! di.hasNext()) { throw log.invalidCertificateExtensionStringValue(extensionValue); final CodePointIterator di = cpi.delimitedBy(DELIMS); if (! di.hasNext()) { throw log.invalidCertificateExtensionStringValue(extensionValue);
private static AccessDescription getAccessDescription(final String methodAndTypeAndValue) throws IllegalArgumentException { // method:location-type:location-value final CodePointIterator cpi = CodePointIterator.ofString(methodAndTypeAndValue); final CodePointIterator di = cpi.delimitedBy(':'); if (! di.hasNext()) { throw log.invalidCertificateExtensionStringValue(methodAndTypeAndValue); } final String accessMethodId = oidFromMethod(di.drainToString()); skipDelims(di, cpi, ':'); final String typeAndValue = cpi.drainToString(); final GeneralName accessLocation = getGeneralName(typeAndValue); return new AccessDescription(accessMethodId, accessLocation); }
private static CipherSuiteSelector parseSpecial(final CipherSuiteSelector current, final CodePointIterator i) { String word = i.delimitedBy('=', ':').drainToString(); switch (word) { case "STRENGTH": { if (i.hasNext() && i.next() == '=') { throw ElytronMessages.log.mechSelectorTokenNotAllowed("=", i.getIndex(), i.drainToString()); } return current.sortByAlgorithmKeyLength(); } default: { throw ElytronMessages.log.mechSelectorUnknownToken(word, i.drainToString()); } } }
private static int parseModCryptIterationCount(final CodePointIterator reader, final int minIterations, final int maxIterations, final int defaultIterations) throws InvalidKeySpecException { int iterationCount; final CodePointIterator dr = reader.delimitedBy('$'); try { if (dr.limitedTo(7).contentEquals(CodePointIterator.ofString("rounds="))) {
private static Password parseUnixMD5CryptPasswordString(final char[] cryptString) throws InvalidKeySpecException { assert cryptString[0] == '$'; // previously tested by doIdentifyAlgorithm assert cryptString[1] == '1'; // previously tested by doIdentifyAlgorithm assert cryptString[2] == '$'; // previously tested by doIdentifyAlgorithm CodePointIterator r = CodePointIterator.ofChars(cryptString, 3); try { final byte[] salt = r.delimitedBy('$').drainToString().getBytes(StandardCharsets.ISO_8859_1); if (! r.hasNext()) { throw log.invalidKeySpecNoSaltTerminatorGiven(); } r.next(); // skip $ final byte[] decoded = r.base64Decode(MOD_CRYPT_LE, false).limitedTo(MD5_IDX_REV.length).drain(); if (decoded.length != MD5_IDX.length) { throw log.invalidHashLength(); } byte[] hash = ByteIterator.ofBytes(decoded, MD5_IDX_REV).drain(); return UnixMD5CryptPassword.createRaw(UnixMD5CryptPassword.ALGORITHM_CRYPT_MD5, salt, hash); } catch (NoSuchElementException e) { throw log.invalidKeySpecUnexpectedEndOfPasswordStringWithCause(e); } }
String type = pemContent.delimitedBy('-').drainToString(); final Matcher matcher = VALID_LABEL.matcher(type); if (!matcher.find() && pemContent.limitedTo(5).contentEquals("-----")) { throw log.malformedPemContent(pemContent.getIndex()); String type = pemContent.delimitedBy('-').drainToString(); final Matcher matcher = VALID_LABEL.matcher(type); if (matcher.find()) { throw log.malformedPemContent(pemContent.getIndex()); CodePointIterator delimitedIterator = pemContent.delimitedBy('-').skip(Character::isWhitespace).skipCrLf(); final ByteIterator byteIterator = delimitedIterator.base64Decode(); final R result = contentFunction.apply(type, byteIterator);
final CodePointIterator di = cpi.delimitedBy(DELIMS); final MessageDigest messageDigest; int dictionaryIndex = -1;
String password; try { final CodePointIterator delimIter = i.delimitedBy(0); authorizationId = delimIter.hasNext() ? delimIter.drainToString() : null;