Class SalmonFileSequencer

java.lang.Object
com.mku.salmon.sequence.SalmonFileSequencer
All Implemented Interfaces:
INonceSequencer
Direct Known Subclasses:
WinFileSequencer

public class SalmonFileSequencer extends Object implements INonceSequencer
Generates nonces based on a sequencer backed by a file.
  • 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

      public IRealFile getSequenceFile()
    • createSequence

      public void createSequence(String driveId, String authId)
      Create a sequence for the drive ID and auth ID provided.
      Specified by:
      createSequence in interface INonceSequencer
      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 interface INonceSequencer
      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 sequence
      IOException - Thrown if there is an IO error.
    • setMaxNonce

      public void setMaxNonce(String driveId, String authId, byte[] maxNonce)
      Set the maximum nonce.
      Specified by:
      setMaxNonce in interface INonceSequencer
      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

      public byte[] nextNonce(String driveId)
      Get the next nonce.
      Specified by:
      nextNonce in interface INonceSequencer
      Parameters:
      driveId - The drive ID.
      Returns:
      The next nonce
      Throws:
      SequenceException - Thrown if there is an error with the nonce sequence
      SalmonRangeExceededException - Thrown if the nonce exceeds its range
    • getContents

      protected String getContents()
      Get the contents of a sequence file.
      Returns:
      The contents
      Throws:
      SequenceException - Thrown if there is an error with the nonce sequence
    • revokeSequence

      public void revokeSequence(String driveId)
      Revoke the current sequence for a specific drive.
      Specified by:
      revokeSequence in interface INonceSequencer
      Parameters:
      driveId - The drive ID.
      Throws:
      SequenceException - Thrown if there is an error with the nonce sequence
    • getSequence

      public NonceSequence getSequence(String driveId)
      Get the sequence by the drive ID.
      Specified by:
      getSequence in interface INonceSequencer
      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 interface INonceSequencer
    • saveSequenceFile

      protected void saveSequenceFile(HashMap<String,NonceSequence> sequences)
      Save the sequence file.
      Parameters:
      sequences - The sequences.
      Throws:
      SequenceException - Thrown if there is an error with the nonce sequence
    • saveContents

      protected void saveContents(String contents)
      Save the contents of the file
      Parameters:
      contents - The contents