java_src/src/main/java/com/google/crypto/tink/Registry.java
/**
   * Tries to register {@code manager} for {@code manager.getKeyType()}. If {@code newKeyAllowed} is
   * true, users can generate new keys with this manager using the {@link Registry#newKey} methods.
   *
   * <p>If {@code newKeyAllowed} is true, also tries to register the key templates supported by
   * {@code manager}.
   *
   * <p>If there is an existing key manager, throws an exception if {@code manager} and the existing
   * key manager aren't instances of the same class, or if {@code newKeyAllowed} is true while the
   * existing key manager could not create new keys. Otherwise registration succeeds.
   *
   * @throws GeneralSecurityException if there's an existing key manager is not an instance of the
   *     class of {@code manager}, or the registration tries to re-enable the generation of new
   *     keys.
   * @throws GeneralSecurityException if there's an existing key template.
   */
Tries to register  manager for  manager.getKeyType(). If  newKeyAllowed is
true, users can generate new keys with this manager using the  Registry#newKey methods.

If  newKeyAllowed is true, also tries to register the key templates supported by
manager.

If there is an existing key manager, throws an exception if  manager and the existing
key manager aren't instances of the same class, or if  newKeyAllowed is true while the
existing key manager could not create new keys. Otherwise registration succeeds.

@throws GeneralSecurityException if there's an existing key manager is not an instance of the
class of  manager, or the registration tries to re-enable the generation of new
keys.
@throws GeneralSecurityException if there's an existing key template.
Tries to register manager for manager . getKeyType () . If newKeyAllowed is true users can generate new keys with this manager using the Registry#newKey methods . If newKeyAllowed is true also tries to register the key templates supported by manager . If there is an existing key manager throws an exception if manager and the existing key manager aren ' t instances of the same class or if newKeyAllowed is true while the existing key manager could not create new keys . Otherwise registration succeeds . @throws GeneralSecurityException if there ' s an existing key manager is not an instance of the class of manager or the registration tries to re - enable the generation of new keys . @throws GeneralSecurityException if there ' s an existing key template .
public static synchronized <KeyProtoT extends MessageLite, PublicKeyProtoT extends MessageLite>
      void registerAsymmetricKeyManagers(
          final PrivateKeyTypeManager<KeyProtoT, PublicKeyProtoT> privateKeyTypeManager,
          final KeyTypeManager<PublicKeyProtoT> publicKeyTypeManager,
          boolean newKeyAllowed)
          throws GeneralSecurityException {
    if (privateKeyTypeManager == null || publicKeyTypeManager == null) {
      throw new IllegalArgumentException("given key managers must be non-null.");
    }
    String privateTypeUrl = privateKeyTypeManager.getKeyType();
    String publicTypeUrl = publicKeyTypeManager.getKeyType();
    ensureKeyManagerInsertable(
        privateTypeUrl,
        privateKeyTypeManager.getClass(),
        newKeyAllowed ? privateKeyTypeManager.keyFactory().keyFormats() : Collections.emptyMap(),
        newKeyAllowed);
    ensureKeyManagerInsertable(
        publicTypeUrl, publicKeyTypeManager.getClass(), Collections.emptyMap(), false);
    if (privateTypeUrl.equals(publicTypeUrl)) {
      throw new GeneralSecurityException("Private and public key type must be different.");
    }
    if (keyManagerMap.containsKey(privateTypeUrl)) {
      Class<?> existingPublicKeyManagerClass =
          keyManagerMap.get(privateTypeUrl).publicKeyManagerClassOrNull();
      if (existingPublicKeyManagerClass != null) {
        if (!existingPublicKeyManagerClass
            .getName()
            .equals(publicKeyTypeManager.getClass().getName())) {
          logger.warning(
              "Attempted overwrite of a registered key manager for key type "
                  + privateTypeUrl
                  + " with inconsistent public key type "
                  + publicTypeUrl);
          throw new GeneralSecurityException(
              String.format(
                  "public key manager corresponding to %s is already registered with %s, cannot"
                      + " be re-registered with %s",
                  privateKeyTypeManager.getClass().getName(),
                  existingPublicKeyManagerClass.getName(),
                  publicKeyTypeManager.getClass().getName()));
        }
      }
    }
    if (!keyManagerMap.containsKey(privateTypeUrl)
        || keyManagerMap.get(privateTypeUrl).publicKeyManagerClassOrNull() == null) {
      keyManagerMap.put(
          privateTypeUrl,
          createPrivateKeyContainerFor(privateKeyTypeManager, publicKeyTypeManager));
      keyDeriverMap.put(privateTypeUrl, createDeriverFor(privateKeyTypeManager));
      if (newKeyAllowed) {
        registerKeyTemplates(
            privateKeyTypeManager.getKeyType(), privateKeyTypeManager.keyFactory().keyFormats());
      }
    }
    newKeyAllowedMap.put(privateTypeUrl, newKeyAllowed);
    if (!keyManagerMap.containsKey(publicTypeUrl)) {
      keyManagerMap.put(publicTypeUrl, createContainerFor(publicKeyTypeManager));
    }
    newKeyAllowedMap.put(publicTypeUrl, false);
  }
