SigUtil { public static Enums.HashType toHashType(HashType hash) throws GeneralSecurityException { switch (hash) { case SHA256: return Enums.HashType.SHA256; case SHA384: return Enums.HashType.SHA384; case SHA512: return Enums.HashType.SHA512; default: break; } throw new GeneralSecurityException("unsupported hash type: " + hash.name()); }  static void validateEcdsaParams(EcdsaParams params); static void validateRsaSsaPkcs1Params(RsaSsaPkcs1Params params); static void validateRsaSsaPssParams(RsaSsaPssParams params); static Enums.HashType toHashType(HashType hash); static EllipticCurves.CurveType toCurveType(EllipticCurveType type); static EllipticCurves.EcdsaEncoding toEcdsaEncoding(EcdsaSignatureEncoding encoding);  }
@Test public void testToHashType() throws Exception { assertEquals(Enums.HashType.SHA256, SigUtil.toHashType(HashType.SHA256)); assertEquals(Enums.HashType.SHA384, SigUtil.toHashType(HashType.SHA384)); assertEquals(Enums.HashType.SHA512, SigUtil.toHashType(HashType.SHA512)); try { SigUtil.toHashType(HashType.UNKNOWN_HASH); fail("Invalid hash, should have thrown exception"); } catch (GeneralSecurityException expected) { } }