-
Notifications
You must be signed in to change notification settings - Fork 133
Open
Labels
Description
Is your feature request related to a problem? Please describe.
Currently, memguard panics when encountering memory management failures, which creates several issues:
- Poor Error Handling: Panics force users to implement recovery mechanisms throughout their codebase
- Limited Control: Applications cannot make informed decisions about how to handle memory constraints
- Mobile Compatibility: Android's 64KB mlock limit makes panics common in production environments
Describe the solution you'd like
Proposed API
// New error-returning variants
func NewBuffer(size int) (*Buffer, error)
func NewEnclave(data []byte) (*Enclave, error)
// ... other functions
// Optional: Keep panic variants for backward compatibility
func MustNewBuffer(size int) *Buffer
func MustNewEnclave(data []byte) *Enclave
Error Types
Introduce specific error types for different failure scenarios:
// Specific error types
var (
ErrInsufficientMemory = errors.New("memguard: insufficient lockable memory available")
ErrMemoryLocked = errors.New("memguard: memory locking failed")
ErrMemoryProtection = errors.New("memguard: memory protection failed")
)