Class FileSystemTufStore

java.lang.Object
dev.sigstore.tuf.FileSystemTufStore
All Implemented Interfaces:
MetaReader, MetaStore, TargetReader, TargetStore

public class FileSystemTufStore extends Object implements MetaStore, TargetStore
Uses a local file system directory to store the trusted TUF metadata.
  • Method Details

    • newFileSystemStore

      public static FileSystemTufStore newFileSystemStore(Path repoBaseDir) throws IOException
      Throws:
      IOException
    • newFileSystemStore

      public static FileSystemTufStore newFileSystemStore(Path repoBaseDir, Path targetsCache)
    • getIdentifier

      public String getIdentifier()
      Description copied from interface: MetaStore
      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 MetaStore
      Specified by:
      getIdentifier in interface TargetStore
    • writeTarget

      public void writeTarget(String targetName, byte[] targetContents) throws IOException
      Description copied from interface: TargetStore
      Writes a TUF target to the local target store. Target names may include path elements and the storage engine should be consistent when handling writing and reading these.
      Specified by:
      writeTarget in interface TargetStore
      Parameters:
      targetName - the name of the target file to write (e.g. ctfe.pub)
      targetContents - the content of the target file as bytes
      Throws:
      IOException - if an error occurs
    • readTarget

      public byte[] readTarget(String targetName) throws IOException
      Description copied from interface: TargetReader
      Reads a TUF target file from the local TUF store. Target names may include path elements and the storage engine should be consistent when handling writing and reading these.
      Specified by:
      readTarget in interface TargetReader
      Parameters:
      targetName - the name of the target file to read (e.g. ctfe.pub)
      Returns:
      the content of the file as bytes
      Throws:
      IOException - if an error occurs
    • getTargetInputSteam

      public InputStream getTargetInputSteam(String targetName) throws IOException
      Description copied from interface: TargetReader
      Returns an input stream to a TUF target file in the local TUF store. Target names may include path elements and the storage engine should be consistent when handling writing and reading these.
      Specified by:
      getTargetInputSteam in interface TargetReader
      Parameters:
      targetName - the name of the target file to read (e.g. ctfe.pub)
      Returns:
      an input steam to the target file in the local store, the consumer must close the input stream
      Throws:
      IOException - if an error occurs
    • hasTarget

      public boolean hasTarget(String targetName) throws IOException
      Description copied from interface: TargetReader
      Checks if the local TUF store actually contains a target file with name.
      Specified by:
      hasTarget in interface TargetReader
      Parameters:
      targetName - the name of the target file to read (e.g. ctfe.pub)
      Returns:
      true if the target exists locally
      Throws:
      IOException - if an error occurs
    • writeMeta

      public void writeMeta(String roleName, SignedTufMeta<?> meta) throws IOException
      Description copied from interface: MetaStore
      Generic method to store one of the SignedTufMeta resources in the local tuf store.
      Specified by:
      writeMeta in interface MetaStore
      Parameters:
      roleName - the name of the role
      meta - the metadata to store
      Throws:
      IOException - if writing the resource causes an IO error
    • readMeta

      public <T extends SignedTufMeta<?>> Optional<T> readMeta(String roleName, Class<T> tClass) throws IOException
      Description copied from interface: MetaReader
      Return a named metadata item if there is any.
      Specified by:
      readMeta in interface MetaReader
      Parameters:
      roleName - the name of the role to load (root, timestamp, snapshot, targets, or a delegated target role)
      tClass - the class type
      Returns:
      an instance of the signed metadata for the role if it was found
      Throws:
      IOException - if an error occurs reading from the backing store
    • clearMeta

      public void clearMeta(String role) throws IOException
      Description copied from interface: MetaStore
      Generic method to remove meta, useful when keys rotated in root. Deletion is not optional, implementers must ensure meta is removed from the storage medium.
      Specified by:
      clearMeta in interface MetaStore
      Throws:
      IOException - implementations that read/write IO to clear the data may throw IOException
      See Also:
    • getRepoBaseDir

      public Path getRepoBaseDir()
    • getTargetsDir

      public Path getTargetsDir()