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
ConstructorDescriptionSalmonFileSequencer
(IRealFile sequenceFile, INonceSequenceSerializer serializer) Instantiate a nonce file sequencer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this file sequencer.void
createSequence
(String driveId, String authId) Create a sequence for the drive ID and auth ID provided.protected String
Get the contents of a sequence file.getSequence
(String driveId) Get the sequence by the drive ID.void
initializeSequence
(String driveId, String authId, byte[] startNonce, byte[] maxNonce) Initialize the sequence.byte[]
Get the next nonce.void
revokeSequence
(String driveId) Revoke the current sequence for a specific drive.protected void
saveContents
(String contents) Save the contents of the fileprotected void
saveSequenceFile
(HashMap<String, NonceSequence> sequences) Save the sequence file.void
setMaxNonce
(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:
createSequence
in 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:
initializeSequence
in 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:
setMaxNonce
in 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:
nextNonce
in 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:
revokeSequence
in 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:
getSequence
in 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:
close
in 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
-