@Test public void testWrap_registerSecondWrapperForEncryptOnly_throws() throws Exception { assertThrows( GeneralSecurityException.class, () -> { Registry.registerPrimitiveWrapper( new PrimitiveWrapper<Mac, EncryptOnly>() { @Override public EncryptOnly wrap(PrimitiveSet<Mac> primitiveSet) { return null; } @Override public Class<EncryptOnly> getPrimitiveClass() { return EncryptOnly.class; } @Override public Class<Mac> getInputPrimitiveClass() { return Mac.class; } }); }); }
public static synchronized <B, P> void registerPrimitiveWrapper( final PrimitiveWrapper<B, P> wrapper) throws GeneralSecurityException { if (wrapper == null) { throw new IllegalArgumentException("wrapper must be non-null"); } Class<P> classObject = wrapper.getPrimitiveClass(); if (primitiveWrapperMap.containsKey(classObject)) { @SuppressWarnings("unchecked") PrimitiveWrapper<?, P> existingWrapper = (PrimitiveWrapper<?, P>) primitiveWrapperMap.get(classObject); if (!wrapper.getClass().equals(existingWrapper.getClass())) { logger.warning("Attempted overwrite of a registered SetWrapper for type " + classObject); throw new GeneralSecurityException( String.format( "SetWrapper for primitive (%s) is already registered to be %s, " + "cannot be re-registered with %s", classObject.getName(), existingWrapper.getClass().getName(), wrapper.getClass().getName())); } } primitiveWrapperMap.put(classObject, wrapper); }
Registry { public static synchronized <B, P> void registerPrimitiveWrapper( final PrimitiveWrapper<B, P> wrapper) throws GeneralSecurityException { if (wrapper == null) { throw new IllegalArgumentException("wrapper must be non-null"); } Class<P> classObject = wrapper.getPrimitiveClass(); if (primitiveWrapperMap.containsKey(classObject)) { @SuppressWarnings("unchecked") PrimitiveWrapper<?, P> existingWrapper = (PrimitiveWrapper<?, P>) primitiveWrapperMap.get(classObject); if (!wrapper.getClass().equals(existingWrapper.getClass())) { logger.warning("Attempted overwrite of a registered SetWrapper for type " + classObject); throw new GeneralSecurityException( String.format( "SetWrapper for primitive (%s) is already registered to be %s, " + "cannot be re-registered with %s", classObject.getName(), existingWrapper.getClass().getName(), wrapper.getClass().getName())); } } primitiveWrapperMap.put(classObject, wrapper); } }
Registry { public static synchronized <B, P> void registerPrimitiveWrapper( final PrimitiveWrapper<B, P> wrapper) throws GeneralSecurityException { if (wrapper == null) { throw new IllegalArgumentException("wrapper must be non-null"); } Class<P> classObject = wrapper.getPrimitiveClass(); if (primitiveWrapperMap.containsKey(classObject)) { @SuppressWarnings("unchecked") PrimitiveWrapper<?, P> existingWrapper = (PrimitiveWrapper<?, P>) primitiveWrapperMap.get(classObject); if (!wrapper.getClass().equals(existingWrapper.getClass())) { logger.warning("Attempted overwrite of a registered SetWrapper for type " + classObject); throw new GeneralSecurityException( String.format( "SetWrapper for primitive (%s) is already registered to be %s, " + "cannot be re-registered with %s", classObject.getName(), existingWrapper.getClass().getName(), wrapper.getClass().getName())); } } primitiveWrapperMap.put(classObject, wrapper); } private  Registry(); }
Registry { public static synchronized <B, P> void registerPrimitiveWrapper( final PrimitiveWrapper<B, P> wrapper) throws GeneralSecurityException { if (wrapper == null) { throw new IllegalArgumentException("wrapper must be non-null"); } Class<P> classObject = wrapper.getPrimitiveClass(); if (primitiveWrapperMap.containsKey(classObject)) { @SuppressWarnings("unchecked") PrimitiveWrapper<?, P> existingWrapper = (PrimitiveWrapper<?, P>) primitiveWrapperMap.get(classObject); if (!wrapper.getClass().equals(existingWrapper.getClass())) { logger.warning("Attempted overwrite of a registered SetWrapper for type " + classObject); throw new GeneralSecurityException( String.format( "SetWrapper for primitive (%s) is already registered to be %s, " + "cannot be re-registered with %s", classObject.getName(), existingWrapper.getClass().getName(), wrapper.getClass().getName())); } } primitiveWrapperMap.put(classObject, wrapper); } private  Registry(); @Deprecated static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue); @Deprecated static Catalogue<?> getCatalogue(String catalogueName); static synchronized void registerKeyManager(final KeyManager<P> manager); static synchronized void registerKeyManager(
      final KeyManager<P> manager, boolean newKeyAllowed); static synchronized void registerKeyManager(
      final KeyTypeManager<KeyProtoT> manager, boolean newKeyAllowed); static synchronized void registerAsymmetricKeyManagers(
          final PrivateKeyTypeManager<KeyProtoT, PublicKeyProtoT> privateKeyTypeManager,
          final KeyTypeManager<PublicKeyProtoT> publicKeyTypeManager,
          boolean newKeyAllowed); @Deprecated static synchronized void registerKeyManager(
      String typeUrl, final KeyManager<P> manager); @Deprecated static synchronized void registerKeyManager(
      String typeUrl, final KeyManager<P> manager, boolean newKeyAllowed); static synchronized void registerPrimitiveWrapper(
      final PrimitiveWrapper<B, P> wrapper); @Deprecated static KeyManager<P> getKeyManager(String typeUrl); static KeyManager<?> getUntypedKeyManager(String typeUrl); static KeyManager<P> getKeyManager(String typeUrl, Class<P> primitiveClass); static synchronized KeyData newKeyData(KeyTemplate keyTemplate); static synchronized MessageLite newKey(KeyTemplate keyTemplate); static synchronized MessageLite newKey(String typeUrl, MessageLite format); static KeyData getPublicKeyData(String typeUrl, ByteString serializedPrivateKey); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, MessageLite key); static P getPrimitive(String typeUrl, MessageLite key, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, ByteString serializedKey); static P getPrimitive(
      String typeUrl, ByteString serializedKey, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, byte[] serializedKey); static P getPrimitive(String typeUrl, byte[] serializedKey, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(KeyData keyData); static P getPrimitive(KeyData keyData, Class<P> primitiveClass); @Deprecated static PrimitiveSet<P> getPrimitives(KeysetHandle keysetHandle); static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, Class<P> primitiveClass); @Deprecated static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, final KeyManager<P> customManager); static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, final KeyManager<P> customManager, Class<P> primitiveClass); static P wrap(PrimitiveSet<B> primitiveSet, Class<P> clazz); static P wrap(PrimitiveSet<P> primitiveSet); static Class<?> getInputPrimitive(Class<?> wrappedPrimitive); }
