java_src/src/main/java/com/google/crypto/tink/Registry.java
/**
   * Throws a general security exception if one of these conditions holds:
   *
   * <ul>
   *   <li>There is already a key manager registered for {@code typeURL}, and at least one of the
   *       following is true:
   *       <ul>
   *         <li>The class implementing the existing key manager differs from the given one.
   *         <li>The value of {@code newKeyAllowed} currently registered is false, but the input
   *             parameter is true.
   *       </ul>
   *   <li>The {@code newKeyAllowed} flag is true, and at least one of the following is true:
   *       <ul>
   *         <li>The key manager was already registered, but it contains new key templates.
   *         <li>The key manager is new, but it contains existing key templates.
   */
Throws a general security exception if one of these conditions holds:

There is already a key manager registered for  typeURL, and at least one of the
following is true:

The class implementing the existing key manager differs from the given one.
The value of  newKeyAllowed currently registered is false, but the input
parameter is true.

The  newKeyAllowed flag is true, and at least one of the following is true:

The key manager was already registered, but it contains new key templates.
The key manager is new, but it contains existing key templates.
Throws a general security exception if one of these conditions holds : There is already a key manager registered for typeURL and at least one of the following is true : The class implementing the existing key manager differs from the given one . The value of newKeyAllowed currently registered is false but the input parameter is true . The newKeyAllowed flag is true and at least one of the following is true : The key manager was already registered but it contains new key templates . The key manager is new but it contains existing key templates .
private static synchronized <KeyProtoT extends MessageLite, KeyFormatProtoT extends MessageLite>
      void ensureKeyManagerInsertable(
          String typeUrl,
          Class<?> implementingClass,
          Map<String, KeyTypeManager.KeyFactory.KeyFormat<KeyFormatProtoT>> keyFormats,
          boolean newKeyAllowed)
          throws GeneralSecurityException {
    KeyManagerContainer container = keyManagerMap.get(typeUrl);
    if (container != null && !container.getImplementingClass().equals(implementingClass)) {
      logger.warning("Attempted overwrite of a registered key manager for key type " + typeUrl);
      throw new GeneralSecurityException(
          String.format(
              "typeUrl (%s) is already registered with %s, cannot be re-registered with %s",
              typeUrl, container.getImplementingClass().getName(), implementingClass.getName()));
    }
    if (newKeyAllowed && newKeyAllowedMap.containsKey(typeUrl) && !newKeyAllowedMap.get(typeUrl)) {
      throw new GeneralSecurityException("New keys are already disallowed for key type " + typeUrl);
    }
    if (newKeyAllowed) {
      if (keyManagerMap.containsKey(typeUrl)) {
        for (Map.Entry<String, KeyTypeManager.KeyFactory.KeyFormat<KeyFormatProtoT>> entry :
            keyFormats.entrySet()) {
          if (!keyTemplateMap.containsKey(entry.getKey())) {
            throw new GeneralSecurityException(
                "Attempted to register a new key template "
                    + entry.getKey()
                    + " from an existing key manager of type "
                    + typeUrl);
          }
        }
      } else {
        for (Map.Entry<String, KeyTypeManager.KeyFactory.KeyFormat<KeyFormatProtoT>> entry :
            keyFormats.entrySet()) {
          if (keyTemplateMap.containsKey(entry.getKey())) {
            throw new GeneralSecurityException(
                "Attempted overwrite of a registered key template " + entry.getKey());
          }
        }
      }
    }
  }
private static synchronized < KeyProtoT extends MessageLite , KeyFormatProtoT extends MessageLite > void ensureKeyManagerInsertable ( String typeUrl , Class < ? > implementingClass , Map < String , KeyTypeManager . KeyFactory . KeyFormat < KeyFormatProtoT > > keyFormats , boolean newKeyAllowed ) throws GeneralSecurityException { KeyManagerContainer container = keyManagerMap . get ( typeUrl ) ; if ( container != null && ! container . getImplementingClass ( ) . equals ( implementingClass ) ) { logger . warning ( "Attempted overwrite of a registered key manager for key type " + typeUrl ) ; throw new GeneralSecurityException ( String . format ( "typeUrl (%s) is already registered with %s, cannot be re-registered with %s" , typeUrl , container . getImplementingClass ( ) . getName ( ) , implementingClass . getName ( ) ) ) ; } if ( newKeyAllowed && newKeyAllowedMap . containsKey ( typeUrl ) && ! newKeyAllowedMap . get ( typeUrl ) ) { throw new GeneralSecurityException ( "New keys are already disallowed for key type " + typeUrl ) ; } if ( newKeyAllowed ) { if ( keyManagerMap . containsKey ( typeUrl ) ) { for ( Map . Entry < String , KeyTypeManager . KeyFactory . KeyFormat < KeyFormatProtoT > > entry : keyFormats . entrySet ( ) ) { if ( ! keyTemplateMap . containsKey ( entry . getKey ( ) ) ) { throw new GeneralSecurityException ( "Attempted to register a new key template " + entry . getKey ( ) + " from an existing key manager of type " + typeUrl ) ; } } } else { for ( Map . Entry < String , KeyTypeManager . KeyFactory . KeyFormat < KeyFormatProtoT > > entry : keyFormats . entrySet ( ) ) { if ( keyTemplateMap . containsKey ( entry . getKey ( ) ) ) { throw new GeneralSecurityException ( "Attempted overwrite of a registered key template " + entry . getKey ( ) ) ; } } } } }
Throws a general security exception if one of these conditions holds:
 <ul>
   <li>There is already a key manager registered for {@code typeURL}, and at least one of the
       following is true:
       <ul>
         <li>The class implementing the existing key manager differs from the given one.
Throws a general security exception if one of these conditions holds : <ul > <li > There is already a key manager registered for { @code typeURL } and at least one of the following is true : <ul > <li > The class implementing the existing key manager differs from the given one .
// When re-inserting an already present KeyTypeManager, no new key templates should be // present. // Check that new key managers can't overwrite existing key templates.