Package com.mku.salmon.sequence
Class SalmonFileSequencer
java.lang.Object
com.mku.salmon.sequence.SalmonFileSequencer
- All Implemented Interfaces:
INonceSequencer
- Direct Known Subclasses:
WinFileSequencer
Generates nonces based on a sequencer backed by a file.
-
Constructor Summary
ConstructorsConstructorDescriptionSalmonFileSequencer(IRealFile sequenceFile, INonceSequenceSerializer serializer) Instantiate a nonce file sequencer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this file sequencer.voidcreateSequence(String driveId, String authId) Create a sequence for the drive ID and auth ID provided.protected StringGet the contents of a sequence file.getSequence(String driveId) Get the sequence by the drive ID.voidinitializeSequence(String driveId, String authId, byte[] startNonce, byte[] maxNonce) Initialize the sequence.byte[]Get the next nonce.voidrevokeSequence(String driveId) Revoke the current sequence for a specific drive.protected voidsaveContents(String contents) Save the contents of the fileprotected voidsaveSequenceFile(HashMap<String, NonceSequence> sequences) Save the sequence file.voidsetMaxNonce(String driveId, String authId, byte[] maxNonce) Set the maximum nonce.
-
Constructor Details
-
SalmonFileSequencer
public SalmonFileSequencer(IRealFile sequenceFile, INonceSequenceSerializer serializer) throws IOException Instantiate a nonce file sequencer.- Parameters:
sequenceFile- The sequence file.serializer- The serializer to be used.- Throws:
IOException- Thrown if there is an IO error.SequenceException- Thrown if there is an error with the nonce sequence
-
-
Method Details
-
getSequenceFile
-
createSequence
Create a sequence for the drive ID and auth ID provided.- Specified by:
createSequencein interfaceINonceSequencer- Parameters:
driveId- The drive ID.authId- The authorization ID of the drive.- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
initializeSequence
public void initializeSequence(String driveId, String authId, byte[] startNonce, byte[] maxNonce) throws IOException Initialize the sequence.- Specified by:
initializeSequencein interfaceINonceSequencer- Parameters:
driveId- The drive ID.authId- The auth ID of the device for the drive.startNonce- The starting nonce.maxNonce- The maximum nonce.- Throws:
SequenceException- Thrown if there is an error with the nonce sequenceIOException- Thrown if there is an IO error.
-
setMaxNonce
Set the maximum nonce.- Specified by:
setMaxNoncein interfaceINonceSequencer- Parameters:
driveId- The drive ID.authId- The auth ID of the device for the drive.maxNonce- The maximum nonce.- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
nextNonce
Get the next nonce.- Specified by:
nextNoncein interfaceINonceSequencer- Parameters:
driveId- The drive ID.- Returns:
- The next nonce
- Throws:
SequenceException- Thrown if there is an error with the nonce sequenceSalmonRangeExceededException- Thrown if the nonce exceeds its range
-
getContents
Get the contents of a sequence file.- Returns:
- The contents
- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
revokeSequence
Revoke the current sequence for a specific drive.- Specified by:
revokeSequencein interfaceINonceSequencer- Parameters:
driveId- The drive ID.- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
getSequence
Get the sequence by the drive ID.- Specified by:
getSequencein interfaceINonceSequencer- Parameters:
driveId- The drive ID.- Returns:
- The sequence
- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
close
public void close()Close this file sequencer.- Specified by:
closein interfaceINonceSequencer
-
saveSequenceFile
Save the sequence file.- Parameters:
sequences- The sequences.- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
saveContents
Save the contents of the file- Parameters:
contents- The contents
-