credman

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package credman provides encrypted credential management for HTTP cookies. It handles secure storage, retrieval, and persistence of cookies using AES-GCM encryption backed by the operating system's keyring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CookieManager

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

CookieManager handles encrypted storage and retrieval of HTTP cookies. It persists cookies to a file using GOB encoding, with values encrypted using AES-GCM before storage. The manager maintains an in-memory cache of cookies for efficient access.

func NewCookieManager

func NewCookieManager(filePath string, key []byte) (*CookieManager, error)

NewCookieManager creates a new CookieManager that stores cookies at the specified file path, encrypted with the provided key. The key must be 32 bytes for AES-256 encryption. If the file exists, existing cookies are loaded into memory. Returns an error if the file cannot be opened or if existing cookie data is corrupted.

func (*CookieManager) Close

func (cm *CookieManager) Close() error

Close persists all cookies to disk and closes the underlying file handle. This method should be called when the CookieManager is no longer needed to ensure all data is saved and resources are released.

func (*CookieManager) DeleteCookie

func (cm *CookieManager) DeleteCookie(name string) error

DeleteCookie removes a cookie by name from storage. The change is immediately persisted to disk. Returns an error if the cookie does not exist or if persistence fails.

func (*CookieManager) GetCookie

func (cm *CookieManager) GetCookie(name string) (*types.Cookie, error)

GetCookie retrieves a cookie by name and returns it with its value decrypted. Returns a copy of the cookie to prevent modification of the internal state. Returns an error if the cookie does not exist or if decryption fails.

func (*CookieManager) SetCookie

func (cm *CookieManager) SetCookie(cookie types.Cookie) error

SetCookie stores a new cookie with its value encrypted. The cookie is identified by its Name field. If a cookie with the same name already exists, it is overwritten. The encrypted cookie is immediately persisted to disk. Returns an error if encryption or persistence fails.

func (*CookieManager) UpdateCookie

func (cm *CookieManager) UpdateCookie(cookie *types.Cookie) error

UpdateCookie updates an existing cookie with new values. The cookie's value is encrypted before storage. Unlike SetCookie, this method accepts a pointer and creates an internal copy. Returns an error if the cookie pointer is nil, encryption fails, or persistence fails.

Directories

Path Synopsis
Package encryption provides AES-GCM encryption and decryption functions for securing sensitive credential data.
Package encryption provides AES-GCM encryption and decryption functions for securing sensitive credential data.
Package keyring provides secure key storage using the operating system's native keyring service with automatic fallback to file-based storage.
Package keyring provides secure key storage using the operating system's native keyring service with automatic fallback to file-based storage.
Package types defines common data structures used throughout the credman package for credential management.
Package types defines common data structures used throughout the credman package for credential management.

Jump to

Keyboard shortcuts

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