@Test public void getPrimitive_throwsForUnknownPrimitives() throws Exception { KeyTypeManager<AesGcmKey> keyManager = new TestKeyTypeManager(); try { keyManager.getPrimitive(AesGcmKey.getDefaultInstance(), Primitive1.class); fail(); } catch (IllegalArgumentException e) { } }
public final <P> P getPrimitive(KeyProtoT key, Class<P> primitiveClass) throws GeneralSecurityException { @SuppressWarnings("unchecked") PrimitiveFactory<P, KeyProtoT> factory = (PrimitiveFactory<P, KeyProtoT>) factories.get(primitiveClass); if (factory == null) { throw new IllegalArgumentException( "Requested primitive class " + primitiveClass.getCanonicalName() + " not supported."); } return factory.getPrimitive(key); }
KeyTypeManager { public final <P> P getPrimitive(KeyProtoT key, Class<P> primitiveClass) throws GeneralSecurityException { @SuppressWarnings("unchecked") PrimitiveFactory<P, KeyProtoT> factory = (PrimitiveFactory<P, KeyProtoT>) factories.get(primitiveClass); if (factory == null) { throw new IllegalArgumentException( "Requested primitive class " + primitiveClass.getCanonicalName() + " not supported."); } return factory.getPrimitive(key); } }
KeyTypeManager { public final <P> P getPrimitive(KeyProtoT key, Class<P> primitiveClass) throws GeneralSecurityException { @SuppressWarnings("unchecked") PrimitiveFactory<P, KeyProtoT> factory = (PrimitiveFactory<P, KeyProtoT>) factories.get(primitiveClass); if (factory == null) { throw new IllegalArgumentException( "Requested primitive class " + primitiveClass.getCanonicalName() + " not supported."); } return factory.getPrimitive(key); } @SafeVarargs // Safe because we do not reference the array (see Effective Java ed. 3, Item 32). protected  KeyTypeManager(Class<KeyProtoT> clazz, PrimitiveFactory<?, KeyProtoT>... factories); }
KeyTypeManager { public final <P> P getPrimitive(KeyProtoT key, Class<P> primitiveClass) throws GeneralSecurityException { @SuppressWarnings("unchecked") PrimitiveFactory<P, KeyProtoT> factory = (PrimitiveFactory<P, KeyProtoT>) factories.get(primitiveClass); if (factory == null) { throw new IllegalArgumentException( "Requested primitive class " + primitiveClass.getCanonicalName() + " not supported."); } return factory.getPrimitive(key); } @SafeVarargs // Safe because we do not reference the array (see Effective Java ed. 3, Item 32). protected  KeyTypeManager(Class<KeyProtoT> clazz, PrimitiveFactory<?, KeyProtoT>... factories); final Class<KeyProtoT> getKeyClass(); abstract String getKeyType(); abstract int getVersion(); abstract KeyMaterialType keyMaterialType(); abstract KeyProtoT parseKey(ByteString byteString); abstract void validateKey(KeyProtoT keyProto); final P getPrimitive(KeyProtoT key, Class<P> primitiveClass); final Set<Class<?>> supportedPrimitives(); KeyFactory<?, KeyProtoT> keyFactory(); }
KeyTypeManager { public final <P> P getPrimitive(KeyProtoT key, Class<P> primitiveClass) throws GeneralSecurityException { @SuppressWarnings("unchecked") PrimitiveFactory<P, KeyProtoT> factory = (PrimitiveFactory<P, KeyProtoT>) factories.get(primitiveClass); if (factory == null) { throw new IllegalArgumentException( "Requested primitive class " + primitiveClass.getCanonicalName() + " not supported."); } return factory.getPrimitive(key); } @SafeVarargs // Safe because we do not reference the array (see Effective Java ed. 3, Item 32). protected  KeyTypeManager(Class<KeyProtoT> clazz, PrimitiveFactory<?, KeyProtoT>... factories); final Class<KeyProtoT> getKeyClass(); abstract String getKeyType(); abstract int getVersion(); abstract KeyMaterialType keyMaterialType(); abstract KeyProtoT parseKey(ByteString byteString); abstract void validateKey(KeyProtoT keyProto); final P getPrimitive(KeyProtoT key, Class<P> primitiveClass); final Set<Class<?>> supportedPrimitives(); KeyFactory<?, KeyProtoT> keyFactory();  }