privacy

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

pkg/adapter/privacy/audit_logger.go

pkg/adapter/privacy/detector.go

Package privacy provides PII detection, masking, and tokenization. Detects email, SSN, phone, credit card, and passport patterns. Supports partial masking, full masking, hashing, and AES-256 tokenization.

pkg/adapter/privacy/masker.go

pkg/adapter/privacy/patterns.go

pkg/adapter/privacy/tokenizer.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateCreditCard

func ValidateCreditCard(cardNumber string) bool

ValidateCreditCard uses Luhn algorithm to validate credit card numbers

func ValidateIPv4

func ValidateIPv4(ip string) bool

ValidateIPv4 validates IPv4 address format (already done by regex, but explicit validation available)

func ValidateSSN

func ValidateSSN(ssn string) bool

ValidateSSN validates SSN format and rules

Types

type AuditLogger

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

AuditLogger logs all PII operations for compliance and auditing

func NewAuditLogger

func NewAuditLogger() *AuditLogger

NewAuditLogger creates a new audit logger

func (*AuditLogger) ClearLogs

func (a *AuditLogger) ClearLogs()

ClearLogs clears all logged events

func (*AuditLogger) ExportLogs

func (a *AuditLogger) ExportLogs() string

ExportLogs exports logs as JSON string for storage/transmission

func (*AuditLogger) FormatLog

func (a *AuditLogger) FormatLog(log map[string]any) string

FormatLog formats a log entry for human-readable output

func (*AuditLogger) GetEventsByAction

func (a *AuditLogger) GetEventsByAction(action string) []map[string]any

GetEventsByAction returns all events of a specific action type

func (*AuditLogger) GetEventsByUserID

func (a *AuditLogger) GetEventsByUserID(userID string) []map[string]any

GetEventsByUserID returns all events for a specific user

func (*AuditLogger) GetEventsSince

func (a *AuditLogger) GetEventsSince(since time.Time) []map[string]any

GetEventsSince returns all events since the given time

func (*AuditLogger) GetLogs

func (a *AuditLogger) GetLogs() []map[string]any

GetLogs returns all logged events

func (*AuditLogger) GetStatistics

func (a *AuditLogger) GetStatistics() map[string]any

GetStatistics returns statistics about logged events

func (*AuditLogger) IsCompliant

func (a *AuditLogger) IsCompliant() bool

IsCompliant checks if all operations are compliant (no unhandled errors)

func (*AuditLogger) LogAccess

func (a *AuditLogger) LogAccess(ctx context.Context, userID string, action string, resource string) error

LogAccess logs data access events

func (*AuditLogger) LogDetection

func (a *AuditLogger) LogDetection(ctx context.Context, userID string, detections []port.PIIDetectionResult) error

LogDetection logs a PII detection event

func (*AuditLogger) LogDetokenization

func (a *AuditLogger) LogDetokenization(ctx context.Context, userID string, resource string, piiCount int) error

LogDetokenization logs a PII detokenization event

func (*AuditLogger) LogError

func (a *AuditLogger) LogError(ctx context.Context, userID string, errorType string, errorMessage string) error

LogError logs an error event

func (*AuditLogger) LogMasking

func (a *AuditLogger) LogMasking(ctx context.Context, userID string, resource string, piiCount int) error

LogMasking logs a PII masking event

func (*AuditLogger) LogTokenization

func (a *AuditLogger) LogTokenization(ctx context.Context, userID string, resource string, piiCount int) error

LogTokenization logs a PII tokenization event

func (*AuditLogger) ValidateCompliance

func (a *AuditLogger) ValidateCompliance() (bool, string)

ValidateCompliance checks if masking was applied to all detected PII

type PIIDetector

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

PIIDetector implements the PrivacyPort interface for PII detection

func NewPIIDetector

func NewPIIDetector() *PIIDetector

NewPIIDetector creates a new PII detector instance

func (*PIIDetector) DetectPII

func (d *PIIDetector) DetectPII(ctx context.Context, data any) ([]port.PIIDetectionResult, error)

DetectPII detects all types of PII in the given data Supports string, map[string]any, and arrays Returns all detected PII instances with their locations and types

func (*PIIDetector) DetokenizePII

func (d *PIIDetector) DetokenizePII(ctx context.Context, data any, tokens map[string]string) (any, error)

DetokenizePII recovers original PII from tokens Implemented in tokenizer adapter (Day 42)

func (*PIIDetector) MaskPII

func (d *PIIDetector) MaskPII(ctx context.Context, data any) (any, error)

MaskPII masks all detected PII in the data For strings, replaces PII values with masked versions For structured data, recursively masks all PII

func (*PIIDetector) TokenizePII

func (d *PIIDetector) TokenizePII(ctx context.Context, data any) (any, error)

TokenizePII replaces PII with encrypted tokens Implemented in tokenizer adapter (Day 42)

type PIIMasker

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

PIIMasker implements masking functionality for PII data

func NewPIIMasker

func NewPIIMasker(detector *PIIDetector) *PIIMasker

NewPIIMasker creates a new PII masker

func (*PIIMasker) MaskPII

func (m *PIIMasker) MaskPII(ctx context.Context, data any) (any, error)

MaskPII implements the PrivacyPort.MaskPII method

type PIITokenizer

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

PIITokenizer implements reversible tokenization for PII using AES-256 encryption

func NewPIITokenizer

func NewPIITokenizer() *PIITokenizer

NewPIITokenizer creates a new PII tokenizer with a derived encryption key

func (*PIITokenizer) DetokenizePII

func (t *PIITokenizer) DetokenizePII(ctx context.Context, data any, tokens map[string]string) (any, error)

DetokenizePII implements the PrivacyPort.DetokenizePII method Note: The PrivacyPort interface requires map[string]string, but our implementation returns (any, map[string]string, error) We need to add a wrapper method

func (*PIITokenizer) DetokenizeValue

func (t *PIITokenizer) DetokenizeValue(ctx context.Context, token string) (string, error)

DetokenizeValue detokenizes a single token back to its original value

func (*PIITokenizer) TokenizePII

func (t *PIITokenizer) TokenizePII(ctx context.Context, data any) (any, error)

TokenizePII implements the PrivacyPort.TokenizePII method Returns tokenized data. The tokens map should be extracted from the returned value if it's a map

func (*PIITokenizer) TokenizeValue

func (t *PIITokenizer) TokenizeValue(ctx context.Context, value string) (string, error)

TokenizeValue tokenizes a single PII value and returns its token

type Patterns

type Patterns struct {
	EmailPattern      *regexp.Regexp
	PhonePattern      *regexp.Regexp
	CreditCardPattern *regexp.Regexp
	SSNPattern        *regexp.Regexp
	PassportPattern   *regexp.Regexp
	IPv4Pattern       *regexp.Regexp
	IPv6Pattern       *regexp.Regexp
}

Patterns holds all compiled regex patterns for PII detection

func NewPatterns

func NewPatterns() *Patterns

NewPatterns creates and compiles all PII detection patterns

Jump to

Keyboard shortcuts

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