/** * Convenience method for creating a new primitive for the key given in {@code proto}. * * <p>It looks up a {@link KeyManager} identified by {@code type_url}, and calls {@link * KeyManager#getPrimitive} with {@code serialized} as the parameter. * * @return a new primitive */ @SuppressWarnings("TypeParameterUnusedInFormals") public static <P> P getPrimitive(String typeUrl, ByteString serialized) throws GeneralSecurityException { KeyManager<P> manager = getKeyManager(typeUrl); return manager.getPrimitive(serialized); }
/** * Convenience method for creating a new primitive for the key given in {@code proto}. * * <p>It looks up a {@link KeyManager} identified by {@code type_url}, and calls {@link * KeyManager#getPrimitive} with {@code key} as the parameter. * * @return a new primitive */ @SuppressWarnings("TypeParameterUnusedInFormals") public static <P> P getPrimitive(String typeUrl, MessageLite key) throws GeneralSecurityException { KeyManager<P> manager = getKeyManager(typeUrl); return manager.getPrimitive(key); }
/** * Convenience method for extracting the public key data from the private key given in {@code * serializedPrivateKey}. * * <p>It looks up a {@link PrivateKeyManager} identified by {@code typeUrl}, and calls {@link * PrivateKeyManager#getPublicKeyData} with {@code serializedPrivateKey} as the parameter. * * @return a new key */ @SuppressWarnings("unchecked") public static <P> KeyData getPublicKeyData(String typeUrl, ByteString serializedPrivateKey) throws GeneralSecurityException { PrivateKeyManager<P> manager = (PrivateKeyManager) getKeyManager(typeUrl); return manager.getPublicKeyData(serializedPrivateKey); }
/** * Convenience method for generating a new key for the specified {@code format}. * * <p>It looks up a {@link KeyManager} identified by {@code keyTemplate.type_url}, and calls * {@link KeyManager#newKey} with {@code format} as the parameter. * * @return a new key */ public static synchronized <P> MessageLite newKey(String typeUrl, MessageLite format) throws GeneralSecurityException { KeyManager<P> manager = getKeyManager(typeUrl); if (newKeyAllowedMap.get(typeUrl).booleanValue()) { return manager.newKey(format); } else { throw new GeneralSecurityException("newKey-operation not permitted for key type " + typeUrl); } }
KeyManager<P> existingManager = getKeyManager(typeUrl); boolean existingNewKeyAllowed = newKeyAllowedMap.get(typeUrl).booleanValue(); if (!manager.getClass().equals(existingManager.getClass())
/** * Convenience method for generating a new key for the specified {@code keyTemplate}. * * <p>It looks up a {@link KeyManager} identified by {@code keyTemplate.type_url}, and calls * {@link KeyManager#newKey} with {@code keyTemplate} as the parameter. * * @return a new key */ public static synchronized <P> MessageLite newKey(KeyTemplate keyTemplate) throws GeneralSecurityException { KeyManager<P> manager = getKeyManager(keyTemplate.getTypeUrl()); if (newKeyAllowedMap.get(keyTemplate.getTypeUrl()).booleanValue()) { return manager.newKey(keyTemplate.getValue()); } else { throw new GeneralSecurityException( "newKey-operation not permitted for key type " + keyTemplate.getTypeUrl()); } }
/** * Convenience method for generating a new {@link KeyData} for the specified {@code template}. * * <p>It looks up a {@link KeyManager} identified by {@code keyTemplate.type_url}, and calls * {@link KeyManager#newKeyData}. * * <p>This method should be used solely for key management. * * @return a new {@link KeyData} */ public static synchronized <P> KeyData newKeyData(KeyTemplate keyTemplate) throws GeneralSecurityException { KeyManager<P> manager = getKeyManager(keyTemplate.getTypeUrl()); if (newKeyAllowedMap.get(keyTemplate.getTypeUrl()).booleanValue()) { return manager.newKeyData(keyTemplate.getValue()); } else { throw new GeneralSecurityException( "newKey-operation not permitted for key type " + keyTemplate.getTypeUrl()); } }