@Test void testParseThrowsNoSuchElementException() { thrown = assertThrows(NoSuchElementException.class, () -> CryptographicServiceMessage.parse("") ); assertNull(thrown.getMessage()); }
public static CryptographicServiceMessage parse(String csmString) throws ParsingException { CryptographicServiceMessage csm = new CryptographicServiceMessage(); StringTokenizer st = new StringTokenizer(csmString, "() \t\n\r\f"); if (!st.nextToken().equalsIgnoreCase("CSM")) throw new ParsingException("Invalid CSM, doesn't start with the \"CSM(\" tag: " + csmString); do { String field = st.nextToken(); int separatorIndex = field.indexOf('/'); if (separatorIndex > 0) { String tag = field.substring(0, separatorIndex).toUpperCase(); String content = ""; if (separatorIndex < field.length()) content = field.substring(separatorIndex + 1); if (tag.equalsIgnoreCase("MCL")) csm.setMCL(content); else csm.addField(tag, content); } else throw new ParsingException("Invalid field, doesn't have a tag: " + field); } while (st.hasMoreTokens()); if (csm.getMCL() == null) throw new ParsingException("Invalid CSM, doesn't contain an MCL: " + csmString); return csm; }
CryptographicServiceMessage implements Loggeable { public static CryptographicServiceMessage parse(String csmString) throws ParsingException { CryptographicServiceMessage csm = new CryptographicServiceMessage(); StringTokenizer st = new StringTokenizer(csmString, "() \t\n\r\f"); if (!st.nextToken().equalsIgnoreCase("CSM")) throw new ParsingException("Invalid CSM, doesn't start with the \"CSM(\" tag: " + csmString); do { String field = st.nextToken(); int separatorIndex = field.indexOf('/'); if (separatorIndex > 0) { String tag = field.substring(0, separatorIndex).toUpperCase(); String content = ""; if (separatorIndex < field.length()) content = field.substring(separatorIndex + 1); if (tag.equalsIgnoreCase("MCL")) csm.setMCL(content); else csm.addField(tag, content); } else throw new ParsingException("Invalid field, doesn't have a tag: " + field); } while (st.hasMoreTokens()); if (csm.getMCL() == null) throw new ParsingException("Invalid CSM, doesn't contain an MCL: " + csmString); return csm; } }
CryptographicServiceMessage implements Loggeable { public static CryptographicServiceMessage parse(String csmString) throws ParsingException { CryptographicServiceMessage csm = new CryptographicServiceMessage(); StringTokenizer st = new StringTokenizer(csmString, "() \t\n\r\f"); if (!st.nextToken().equalsIgnoreCase("CSM")) throw new ParsingException("Invalid CSM, doesn't start with the \"CSM(\" tag: " + csmString); do { String field = st.nextToken(); int separatorIndex = field.indexOf('/'); if (separatorIndex > 0) { String tag = field.substring(0, separatorIndex).toUpperCase(); String content = ""; if (separatorIndex < field.length()) content = field.substring(separatorIndex + 1); if (tag.equalsIgnoreCase("MCL")) csm.setMCL(content); else csm.addField(tag, content); } else throw new ParsingException("Invalid field, doesn't have a tag: " + field); } while (st.hasMoreTokens()); if (csm.getMCL() == null) throw new ParsingException("Invalid CSM, doesn't contain an MCL: " + csmString); return csm; } CryptographicServiceMessage();  CryptographicServiceMessage(String mcl); }
CryptographicServiceMessage implements Loggeable { public static CryptographicServiceMessage parse(String csmString) throws ParsingException { CryptographicServiceMessage csm = new CryptographicServiceMessage(); StringTokenizer st = new StringTokenizer(csmString, "() \t\n\r\f"); if (!st.nextToken().equalsIgnoreCase("CSM")) throw new ParsingException("Invalid CSM, doesn't start with the \"CSM(\" tag: " + csmString); do { String field = st.nextToken(); int separatorIndex = field.indexOf('/'); if (separatorIndex > 0) { String tag = field.substring(0, separatorIndex).toUpperCase(); String content = ""; if (separatorIndex < field.length()) content = field.substring(separatorIndex + 1); if (tag.equalsIgnoreCase("MCL")) csm.setMCL(content); else csm.addField(tag, content); } else throw new ParsingException("Invalid field, doesn't have a tag: " + field); } while (st.hasMoreTokens()); if (csm.getMCL() == null) throw new ParsingException("Invalid CSM, doesn't contain an MCL: " + csmString); return csm; } CryptographicServiceMessage();  CryptographicServiceMessage(String mcl); void setMCL(String mcl); String getMCL(); void addField(String tag, String content); String getFieldContent(String tag); @Override String toString(); @Override void dump(PrintStream p, String indent); static CryptographicServiceMessage parse(String csmString); }
CryptographicServiceMessage implements Loggeable { public static CryptographicServiceMessage parse(String csmString) throws ParsingException { CryptographicServiceMessage csm = new CryptographicServiceMessage(); StringTokenizer st = new StringTokenizer(csmString, "() \t\n\r\f"); if (!st.nextToken().equalsIgnoreCase("CSM")) throw new ParsingException("Invalid CSM, doesn't start with the \"CSM(\" tag: " + csmString); do { String field = st.nextToken(); int separatorIndex = field.indexOf('/'); if (separatorIndex > 0) { String tag = field.substring(0, separatorIndex).toUpperCase(); String content = ""; if (separatorIndex < field.length()) content = field.substring(separatorIndex + 1); if (tag.equalsIgnoreCase("MCL")) csm.setMCL(content); else csm.addField(tag, content); } else throw new ParsingException("Invalid field, doesn't have a tag: " + field); } while (st.hasMoreTokens()); if (csm.getMCL() == null) throw new ParsingException("Invalid CSM, doesn't contain an MCL: " + csmString); return csm; } CryptographicServiceMessage();  CryptographicServiceMessage(String mcl); void setMCL(String mcl); String getMCL(); void addField(String tag, String content); String getFieldContent(String tag); @Override String toString(); @Override void dump(PrintStream p, String indent); static CryptographicServiceMessage parse(String csmString); static final String MCL_RSI; static final String MCL_KSM; static final String MCL_RSM; static final String MCL_ESM; static final String TAG_RCV; static final String TAG_ORG; static final String TAG_SVR; static final String TAG_KD; static final String TAG_CTP; static final String TAG_CTR; static final String TAG_ERF; }