Documentation
¶
Overview ¶
Package PII offers tools to deal with Personal Identified Information in struct-field level
Index ¶
Constants ¶
const VERSION version = "v0.3.0"
VERSION is the current version of the PII Go Module.
Variables ¶
var ( ErrEncryptDecryptFailure = newErr("failed to encrypt/decrypt") ErrForgetSubjectFailure = newErr("failed to forget subject") ErrRecoverSubjectFailure = newErr("failed to recover subject") ErrClearCacheFailure = newErr("failed to clear cache") ErrCannotRecoverSubject = newErr("cannot recover subject") ErrSubjectForgotten = newErr("subject is forgotten") )
Errors returned by Protector service
var ( ErrUnsupportedType = errors.New("unsupported type must be a struct pointer") ErrUnsupportedFieldType = errors.New("unsupported field type must be exported string") ErrInvalidTagConfiguration = errors.New("invalid tag configuration") )
Errors related to struct PII tag configuration
var (
ErrInvalidIPAddress = errors.New("invalid IP address")
)
Functions ¶
func MustTruncateIPv4Addr ¶ added in v0.3.0
MustTruncateIPv4Addr ,similar to TruncateIPv4Addr function, truncates the last "n" bytes from the IP v4 address, but it panics in case of error instead.
func TruncateIPv4Addr ¶ added in v0.3.0
TruncateIPv4Addr takes an IP v4 address and a number "n" of least bytes to remove and replace with zeros.
It returns the truncated IP address or returns an error if the given IPv4 address is invalid.
It helps to partially pseudonymize the IP address while preserving a prefix.
Types ¶
type Error ¶
type Error struct { // Err is the base err Err error // contains filtered or unexported fields }
Error is a developer-friendly error wrapper that speaks privacy language. Its base error contains more technical details, and it can be enriched with meta-data, e.g., namespace and subject.
func (Error) Is ¶
Is compares only messages of Errors to decide whether they are equal. Otherwise, the wrapped error will decide.
func (Error) Message ¶
Message returns a short and primary message of the error.
In contrast to Error() method, It doesn't include base error or meta-data in the return.
type Factory ¶
type Factory interface { // Instance creates a new Protector instance for the given namespace or returns the existing one. Instance(namespace string) (Protector, FactoryClearFunc) // Monitor starts a long-running process in a separate Goroutine. // It checks Protectors' activities and removes inactive ones, // and clears their caches based on their cache TTL config. Monitor(ctx context.Context) }
Factory manages and maintains a registry of Protector services.
It monitors each Protector service to track its activity and regularly clears encryption materials caches.
func NewFactory ¶
func NewFactory(newProt FactoryNewFunc, opts ...func(*FactoryConfig)) Factory
NewFactory returns a thread-safe factory service instance. It panics if builderFunc is nil. Options params allow overwriting the default configuration.
type FactoryClearFunc ¶
type FactoryClearFunc func()
FactoryClearFunc presents the function returned by Factory.Instance method. It tells the associated Protector instance to immediately clear the cache of encryption materials.
type FactoryConfig ¶
type FactoryConfig struct { // IDLE is the duration used to define whether a Protector service is inactive. IDLE time.Duration // MonitorPeriod is the frequency of the regular checks made by the monitoring process. MonitorPeriod time.Duration }
FactoryConfig presents the configuration of Factory service
type FactoryNewFunc ¶ added in v0.2.2
FactoryNewFunc is used by the Factory service to create Perotector instance per namespace.
type Protector ¶
type Protector interface { // Encrypt encrypts Personal data fields of the given structs pointers. // It does its best to ensure atomicity in case of multiple structs pointers. // It ensures idempotency and only encrypts fields once. Encrypt(ctx context.Context, structPts ...interface{}) error // Decrypt decrypts Personal data fields of the given structs pointers. // It does its best to ensure in case of multiple structs pointers. // It ensures idempotency and only decrypts fields once. // // It replaces the field value with a replacement message, defined in the tag, // if the subject is forgotten. Otherwise, the field will be kept empty. Decrypt(ctx context.Context, structPts ...interface{}) error // Forget removes the associated encryption materials of the given subject, // and crypto-erases its Personal data. Forget(ctx context.Context, subID string) error // Recover allows to recover encryption materials of the given subject. // It will fail if the grace period was exceeded, and encryption materials were hard deleted. Recover(ctx context.Context, subID string) error // Clear clears encryption materials' cache based on cache-related configuration. Clear(ctx context.Context, force bool) error }
Protector presents the service's interface that encrypts, decrypts, and crypto-erases subjects' Personal data.
func NewProtector ¶
func NewProtector(namespace string, engine core.KeyEngine, opts ...func(*ProtectorConfig)) Protector
NewProtector returns a Protector service instance. It requires a Key engine and accepts options to overwrite the default configuration.
It panics if the given engine is nil. It uses a default namespace if the given namespace is empty.
By default, Cache and Graceful mode options are enabled and 'AES 256 GCM' encrypter is used.
type ProtectorConfig ¶
type ProtectorConfig struct { // Engine presents an implementation of core.KeyEngine. // It manages encryption materials' life-cycle. Engine core.KeyEngine // Encrypter presents an implementation of core.Encrypter. // It allows using a specific encryption algorithm. Encrypter core.Encrypter // CacheEnabled used to enable/disable cache. CacheEnabled bool // CacheTTL defines the cache's time to live duration. CacheTTL time.Duration // GracefulMode allows first to disable the encryption materials during a graceful period. // Therefore recovery may succeed. Otherwise, encryption materials are immediately deleted. GracefulMode bool }
ProtectorConfig presents the configuration of Protector service
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package aes contains implementation and helper functions related specifically to "Advanced Encryption Standard" algorithm and cryptography in general.
|
Package aes contains implementation and helper functions related specifically to "Advanced Encryption Standard" algorithm and cryptography in general. |
Package core contains the encryption logic model and service interfaces.
|
Package core contains the encryption logic model and service interfaces. |
stack
module
|
|