emix

package module
v0.0.0-...-73f5d69 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: MIT Imports: 12 Imported by: 0

README

emix

Build Status codecov License

TODO
  • Add long usage
  • Readme
  • More tests
  • Benchmarks

Documentation

Index

Constants

View Source
const (
	// 4K
	XTSSectorSize = 1024 * 4

	// SectorNumberStart as sector number for AES-XTS
	SectorNumberStart = 1024
)

Variables

View Source
var (

	/// errors
	ErrNameTooShort           = errors.New("name too short")
	ErrNameTooLong            = errors.New("name too long")
	ErrInvalidEmixHeader      = errors.New("invalid emix header")
	ErrInvalidEmixFileContent = errors.New("invalid emix file content")
	ErrInvalidEncodedFileInfo = errors.New("invalid file info")
)

Functions

func AESGCMDecrypt

func AESGCMDecrypt(cipherText []byte, key [16]byte) ([]byte, error)

func AESGCMEncrypt

func AESGCMEncrypt(plainText []byte, key [16]byte) ([]byte, error)

func DecryptContent

func DecryptContent(cipher *xts.Cipher, reader io.Reader, writer io.Writer, size int64) error

EncryptContent decrypt file content using AES-XTS, read cipher data from reader and write plain data to writer

func EncryptContent

func EncryptContent(cipher *xts.Cipher, reader io.Reader, writer io.Writer) error

EncryptContent encrypt file content using AES-XTS, read data from reader and write cipher data to writer

func GeneratePasswordFromFile

func GeneratePasswordFromFile(filePath string) ([]byte, error)

GeneratePasswordFromFile use a credential file to generate password return 16-byte password

func GenerateRandomPassword

func GenerateRandomPassword(length int) ([]byte, error)

GenerateRandomPassword generate random length-byte password

func HKDF

func HKDF(secret []byte, salt []byte, info []byte, length int) []byte

func IsEmixFile

func IsEmixFile(r io.Reader) (bool, error)

IsEmixFile check if the file is emix file

func IsEmixFileByData

func IsEmixFileByData(data []byte) (bool, error)

IsEmixFileByData check if the data is emix file

func IsEmixFileByPath

func IsEmixFileByPath(path string) (bool, error)

IsEmixFileByPath check if the path is emix file

func NewAESGCM

func NewAESGCM(key [16]byte) (cipher.AEAD, error)

use aes-256-gcm

func NewAESXTS

func NewAESXTS(key [16]byte) (*xts.Cipher, error)

NewAESXTS returns an xts.Cipher

func ZipHeader

func ZipHeader() []byte

ZipHeader return zip header

func ZipHeaderLength

func ZipHeaderLength() int

ZipHeaderLength return zip header length

Types

type EmixHeader

type EmixHeader struct {
	EncryptInfo bool
	EncryptData bool
	// EmbedPassword must only use auto generated 16-byte password
	EmbedPassword bool
	Password      [16]byte
	FileInfo      FileInfo
}

func (*EmixHeader) EncodedLength

func (e *EmixHeader) EncodedLength() int

EncodedLength return EmixHeader encoded length

func (*EmixHeader) MarshalBinary

func (e *EmixHeader) MarshalBinary() ([]byte, error)

func (*EmixHeader) UnmarshalBinary

func (e *EmixHeader) UnmarshalBinary(data []byte) error

func (*EmixHeader) UnmarshalBinaryFromReader

func (e *EmixHeader) UnmarshalBinaryFromReader(r io.Reader) error

type FileInfo

type FileInfo struct {
	Name            string
	Size            uint64
	Mode            uint32
	CreateTime      uint64
	ModifyTime      uint64
	FileContentHash [32]byte
}

func (*FileInfo) EncodedLength

func (f *FileInfo) EncodedLength() int

EncodedLength measure encoded length

func (*FileInfo) MarshalBinary

func (f *FileInfo) MarshalBinary() ([]byte, error)

MarshalBinary serialize FileInfo format: namelength + name + size + mode + create time + modify time namelength use 2 bytes

func (*FileInfo) UnmarshalBinary

func (f *FileInfo) UnmarshalBinary(data []byte) error

UnmarshalBinary deserialize FileInfo

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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