zenc

package module
v0.0.0-...-33c2f39 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 10 Imported by: 0

README

ZENC

Build Status

ZENC is a command-line tool, a library and also a file format for data encryption.

Installation

go get -u github.com/goasm/zenc/cmd/zenc

Usage

Via command
zenc [OPTION...] FILE
Option Shorthand Description
--help -h print help message
--encrypt -e encrypt file
--decrypt -d decrypt file
--passwd -p password to be applied
--output -o file to write output
Programmatically
go get -u github.com/goasm/zenc
var err error
// encryption
err = zenc.EncryptFile(reader, writer, password)
// or decryption
err = zenc.DecryptFile(reader, writer, password)

License

The MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongFileType = errors.New("wrong file type")
	ErrWrongChecksum = errors.New("wrong checksum")
	ErrLimitExceeded = errors.New("limit exceeded")
)

zenc errors

View Source
var (
	Magic   = [4]byte{0x5A, 0x45, 0x4E, 0x43} // ZENC
	Version = [4]byte{0x00, 0x01, 0x00, 0x00} // 0.1.0.0
)

File header constants

Functions

func DecryptFile

func DecryptFile(src io.Reader, dst io.Writer, pass string) (err error)

DecryptFile decrypts file using the given password

func EncryptFile

func EncryptFile(src io.Reader, dst io.Writer, pass string) (err error)

EncryptFile encrypts file using the given password

Types

type ChecksumStage

type ChecksumStage struct {
	MiddleStage
	Sum uint32
}

ChecksumStage maintains a checksum of the data being processed

func NewChecksumStage

func NewChecksumStage() *ChecksumStage

NewChecksumStage creates a Stage for calculating checksum

func (*ChecksumStage) Read

func (cs *ChecksumStage) Read(buf []byte) (int, error)

func (*ChecksumStage) Write

func (cs *ChecksumStage) Write(data []byte) (int, error)

type ChunkInfo

type ChunkInfo struct {
	Size int32
}

ChunkInfo holds the information of a chunk

func (*ChunkInfo) ReadFrom

func (ci *ChunkInfo) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads the data of ChunkInfo from r

func (*ChunkInfo) WriteTo

func (ci *ChunkInfo) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the data of ChunkInfo to w

type ChunkStage

type ChunkStage struct {
	MiddleStage
	// contains filtered or unexported fields
}

ChunkStage encodes contiguous bytes into chunks

func NewChunkStage

func NewChunkStage() *ChunkStage

NewChunkStage creates a Stage for encoding data

func (*ChunkStage) Close

func (cs *ChunkStage) Close() (err error)

Close flushes the buffer and ends the chunk stream

func (*ChunkStage) Flush

func (cs *ChunkStage) Flush() (err error)

Flush writes the buffered data to the underlying writer

func (*ChunkStage) Read

func (cs *ChunkStage) Read(buf []byte) (n int, err error)

func (*ChunkStage) Write

func (cs *ChunkStage) Write(data []byte) (n int, err error)

type CryptoStage

type CryptoStage struct {
	MiddleStage
	// contains filtered or unexported fields
}

CryptoStage encrypts/decrypts input data using the cipher key-stream

func NewCryptoStage

func NewCryptoStage(key string, iv []byte) *CryptoStage

NewCryptoStage creates a Stage for both encryption and decryption

func (*CryptoStage) Read

func (cs *CryptoStage) Read(buf []byte) (int, error)

func (*CryptoStage) Write

func (cs *CryptoStage) Write(data []byte) (int, error)

type DechunkStage

type DechunkStage struct {
	MiddleStage
	// contains filtered or unexported fields
}

DechunkStage decodes chunks to contiguous bytes

func NewDechunkStage

func NewDechunkStage() *DechunkStage

NewDechunkStage creates a Stage for decoding chunks

func (*DechunkStage) Read

func (ds *DechunkStage) Read(buf []byte) (n int, err error)

func (*DechunkStage) Write

func (ds *DechunkStage) Write(data []byte) (n int, err error)

type DestStage

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

DestStage outputs data to a destination Writer

func NewDestStage

func NewDestStage(d io.Writer) *DestStage

NewDestStage creates a DestStage from a Writer

func (*DestStage) Next

func (ds *DestStage) Next() Stage

Next of DestStage is always nil

func (*DestStage) Read

func (ds *DestStage) Read(buf []byte) (int, error)

func (*DestStage) SetNext

func (ds *DestStage) SetNext(n Stage)

SetNext on DestStage will panic

func (*DestStage) Write

func (ds *DestStage) Write(data []byte) (int, error)

type FileFooter

type FileFooter struct {
	Checksum uint32
}

FileFooter is used to store extra file information

func NewFileFooter

func NewFileFooter() *FileFooter

NewFileFooter creates a new FileFooter

func (*FileFooter) ReadFrom

func (f *FileFooter) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads the data of FileFooter from r

func (*FileFooter) WriteTo

func (f *FileFooter) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the data of FileFooter to w

type FileHeader

type FileHeader struct {
	Magic   [4]byte
	Version [4]byte
	IV      [16]byte
}

FileHeader is used to identify encrypted file

func NewFileHeader

func NewFileHeader() *FileHeader

NewFileHeader creates a new FileHeader

func (*FileHeader) ReadFrom

func (h *FileHeader) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads the data of FileHeader from r

func (*FileHeader) WriteTo

func (h *FileHeader) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the data of FileHeader to w

type MiddleStage

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

MiddleStage processes data and writes them to next stage

func (*MiddleStage) Next

func (ms *MiddleStage) Next() Stage

Next gets the next Stage

func (*MiddleStage) SetNext

func (ms *MiddleStage) SetNext(n Stage)

SetNext sets the next Stage

type Pipeline

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

Pipeline represents a data flow consisting of one or more stages

func NewPipeline

func NewPipeline() *Pipeline

NewPipeline creates a Pipeline

func (*Pipeline) AddStage

func (p *Pipeline) AddStage(stage Stage)

AddStage adds the stage at the end of the Pipeline

func (*Pipeline) Close

func (p *Pipeline) Close() error

Close closes every stage of the Pipeline

func (*Pipeline) Read

func (p *Pipeline) Read(buf []byte) (int, error)

func (*Pipeline) Write

func (p *Pipeline) Write(data []byte) (int, error)

type SourceStage

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

SourceStage gets input data from a source Reader

func NewSourceStage

func NewSourceStage(s io.Reader) *SourceStage

NewSourceStage creates a SourceStage from a Reader

func (*SourceStage) Next

func (ss *SourceStage) Next() Stage

Next of SourceStage is always nil

func (*SourceStage) Read

func (ss *SourceStage) Read(buf []byte) (int, error)

func (*SourceStage) SetNext

func (ss *SourceStage) SetNext(n Stage)

SetNext on SourceStage will panic

func (*SourceStage) Write

func (ss *SourceStage) Write(data []byte) (int, error)

type Stage

type Stage interface {
	io.ReadWriter
	SetNext(Stage)
	Next() Stage
}

Stage represents a data processing step of Pipeline

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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