fernet-java8
fernet-java8 copied to clipboard
Object to encapsulate token creation parameters
Consider creating an object for generating Fernet tokens that encapsulates the entropy source ( Random ) and time source ( Clock ). This would function similar to the way Validator works for validation and decryption.
Narrative
As a software engineer I would like to control the entropy source and time source for generated tokens So that I achieve consistency between components in the system.
I'm considering making Generator type-aware so it can abstract POJO serialisation.
Draft #172 includes a proposal for a builder and a factory as well as examples. There is no reason they couldn't both be used.
Factory Usage:
Token token = factory.generateToken( pojo ); // type-aware
Factory Creation (simple):
TokenFactory factory = new TokenFactory( convertPojo, () -> key );
Factory Creation (complex):
TokenFactory factory = new TokenFactory( clock, entropySource, convertPojo, getPrimaryKey )
Builder Usage:
Token token = builder.build( id ); // only supports strings and byte arrays
Builder Creation (simple):
TokenBuilder builder = new TokenBuilder().withKey( key );
Builder Creation (complex):
TokenBuilder builder = new TokenBuilder().withClock( clock ).withEntropySource( entropySource ).withKeySupplier( getPrimaryKey );