public static synchronized < KeyProtoT extends MessageLite , PublicKeyProtoT extends MessageLite > void registerAsymmetricKeyManagers ( final PrivateKeyTypeManager < KeyProtoT , PublicKeyProtoT > privateKeyTypeManager , final KeyTypeManager < PublicKeyProtoT > publicKeyTypeManager , boolean newKeyAllowed ) throws GeneralSecurityException { if ( privateKeyTypeManager == null || publicKeyTypeManager == null ) { throw new IllegalArgumentException ( "given key managers must be non-null." ) ; } String privateTypeUrl = privateKeyTypeManager . getKeyType ( ) ; String publicTypeUrl = publicKeyTypeManager . getKeyType ( ) ; ensureKeyManagerInsertable ( privateTypeUrl , privateKeyTypeManager . getClass ( ) , newKeyAllowed ? privateKeyTypeManager . keyFactory ( ) . keyFormats ( ) : Collections . emptyMap ( ) , newKeyAllowed ) ; ensureKeyManagerInsertable ( publicTypeUrl , publicKeyTypeManager . getClass ( ) , Collections . emptyMap ( ) , false ) ; if ( privateTypeUrl . equals ( publicTypeUrl ) ) { throw new GeneralSecurityException ( "Private and public key type must be different." ) ; } if ( keyManagerMap . containsKey ( privateTypeUrl ) ) { Class < ? > existingPublicKeyManagerClass = keyManagerMap . get ( privateTypeUrl ) . publicKeyManagerClassOrNull ( ) ; if ( existingPublicKeyManagerClass != null ) { if ( ! existingPublicKeyManagerClass . getName ( ) . equals ( publicKeyTypeManager . getClass ( ) . getName ( ) ) ) { logger . warning ( "Attempted overwrite of a registered key manager for key type " + privateTypeUrl + " with inconsistent public key type " + publicTypeUrl ) ; throw new GeneralSecurityException ( String . format ( "public key manager corresponding to %s is already registered with %s, cannot" + " be re-registered with %s" , privateKeyTypeManager . getClass ( ) . getName ( ) , existingPublicKeyManagerClass . getName ( ) , publicKeyTypeManager . getClass ( ) . getName ( ) ) ) ; } } } if ( ! keyManagerMap . containsKey ( privateTypeUrl ) || keyManagerMap . get ( privateTypeUrl ) . publicKeyManagerClassOrNull ( ) == null ) { keyManagerMap . put ( privateTypeUrl , createPrivateKeyContainerFor ( privateKeyTypeManager , publicKeyTypeManager ) ) ; keyDeriverMap . put ( privateTypeUrl , createDeriverFor ( privateKeyTypeManager ) ) ; if ( newKeyAllowed ) { registerKeyTemplates ( privateKeyTypeManager . getKeyType ( ) , privateKeyTypeManager . keyFactory ( ) . keyFormats ( ) ) ; } } newKeyAllowedMap . put ( privateTypeUrl , newKeyAllowed ) ; if ( ! keyManagerMap . containsKey ( publicTypeUrl ) ) { keyManagerMap . put ( publicTypeUrl , createContainerFor ( publicKeyTypeManager ) ) ; } newKeyAllowedMap . put ( publicTypeUrl , false ) ; }
Tries to register {@code manager} for {@code manager.getKeyType()}.
Tries to register { @code manager } for { @code manager . getKeyType () } .
// No key format because a public key manager cannot create new keys // We do not allow key derivation for public key types. It doesn't seem like this would make // sense.