Class FileSystemTufStore

  • All Implemented Interfaces:
    MutableTufStore, TufStore

    public class FileSystemTufStore
    extends java.lang.Object
    implements MutableTufStore
    Uses a local file system directory to store the trusted TUF metadata.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearMetaDueToKeyRotation()
      This clears out the snapshot and timestamp metadata from the store, as required when snapshot or timestamp verification keys have changed as a result of a root update.
      java.lang.String getIdentifier()
      A generic string for identifying the local store in debug messages.
      byte[] getTargetFile​(java.lang.String targetName)
      Reads a TUF target file from the local TUF store
      java.util.Optional<Snapshot> loadSnapshot()
      Return the local trusted snapshot metadata if there is any.
      java.util.Optional<Targets> loadTargets()
      Return the local trusted targets metadata if there is any.
      java.util.Optional<Timestamp> loadTimestamp()
      Return local trusted timestamp metadata if there is any.
      java.util.Optional<Root> loadTrustedRoot()
      Local store must have a root that has been blessed safe.
      static MutableTufStore newFileSystemStore​(java.nio.file.Path repoBaseDir)  
      void storeMeta​(SignedTufMeta<?> timestamp)
      Generic method to store one of the SignedTufMeta resources in the local tuf store.
      void storeTargetFile​(java.lang.String targetName, byte[] targetContents)
      Writes a TUF target to the local target store.
      void storeTrustedRoot​(Root root)
      Once you have ascertained that your root is trustworthy use this method to persist it to your local store.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newFileSystemStore

        public static MutableTufStore newFileSystemStore​(java.nio.file.Path repoBaseDir)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getIdentifier

        public java.lang.String getIdentifier()
        Description copied from interface: TufStore
        A generic string for identifying the local store in debug messages. A file system based implementation might return the path being used for storage, while an in-memory store may just return something like 'in-memory'.
        Specified by:
        getIdentifier in interface TufStore
      • loadTrustedRoot

        public java.util.Optional<Root> loadTrustedRoot()
                                                 throws java.io.IOException
        Description copied from interface: TufStore
        Local store must have a root that has been blessed safe.
        Specified by:
        loadTrustedRoot in interface TufStore
        Throws:
        java.io.IOException
      • loadTimestamp

        public java.util.Optional<Timestamp> loadTimestamp()
                                                    throws java.io.IOException
        Description copied from interface: TufStore
        Return local trusted timestamp metadata if there is any.
        Specified by:
        loadTimestamp in interface TufStore
        Throws:
        java.io.IOException
      • loadSnapshot

        public java.util.Optional<Snapshot> loadSnapshot()
                                                  throws java.io.IOException
        Description copied from interface: TufStore
        Return the local trusted snapshot metadata if there is any.
        Specified by:
        loadSnapshot in interface TufStore
        Throws:
        java.io.IOException
      • loadTargets

        public java.util.Optional<Targets> loadTargets()
                                                throws java.io.IOException
        Description copied from interface: TufStore
        Return the local trusted targets metadata if there is any.
        Specified by:
        loadTargets in interface TufStore
        Throws:
        java.io.IOException
      • storeTargetFile

        public void storeTargetFile​(java.lang.String targetName,
                                    byte[] targetContents)
                             throws java.io.IOException
        Description copied from interface: MutableTufStore
        Writes a TUF target to the local target store.
        Specified by:
        storeTargetFile in interface MutableTufStore
        Parameters:
        targetName - the name of the target file to write (e.g. ctfe.pub)
        targetContents - the content of the target file as bytes
        Throws:
        java.io.IOException - if an error occurs
      • getTargetFile

        public byte[] getTargetFile​(java.lang.String targetName)
                             throws java.io.IOException
        Description copied from interface: TufStore
        Reads a TUF target file from the local TUF store
        Specified by:
        getTargetFile in interface TufStore
        Parameters:
        targetName - the name of the target file to read (e.g. ctfe.pub)
        Returns:
        the content of the file as bytes
        Throws:
        java.io.IOException - if an error occurs
      • storeMeta

        public void storeMeta​(SignedTufMeta<?> timestamp)
                       throws java.io.IOException
        Description copied from interface: MutableTufStore
        Generic method to store one of the SignedTufMeta resources in the local tuf store.
        Specified by:
        storeMeta in interface MutableTufStore
        Parameters:
        timestamp - the metadata to store
        Throws:
        java.io.IOException - if writing the resource causes an IO error
      • storeTrustedRoot

        public void storeTrustedRoot​(Root root)
                              throws java.io.IOException
        Description copied from interface: MutableTufStore
        Once you have ascertained that your root is trustworthy use this method to persist it to your local store. This will usually only be called with a root loaded statically from a bundled trusted root, or after the successful verification of an updated root from a mirror.
        Specified by:
        storeTrustedRoot in interface MutableTufStore
        Parameters:
        root - a root that has been proven trustworthy by the client
        Throws:
        java.io.IOException - since some implementations may persist the root to disk or over the network we throw IOException in case of IO error.
        See Also:
        5.3.8
      • clearMetaDueToKeyRotation

        public void clearMetaDueToKeyRotation()
                                       throws java.io.IOException
        Description copied from interface: MutableTufStore
        This clears out the snapshot and timestamp metadata from the store, as required when snapshot or timestamp verification keys have changed as a result of a root update.
        Specified by:
        clearMetaDueToKeyRotation in interface MutableTufStore
        Throws:
        java.io.IOException - implementations that read/write IO to clear the data may throw IOException
        See Also:
        5.3.11