Registry { public static synchronized <B, P> void registerPrimitiveWrapper( final PrimitiveWrapper<B, P> wrapper) throws GeneralSecurityException { if (wrapper == null) { throw new IllegalArgumentException("wrapper must be non-null"); } Class<P> classObject = wrapper.getPrimitiveClass(); if (primitiveWrapperMap.containsKey(classObject)) { @SuppressWarnings("unchecked") PrimitiveWrapper<?, P> existingWrapper = (PrimitiveWrapper<?, P>) primitiveWrapperMap.get(classObject); if (!wrapper.getClass().equals(existingWrapper.getClass())) { logger.warning("Attempted overwrite of a registered SetWrapper for type " + classObject); throw new GeneralSecurityException( String.format( "SetWrapper for primitive (%s) is already registered to be %s, " + "cannot be re-registered with %s", classObject.getName(), existingWrapper.getClass().getName(), wrapper.getClass().getName())); } } primitiveWrapperMap.put(classObject, wrapper); } private  Registry(); @Deprecated static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue); @Deprecated static Catalogue<?> getCatalogue(String catalogueName); static synchronized void registerKeyManager(final KeyManager<P> manager); static synchronized void registerKeyManager(
      final KeyManager<P> manager, boolean newKeyAllowed); static synchronized void registerKeyManager(
      final KeyTypeManager<KeyProtoT> manager, boolean newKeyAllowed); static synchronized void registerAsymmetricKeyManagers(
          final PrivateKeyTypeManager<KeyProtoT, PublicKeyProtoT> privateKeyTypeManager,
          final KeyTypeManager<PublicKeyProtoT> publicKeyTypeManager,
          boolean newKeyAllowed); @Deprecated static synchronized void registerKeyManager(
      String typeUrl, final KeyManager<P> manager); @Deprecated static synchronized void registerKeyManager(
      String typeUrl, final KeyManager<P> manager, boolean newKeyAllowed); static synchronized void registerPrimitiveWrapper(
      final PrimitiveWrapper<B, P> wrapper); @Deprecated static KeyManager<P> getKeyManager(String typeUrl); static KeyManager<?> getUntypedKeyManager(String typeUrl); static KeyManager<P> getKeyManager(String typeUrl, Class<P> primitiveClass); static synchronized KeyData newKeyData(KeyTemplate keyTemplate); static synchronized MessageLite newKey(KeyTemplate keyTemplate); static synchronized MessageLite newKey(String typeUrl, MessageLite format); static KeyData getPublicKeyData(String typeUrl, ByteString serializedPrivateKey); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, MessageLite key); static P getPrimitive(String typeUrl, MessageLite key, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, ByteString serializedKey); static P getPrimitive(
      String typeUrl, ByteString serializedKey, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, byte[] serializedKey); static P getPrimitive(String typeUrl, byte[] serializedKey, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(KeyData keyData); static P getPrimitive(KeyData keyData, Class<P> primitiveClass); @Deprecated static PrimitiveSet<P> getPrimitives(KeysetHandle keysetHandle); static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, Class<P> primitiveClass); @Deprecated static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, final KeyManager<P> customManager); static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, final KeyManager<P> customManager, Class<P> primitiveClass); static P wrap(PrimitiveSet<B> primitiveSet, Class<P> clazz); static P wrap(PrimitiveSet<P> primitiveSet); static Class<?> getInputPrimitive(Class<?> wrappedPrimitive);  }