Class MutableSerializationRegistry


  • public final class MutableSerializationRegistry
    extends java.lang.Object
    A Mutable version of the SerializationRegistry.

    This class probably shouldn't exist; it would be better if we had only the SerializationRegistry. However, at the moment, we need this, since a call to e.g.

     AesCmacKeyManager.register() 
    should register such an object into a global, mutable registry.
    • Constructor Detail

      • MutableSerializationRegistry

        public MutableSerializationRegistry()
    • Method Detail

      • hasParserForKey

        public <SerializationT extends Serialization> boolean hasParserForKey​(SerializationT serializedKey)
        Returns true if a parser for this serializedKey has been registered.
      • parseKey

        public <SerializationT extends SerializationKey parseKey​(SerializationT serializedKey,
                                                                   @Nullable
                                                                   SecretKeyAccess access)
                                                            throws java.security.GeneralSecurityException
        Parses the given serialization into a Key.

        This will look up a previously registered parser for the passed in SerializationT class, and the used object identifier (as indicated by serializedKey.getObjectIdentifier()), and then parse the object with this parsers.

        Throws:
        java.security.GeneralSecurityException
      • parseKeyWithLegacyFallback

        public Key parseKeyWithLegacyFallback​(ProtoKeySerialization protoKeySerialization,
                                              @Nullable
                                              SecretKeyAccess access)
                                       throws java.security.GeneralSecurityException
        Returns a Key object from a protoKeySerialization, even if no parser has been registered.

        Falling back is useful because we want users to be able to call #getAt even for key types for which we did not yet register a parser; in this case we simply fall back to return a LegacyProtoKey.

        Throws:
        java.security.GeneralSecurityException - if a parser is registered but parsing fails or required SecretKeyAccess is missing
      • hasSerializerForKey

        public <KeyT extends Key,​SerializationT extends Serialization> boolean hasSerializerForKey​(KeyT key,
                                                                                                         java.lang.Class<SerializationT> serializationClass)
        Returns true if a parser for this serializedKey has been registered.
      • serializeKey

        public <KeyT extends Key,​SerializationT extends Serialization> SerializationT serializeKey​(KeyT key,
                                                                                                         java.lang.Class<SerializationT> serializationClass,
                                                                                                         @Nullable
                                                                                                         SecretKeyAccess access)
                                                                                                  throws java.security.GeneralSecurityException
        Serializes a given Key into a "SerializationT" object.

        This will look up a previously registered serializer for the requested SerializationT class and the passed in key type, and then call serializeKey on the result.

        Throws:
        java.security.GeneralSecurityException
      • hasParserForParameters

        public <SerializationT extends Serialization> boolean hasParserForParameters​(SerializationT serializedParameters)
        Returns true if a parser for this serializedKey has been registered.
      • parseParameters

        public <SerializationT extends SerializationParameters parseParameters​(SerializationT serializedParameters)
                                                                          throws java.security.GeneralSecurityException
        Parses the given serialization into a Parameters object.

        This will look up a previously registered parser for the passed in SerializationT class, and the used object identifier (as indicated by serializedKey.getObjectIdentifier()), and then parse the object with this parsers.

        Throws:
        java.security.GeneralSecurityException
      • parseParametersWithLegacyFallback

        public Parameters parseParametersWithLegacyFallback​(ProtoParametersSerialization protoParametersSerialization)
                                                     throws java.security.GeneralSecurityException
        Returns a Parameters object from a protoKeySerialization, even if no parser has been registered.

        Falling back is useful because we need to have a parameters object even if no parser is registered (e.g. for when we create a Key from a key template/parameters name object).

        Throws:
        java.security.GeneralSecurityException
      • hasSerializerForParameters

        public <ParametersT extends Parameters,​SerializationT extends Serialization> boolean hasSerializerForParameters​(ParametersT parameters,
                                                                                                                              java.lang.Class<SerializationT> serializationClass)
        Returns true if a parser for this serializedKey has been registered.
      • serializeParameters

        public <ParametersT extends Parameters,​SerializationT extends Serialization> SerializationT serializeParameters​(ParametersT parameters,
                                                                                                                              java.lang.Class<SerializationT> serializationClass)
                                                                                                                       throws java.security.GeneralSecurityException
        Serializes a given Parameters object into a "SerializationT" object.

        This will look up a previously registered serializer for the requested SerializationT class and the passed in key type, and then call serializeKey on the result.

        Throws:
        java.security.GeneralSecurityException