### Question:
PubkeyUtils { static String getAlgorithmForOid(String oid) throws NoSuchAlgorithmException { if ("1.2.840.10045.2.1".equals(oid)) { return "EC"; } else if ("1.2.840.113549.1.1.1".equals(oid)) { return "RSA"; } else if ("1.2.840.10040.4.1".equals(oid)) { return "DSA"; } else { throw new NoSuchAlgorithmException("Unknown algorithm OID " + oid); } } private  PubkeyUtils(); static String formatKey(Key key); static byte[] getEncodedPrivate(PrivateKey pk, String secret); static PrivateKey decodePrivate(byte[] encoded, String keyType); static PrivateKey decodePrivate(byte[] encoded, String keyType, String secret); static int getBitStrength(byte[] encoded, String keyType); static PublicKey decodePublic(byte[] encoded, String keyType); static KeyPair convertToKeyPair(PubkeyBean keybean, String password); static KeyPair recoverKeyPair(byte[] encoded); static String convertToOpenSSHFormat(PublicKey pk, String origNickname); static byte[] extractOpenSSHPublic(KeyPair pair); static String exportPEM(PrivateKey key, String secret); static final String PKCS8_START; static final String PKCS8_END; }### Answer:
@Test public void getAlgorithmForOid_NullInput_Failure() throws Exception { try { PubkeyUtils.getAlgorithmForOid(null); fail("Should throw NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException expected) { } }
@Test public void getAlgorithmForOid_UnknownOid_Failure() throws Exception { try { PubkeyUtils.getAlgorithmForOid("1.3.66666.2000.4000.1"); fail("Should throw NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException expected) { } }
@Test public void getAlgorithmForOid_Ecdsa() throws Exception { assertEquals("EC", PubkeyUtils.getAlgorithmForOid("1.2.840.10045.2.1")); }
@Test public void getAlgorithmForOid_Rsa() throws Exception { assertEquals("RSA", PubkeyUtils.getAlgorithmForOid("1.2.840.113549.1.1.1")); }
@Test @Ignore public void getAlgorithmForOid_Dsa() throws Exception { assertEquals("DSA", PubkeyUtils.getAlgorithmForOid("1.2.840.10040.4.1")); }