### Question:
ZeusUtils { public static KeyPair parseKey(String keyIn, List<ErrorEntry> errors) { KeyPair kp = null; List<PemBlock> blocks = PemUtils.parseMultiPem(keyIn); Object obj; if (blocks.size() < 1) { errors.add(new ErrorEntry(ErrorType.UNREADABLE_KEY, KEYREQUIRED, true, null)); return null; } if (blocks.size() > 1) { errors.add(new ErrorEntry(ErrorType.UNREADABLE_KEY, "Multiple pem blocks used in Key", true, null)); return null; } obj = blocks.get(0).getDecodedObject(); if (obj == null) { errors.add(new ErrorEntry(ErrorType.UNREADABLE_KEY, "Unable to parse pemblock to RSA Key", true, null)); return null; } if (obj instanceof BCRSAPrivateCrtKey) { try { obj = RSAKeyUtils.getPemKeyPair((BCRSAPrivateCrtKey) obj); } catch (PemException ex) { errors.add(new ErrorEntry(ErrorType.UNREADABLE_KEY, "Error while attempting to convert key from PKCS8 to PKCS1", true, ex)); return null; } } if (!(obj instanceof KeyPair)) { String msg = String.format("%s keyobject was an instance of %s but was expecting a %s", ERRORDECODINGKEY, obj.getClass().getName(), KeyPair.class.getCanonicalName()); errors.add(new ErrorEntry(ErrorType.UNREADABLE_KEY, msg, true, null)); return null; } kp = (KeyPair) obj; if (!(kp.getPublic() instanceof BCRSAPublicKey)) { String msg = String.format("%s Error decoding public portion of key. Objected decoded to class %s but was expecting %s", ERRORDECODINGKEY, obj.getClass().getName(), BCRSAPublicKey.class.getCanonicalName()); errors.add(new ErrorEntry(ErrorType.UNREADABLE_KEY, msg, true, null)); kp = null; return kp; } if (!(kp.getPrivate() instanceof BCRSAPrivateCrtKey)) { String msg = String.format("%s Error decoding private portion of key. Object decoded to class %s but was expecting %s", ERRORDECODINGKEY, obj.getClass().getName(), BCRSAPrivateCrtKey.class.getCanonicalName()); errors.add(new ErrorEntry(ErrorType.UNREADABLE_KEY, msg, true, null)); kp = null; return kp; } return kp; } ZeusUtils();  ZeusUtils(Set<X509CertificateHolder> roots); ZeusCrtFile buildZeusCrtFileLbassValidation(String userKeyStr, String userCrtStr, String intermediates); Set<X509CertificateHolder> getRoots(); void setRoots(Set<X509CertificateHolder> roots); static KeyPair parseKey(String keyIn, List<ErrorEntry> errors); static X509CertificateHolder parseCert(String certIn, List<ErrorEntry> errors); static Set<X509CertificateHolder> parseIntermediateCerts(String intermediates, List<ErrorEntry> errors); static List<X509CertificateHolder> decodeImd(Map<X509CertificateHolder, Integer> lineMap, String imdStr, ZeusCrtFile zcf);  }### Answer:
@Test public void shouldValidateWellFormedKey() { List<ErrorEntry> errors = new ArrayList<ErrorEntry>(); ZeusUtils.parseKey(workingUserKey, errors); Assert.assertTrue(errors.isEmpty()); }
@Test public void shouldInvalidateMalformedKey() { List<ErrorEntry> errors = new ArrayList<ErrorEntry>(); ZeusUtils.parseKey("foobar", errors); Assert.assertFalse(errors.isEmpty()); Assert.assertEquals(ErrorType.UNREADABLE_KEY, errors.get(0).getErrorType()); }