enstore

package module
v0.0.0-...-63ce023 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 10 Imported by: 0

README

enstore

EnStore is a library for placing files into encrypted blocks, which can be written to an arbitrary destination, and being able to list and retrieve said files without having to pull down an entire encrypted volume (only blocks which contain the file being retrieved will be read and decrypted). Adding new files will also only pull and push the necessary blocks. The only place files are ever decrypted is in-memory (unless the decrypted file is written out to a file by the user).

Usage

EnStore is a library, but does expose a command-line interface to use as a simple tool. See usage as a library, or as a CLI.

Library Usage

TODO

CLI

The CLI can be compiled from source using

$ cd main
$ go build -o enstore

go must be installed to build. Pre-built binaries may be forthcoming.

TODO

Documentation

Index

Constants

View Source
const (
	// ConfigfilePath is the default config file path
	ConfigfilePath string = "config.json"
	// DefaultBlockSize is the default block size (5 MB)
	DefaultBlockSize int = 5242880 // 5 MB
	// DefaultChunkSize is the default chunk size (512 bytes)
	DefaultChunkSize int = 512 // 512 bytes
	// DefaultIndexfile is the default index file path
	DefaultIndexfile string = "index"
)

Variables

This section is empty.

Functions

func WriteBlock

func WriteBlock(block *Block, crypter Crypter, writer BlockWriter) error

Types

type AESCrypter

type AESCrypter struct {
	// contains filtered or unexported fields
}

AESCrypter is a struct that can encrypt and decypt bytes using AES and a common key

func NewAESCrypter

func NewAESCrypter(key []byte) (*AESCrypter, error)

NewAESCrypter creates a new AESCrypter with the provided key

func (*AESCrypter) Decrypt

func (a *AESCrypter) Decrypt(bytes []byte) ([]byte, error)

Decrypt decrypts the bytes passed to it

func (*AESCrypter) Decrypter

func (a *AESCrypter) Decrypter(source io.Reader) (io.Reader, error)

Decrypter returns an io.Reader which, when read, returns the decrypted bytes of the `source` io.Reader

func (*AESCrypter) Encrypt

func (a *AESCrypter) Encrypt(bytes []byte) ([]byte, error)

Encrypt encrypts the bytes passed to it

func (*AESCrypter) Encrypter

func (a *AESCrypter) Encrypter(source io.Reader) (io.Reader, error)

Encrypter returns an io.Reader which, when read, returns the encrypted bytes of the `source` io.Reader

type AESDecryptionReader

type AESDecryptionReader struct {
	Source io.Reader
	Stream cipher.Stream
}

AESDecryptionReader is an io.Reader which provides the decrypted version of a source io.Reader when read The source io.Reader should be positioned at the start of the ciphertext when initialized

func (*AESDecryptionReader) Read

func (d *AESDecryptionReader) Read(p []byte) (int, error)

Read returns the decrypted bytes of the source io.Reader

type AESEncryptionReader

type AESEncryptionReader struct {
	Source io.Reader
	Stream cipher.Stream
	IV     []byte
	// contains filtered or unexported fields
}

AESEncyptionReader is an io.Reader which provides the encrypted version of a source io.Reader when read

func (*AESEncryptionReader) Read

func (e *AESEncryptionReader) Read(p []byte) (int, error)

Read returns the encrypted bytes of the source io.Reader, starting with the IV

type Block

type Block struct {
	Filename string
	Bytes    []byte
}

func NewBlock

func NewBlock(blockName string, blockSize int64) (*Block, error)

func ReadBlock

func ReadBlock(blockName string, crypter Crypter, reader BlockReader) (*Block, error)

func (*Block) Update

func (b *Block) Update(startByte int, newBytes []byte) (int, error)

type BlockLocation

type BlockLocation struct {
	Block     string
	StartByte int64
	EndByte   int64
}

BlockLocation describes a section of bytes on a block

type BlockMetadata

type BlockMetadata struct {
	Filename string
	Size     int64
	Next     string
}

type BlockReader

type BlockReader interface {
	Read(string) ([]byte, error)
}

type BlockWriter

type BlockWriter interface {
	Write(string, []byte) error
}

type Config

type Config struct {
	BlockSize int
	ChunkSize int
	IndexFile string
}

Config is the basic configuration for enstore

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns a pointer to a new Config with default values

type Crypter

type Crypter interface {
	Encrypt([]byte) ([]byte, error)
	Decrypt([]byte) ([]byte, error)
}

Crypter allows for encryption and decryption of bytes

type File

type File interface {
	io.Reader
	Name() string
	Size() int64
}

File contains a file's name and contents

type FileMetadata

type FileMetadata struct {
	Filename string
	Size     int64
	Blocks   []BlockLocation
}

FileMetadata contains file metadata in the Index

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index keeps track of all files and blocks and where all files exist across each block. It has methods for adding, removing, getting, and listing files on the blocks.

func LoadIndex

func LoadIndex(reader IndexReader, crypter Crypter, cfg *Config) (*Index, error)

LoadIndex will attempt to load an existing index file and decrypt its store. If no file exists, it will create a new one with the supplied key.

func NewIndex

func NewIndex(cfg *Config) *Index

NewIndex returns an empty index

func (*Index) AddFile

func (ix *Index) AddFile(file File, reader BlockReader, writer BlockWriter, crypter Crypter) error

AddFile will add a file to the index and write it to any blocks with space, creating new blocks as necessary

func (*Index) DeleteFile

func (ix *Index) DeleteFile(filename string, reader BlockReader, writer BlockWriter, crypter Crypter, zeroOut bool) error

func (*Index) GetFile

func (ix *Index) GetFile(filename string, destination io.Writer, reader BlockReader, crypter Crypter) error

GetFile will read all blocks a file in the index is stored on, and assemble and return the unencrypted file

func (*Index) ListFiles

func (ix *Index) ListFiles() []FileMetadata

ListFiles returns a slice of all the files in the index. This slice is a copy of the internal store, so manipulations can be performed on it

func (*Index) Save

func (ix *Index) Save(writer IndexWriter, crypter Crypter) error

Save will save the index encrypted with the supplied key, using the IndexWriter to write the file

type IndexReader

type IndexReader interface {
	BlockReader
	Exists(filename string) bool
}

IndexReader exposes BlockReader method(s), and a method to check the existence of a file

type IndexWriter

type IndexWriter interface {
	BlockWriter
}

IndexWriter mirrors BlockWriter

type LocalFileReadWriter

type LocalFileReadWriter struct {
	BasePath string
}

func (*LocalFileReadWriter) Exists

func (lfrw *LocalFileReadWriter) Exists(filename string) bool

func (*LocalFileReadWriter) Read

func (lfrw *LocalFileReadWriter) Read(filename string) ([]byte, error)

func (*LocalFileReadWriter) Write

func (lfrw *LocalFileReadWriter) Write(filename string, bytes []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL