public abstract static class KeyTypeManager.KeyFactory<KeyFormatProtoT extends com.google.protobuf.MessageLite,KeyT> extends Object
KeyFactory creates new keys from a given KeyFormat.
A KeyFactory implements all the methods which are required if a KeyTypeManager should also be able to generate keys. In particular, in this case it needs to have some KeyFormat protocol buffer which can be validated, parsed, and from which a key can be generated.
| Constructor and Description |
|---|
KeyFactory(Class<KeyFormatProtoT> clazz) |
| Modifier and Type | Method and Description |
|---|---|
abstract KeyT |
createKey(KeyFormatProtoT keyFormat)
Creates a new key from a given format.
|
KeyT |
deriveKey(KeyFormatProtoT keyFormat,
InputStream pseudoRandomness)
Derives a new key from a given format, using the given .
|
Class<KeyFormatProtoT> |
getKeyFormatClass()
Returns the class corresponding to the key format protobuffer.
|
abstract KeyFormatProtoT |
parseKeyFormat(com.google.protobuf.ByteString byteString)
Parses a serialized key proto.
|
abstract void |
validateKeyFormat(KeyFormatProtoT keyFormatProto)
Checks if the given
keyFormatProto is a valid key. |
public KeyFactory(Class<KeyFormatProtoT> clazz)
public final Class<KeyFormatProtoT> getKeyFormatClass()
public abstract void validateKeyFormat(KeyFormatProtoT keyFormatProto) throws GeneralSecurityException
keyFormatProto is a valid key.GeneralSecurityException - if the passed keyFormatProto is not valid in any
way.public abstract KeyFormatProtoT parseKeyFormat(com.google.protobuf.ByteString byteString) throws com.google.protobuf.InvalidProtocolBufferException
Implement as return KeyFormatProtoT.parseFrom(byteString);.
com.google.protobuf.InvalidProtocolBufferExceptionpublic abstract KeyT createKey(KeyFormatProtoT keyFormat) throws GeneralSecurityException
GeneralSecurityExceptionpublic KeyT deriveKey(KeyFormatProtoT keyFormat, InputStream pseudoRandomness) throws GeneralSecurityException
Implementations need to note that the given paramter may only produce a finite amount of randomness. Hence, proper implementations will first obtain all the pseudorandom bytes needed; and only after produce the key.
While validateKeyFormat is called before this method will be called,
implementations must check the version of the given , as validateKeyFormat is also called from createKey.
Not every KeyTypeManager needs to implement this; if not implemented a GeneralSecurityException will be thrown.
GeneralSecurityException