tea

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tea implements TEA encryption and decryption with streaming support. It provides TEA encryption and decryption operations using the standard TEA algorithm with support for variable rounds and 128-bit keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStreamDecrypter

func NewStreamDecrypter(r io.Reader, c *cipher.TeaCipher) io.Reader

NewStreamDecrypter creates a new streaming TEA decrypter that reads encrypted data from the provided io.Reader. The decrypter uses the specified cipher interface and validates the key length for proper TEA decryption.

func NewStreamEncrypter

func NewStreamEncrypter(w io.Writer, c *cipher.TeaCipher) io.WriteCloser

NewStreamEncrypter creates a new streaming TEA encrypter that writes encrypted data to the provided io.Writer. The encrypter uses the specified cipher interface and validates the key length for proper TEA encryption.

Types

type DecryptError

type DecryptError struct {
	Err error // The underlying error that caused the failure
}

DecryptError represents an error when TEA decryption fails. This error occurs when the underlying TEA decryption operation fails. The error includes the underlying error for detailed debugging.

func (DecryptError) Error

func (e DecryptError) Error() string

Error returns a formatted error message describing the decryption failure. The message includes the underlying error for debugging.

type EncryptError

type EncryptError struct {
	Err error // The underlying error that caused the failure
}

EncryptError represents an error when TEA encryption fails. This error occurs when the underlying TEA encryption operation fails. The error includes the underlying error for detailed debugging.

func (EncryptError) Error

func (e EncryptError) Error() string

Error returns a formatted error message describing the encryption failure. The message includes the underlying error for debugging.

type InvalidDataSizeError

type InvalidDataSizeError struct {
	Size int // The actual data size that caused the error
}

InvalidDataSizeError represents an error when the data size is invalid for TEA operations. TEA requires data to be a multiple of 8 bytes (64 bits).

func (InvalidDataSizeError) Error

func (e InvalidDataSizeError) Error() string

Error returns a formatted error message describing the invalid data size. The message includes the actual size and the required size for debugging.

type KeySizeError

type KeySizeError int

KeySizeError represents an error when the TEA key size is invalid. TEA keys must be exactly 16 bytes (128 bits) long. This error occurs when the provided key does not meet this size requirement.

func (KeySizeError) Error

func (k KeySizeError) Error() string

Error returns a formatted error message describing the invalid key size. The message includes the actual key size and the required size for debugging.

type ReadError

type ReadError struct {
	Err error // The underlying error that caused the failure
}

ReadError represents an error when reading encrypted data fails. This error occurs when reading encrypted data from the underlying reader fails. The error includes the underlying error for detailed debugging.

func (ReadError) Error

func (e ReadError) Error() string

Error returns a formatted error message describing the read failure. The message includes the underlying error for debugging.

type StdDecrypter

type StdDecrypter struct {
	Error error // Error field for storing decryption errors
	// contains filtered or unexported fields
}

StdDecrypter represents a TEA decrypter for standard decryption operations. It implements TEA decryption using the standard TEA algorithm with support for different key sizes and various cipher modes.

func NewStdDecrypter

func NewStdDecrypter(c *cipher.TeaCipher) *StdDecrypter

NewStdDecrypter creates a new TEA decrypter with the specified cipher and key. Validates the key length and initializes the decrypter for TEA decryption operations. The key must be exactly 16 bytes (128 bits).

func (*StdDecrypter) Decrypt

func (d *StdDecrypter) Decrypt(src []byte) (dst []byte, err error)

Decrypt decrypts the given byte slice using TEA decryption. Creates a TEA cipher block and uses the configured cipher interface to perform the decryption operation with proper error handling. Returns empty data when input is empty.

type StdEncrypter

type StdEncrypter struct {
	Error error // Error field for storing encryption errors
	// contains filtered or unexported fields
}

StdEncrypter represents a TEA encrypter for standard encryption operations. It implements TEA encryption using the standard TEA algorithm with support for different key sizes and various cipher modes.

func NewStdEncrypter

func NewStdEncrypter(c *cipher.TeaCipher) *StdEncrypter

NewStdEncrypter creates a new TEA encrypter with the specified cipher and key. Validates the key length and initializes the encrypter for TEA encryption operations. The key must be exactly 16 bytes (128 bits).

func (*StdEncrypter) Encrypt

func (e *StdEncrypter) Encrypt(src []byte) (dst []byte, err error)

Encrypt encrypts the given byte slice using TEA encryption. Creates a TEA cipher block and uses the configured cipher interface to perform the encryption operation with proper error handling. Returns empty data when input is empty.

type StreamDecrypter

type StreamDecrypter struct {
	Error error // Error field for storing decryption errors
	// contains filtered or unexported fields
}

StreamDecrypter represents a streaming TEA decrypter that implements io.Reader. It provides efficient decryption for large data streams by processing data in chunks and reading decrypted output from the underlying reader with proper state management.

func (*StreamDecrypter) Read

func (d *StreamDecrypter) Read(p []byte) (n int, err error)

Read implements the io.Reader interface for streaming TEA decryption. On the first call, reads all encrypted data from the underlying reader and decrypts it. Subsequent calls return chunks of the decrypted data to maintain streaming interface.

type StreamEncrypter

type StreamEncrypter struct {
	Error error // Error field for storing encryption errors
	// contains filtered or unexported fields
}

StreamEncrypter represents a streaming TEA encrypter that implements io.WriteCloser. It provides efficient encryption for large data streams by processing data in chunks and writing encrypted output to the underlying writer.

func (*StreamEncrypter) Close

func (e *StreamEncrypter) Close() error

Close implements the io.Closer interface for the streaming TEA encrypter. Closes the underlying writer if it implements io.Closer. Note: All data is processed in Write method for compatibility with cipher interface.

func (*StreamEncrypter) Write

func (e *StreamEncrypter) Write(p []byte) (n int, err error)

Write implements the io.Writer interface for streaming TEA encryption. Provides improved performance through cipher block reuse while maintaining compatibility. Accumulates data and processes it using the cipher interface for consistency.

type UnsupportedBlockModeError added in v1.1.7

type UnsupportedBlockModeError struct {
	Mode string // The unsupported mode name
}

UnsupportedBlockModeError represents an error when an unsupported block mode is used.

func (UnsupportedBlockModeError) Error added in v1.1.7

Error returns a formatted error message describing the unsupported mode. The message includes the mode name and explains why it's not supported.

type WriteError

type WriteError struct {
	Err error // The underlying error that caused the failure
}

WriteError represents an error when writing encrypted data fails. This error occurs when writing encrypted data to the underlying writer fails. The error includes the underlying error for detailed debugging.

func (WriteError) Error

func (e WriteError) Error() string

Error returns a formatted error message describing the write failure. The message includes the underlying error for debugging.

Source Files

  • errors.go
  • tea.go

Jump to

Keyboard shortcuts

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