Documentation
¶
Overview ¶
Package core provides shared cryptographic and data handling functions that work in both CLI and WASM environments.
Index ¶
- Constants
- Variables
- func Combine(shares [][]byte) ([]byte, error)
- func Decrypt(dst io.Writer, src io.Reader, passphrase string) error
- func DecryptBytes(encryptedData []byte, passphrase string) ([]byte, error)
- func Encrypt(dst io.Writer, src io.Reader, passphrase string) error
- func HashBytes(b []byte) string
- func HashString(s string) string
- func SanitizeFilename(name string) string
- func Split(secret []byte, n, k int) ([][]byte, error)
- func ValidateShamirParams(n, k int) error
- func VerifyHash(got, expected string) bool
- type ExtractedFile
- type Share
Constants ¶
const ( // MaxFileSize is the maximum size of a single file during extraction (100 MB). MaxFileSize = 100 * 1024 * 1024 // MaxTotalSize is the maximum total size of all extracted files (1 GB). MaxTotalSize = 1024 * 1024 * 1024 )
const ( )
Variables ¶
var ErrEmptyPassphrase = errors.New("passphrase cannot be empty")
ErrEmptyPassphrase is returned when an empty passphrase is provided.
Functions ¶
func Combine ¶
Combine reconstructs the secret from k or more shares. Returns an error if fewer than 2 shares are provided. Note: If corrupted or wrong shares are provided, this may return garbage data without error. Use verification hashes to detect this.
func DecryptBytes ¶
DecryptBytes is a convenience function that decrypts data and returns bytes.
func Encrypt ¶
Encrypt encrypts data using age with a passphrase (scrypt mode). The passphrase is used to derive an encryption key using scrypt.
func HashString ¶
HashString returns the SHA-256 hash of a string, prefixed with "sha256:".
func SanitizeFilename ¶
SanitizeFilename removes characters that are problematic in filenames.
func Split ¶
Split divides a secret into n shares, requiring k to reconstruct. Parameters:
- secret: the data to split (e.g., a passphrase)
- n: total number of shares to create (2-255)
- k: minimum shares needed to reconstruct (2-n)
func ValidateShamirParams ¶
ValidateShamirParams validates the parameters for Shamir's Secret Sharing.
func VerifyHash ¶
VerifyHash checks if the given hash matches the expected value. Uses constant-time comparison to prevent timing attacks.
Types ¶
type ExtractedFile ¶
ExtractedFile represents a file extracted from a tar.gz archive.
func ExtractTarGz ¶
func ExtractTarGz(tarGzData []byte) ([]ExtractedFile, error)
ExtractTarGz extracts files from tar.gz data in memory. This is used by both CLI and WASM for in-memory extraction. For file-based extraction, use the manifest package.
func ExtractTarGzReader ¶
func ExtractTarGzReader(r io.Reader) ([]ExtractedFile, error)
ExtractTarGzReader extracts files from a tar.gz reader.
type Share ¶
type Share struct {
}
Share represents a single Shamir share with metadata.
func ParseShare ¶
ParseShare parses a share from its encoded format. The content can be a full README.txt file - it will find the share block.