common

package
v0.0.0-...-982e07a Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAccessTimeGranularity = 24 * time.Hour

DefaultAccessTimeGranularity is the default difference in time required for the access time to be updated.

Variables

View Source
var (
	ErrUnknownTokenType     = errors.New("unknown token type")
	ErrUnsupportedTokenType = errors.New("token type not supported")
)

Validation errors

View Source
var (
	TokenType_name = map[int32]string{
		0: "Unknown",
		1: "Int32",
		2: "Int64",
		3: "String",
		4: "Bytes",
		5: "Email",
		6: "Int32Str",
		7: "Int64Str",
	}
	TokenType_value = map[string]int32{
		"Unknown":  0,
		"Int32":    1,
		"Int64":    2,
		"String":   3,
		"Bytes":    4,
		"Email":    5,
		"Int32Str": 6,
		"Int64Str": 7,
	}
)

Enum value maps for TokenType.

View Source
var ErrTokenDisabled = errors.New("disabled token accessed")

ErrTokenDisabled is returned when a token was found, but is explicitly disabled

View Source
var ErrTokenExists = errors.New("token already exists")

ErrTokenExists is returned by TokenStorage.Save when a token with given ID and context already exists in the storage

View Source
var ErrTokenNotFound = errors.New("token not found in storage")

ErrTokenNotFound error used when token wasn't found in storage

View Source
var File_metadata_proto protoreflect.FileDescriptor
View Source
var File_tokenTypes_proto protoreflect.FileDescriptor

Functions

func AggregateTokenContextToBytes

func AggregateTokenContextToBytes(context TokenContext) []byte

AggregateTokenContextToBytes used as function to return one byte array as value which is digest for context

func EmbedMetadata

func EmbedMetadata(data []byte, metadata TokenMetadata) []byte

EmbedMetadata composes data with additional metadata into a single byte slice.

func EncodeTokenValue

func EncodeTokenValue(value *TokenValue) ([]byte, error)

EncodeTokenValue serializes token value into bytes.

func ValidateTokenType

func ValidateTokenType(value TokenType) error

ValidateTokenType return true if value is supported TokenType

Types

type Anonymizer

type Anonymizer interface {
	// generic
	Anonymize(data interface{}, context TokenContext, dataType TokenType) (interface{}, error)

	// type specific
	AnonymizeInt32(value int32, context TokenContext) (int32, error)
	AnonymizeInt64(value int64, context TokenContext) (int64, error)
	AnonymizeBytes(value []byte, context TokenContext) ([]byte, error)
	AnonymizeStr(value string, context TokenContext) (string, error)
	AnonymizeEmail(email Email, context TokenContext) (Email, error)
}

Anonymizer interface provide all supported methods to anonymize data

type Email

type Email string

Email type used to separate string type from Email for tokens

type Encryptor

type Encryptor interface {
	Encrypt(data, context TokenContext) ([]byte, error)
	Decrypt(data, context TokenContext) ([]byte, error)
}

Encryptor interface used as abstraction for token encryption

type MetadataContainer

type MetadataContainer struct {
	Data     []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
	Created  int64  `protobuf:"varint,2,opt,name=created,proto3" json:"created,omitempty"`
	Accessed int64  `protobuf:"varint,3,opt,name=accessed,proto3" json:"accessed,omitempty"`
	Disabled bool   `protobuf:"varint,4,opt,name=disabled,proto3" json:"disabled,omitempty"`
	// contains filtered or unexported fields
}

MetadataContainer is Protobuf container for TokenMetadata.

func (*MetadataContainer) Descriptor deprecated

func (*MetadataContainer) Descriptor() ([]byte, []int)

Deprecated: Use MetadataContainer.ProtoReflect.Descriptor instead.

func (*MetadataContainer) GetAccessed

func (x *MetadataContainer) GetAccessed() int64

func (*MetadataContainer) GetCreated

func (x *MetadataContainer) GetCreated() int64

func (*MetadataContainer) GetData

func (x *MetadataContainer) GetData() []byte

func (*MetadataContainer) GetDisabled

func (x *MetadataContainer) GetDisabled() bool

func (*MetadataContainer) ProtoMessage

func (*MetadataContainer) ProtoMessage()

func (*MetadataContainer) ProtoReflect

func (x *MetadataContainer) ProtoReflect() protoreflect.Message

func (*MetadataContainer) Reset

func (x *MetadataContainer) Reset()

func (*MetadataContainer) String

func (x *MetadataContainer) String() string

type Pseudoanonymizer

type Pseudoanonymizer interface {
	Anonymizer
	AnonymizeConsistently(data interface{}, context TokenContext, dataType TokenType) (interface{}, error)
	Deanonymize(data interface{}, context TokenContext, dataType TokenType) (interface{}, error)
}

Pseudoanonymizer extends Anonymizer interface with methods to anonymize consistently and deanonymize value

type TokenAction

type TokenAction int

TokenAction is an action to perform during VisitMetadata.

const (
	TokenContinue TokenAction = iota
	TokenEnable
	TokenDisable
	TokenRemove
)

Available TokenAction values.

type TokenContext

type TokenContext struct {
	ClientID          []byte
	AdditionalContext []byte
}

TokenContext used as metadata for each token

type TokenMetadata

type TokenMetadata struct {
	Created  time.Time
	Accessed time.Time
	Disabled bool
}

TokenMetadata is additional bookeeping information kept by TokenStorage along with the token value.

func ExtractMetadata

func ExtractMetadata(data []byte) ([]byte, TokenMetadata, error)

ExtractMetadata extracts data and metadata back from a composite byte slice.

func NewTokenMetadata

func NewTokenMetadata() TokenMetadata

NewTokenMetadata creates metadata for a newly created token entry,

func (*TokenMetadata) AccessedBefore

func (t *TokenMetadata) AccessedBefore(instant time.Time, granularity time.Duration) bool

AccessedBefore checks that the token has been accessed before the specified time instance with given granularity.

func (TokenMetadata) Equal

func (t TokenMetadata) Equal(other TokenMetadata) bool

Equal returns true if this metadata is equal to the other one.

type TokenSetting

type TokenSetting interface {
	IsTokenized() bool
	IsConsistentTokenization() bool
	GetTokenType() TokenType
}

TokenSetting describes how a column should be tokenized.

type TokenStorage

type TokenStorage interface {
	Save(id []byte, context TokenContext, data []byte) error
	Get(id []byte, context TokenContext) ([]byte, error)
	Stat(id []byte, context TokenContext) (TokenMetadata, error)

	// Iterate over token metadata in the storage.
	// In addition to metadata, length of data for an entry is provided for reference. (Can't access data without context information).
	// The iteration order is unspecified. If the storage in concurrently modified during iteration,
	// modifications may or may not be visible during the iteration, and entries may be visited multiple times.
	// Return the desired action to do with the token, usually TokenContinue to simply continue iteration.
	// Return a non-nil error to stop iteration and return this error.
	VisitMetadata(cb func(dataLength int, metadata TokenMetadata) (TokenAction, error)) error

	SetAccessTimeGranularity(granularity time.Duration) error
}

TokenStorage interface abstracts storage implementation

type TokenType

type TokenType int32

TokenType defines tokenization type.

const (
	TokenType_Unknown  TokenType = 0
	TokenType_Int32    TokenType = 1
	TokenType_Int64    TokenType = 2
	TokenType_String   TokenType = 3
	TokenType_Bytes    TokenType = 4
	TokenType_Email    TokenType = 5
	TokenType_Int32Str TokenType = 6
	TokenType_Int64Str TokenType = 7
)

func NormalizeTokenType

func NormalizeTokenType(value TokenType, defaultType TokenType) TokenType

NormalizeTokenType checks the token type and replaces it with the default value if the type is not supported or invalid.

func (TokenType) Descriptor

func (TokenType) Descriptor() protoreflect.EnumDescriptor

func (TokenType) Enum

func (x TokenType) Enum() *TokenType

func (TokenType) EnumDescriptor deprecated

func (TokenType) EnumDescriptor() ([]byte, []int)

Deprecated: Use TokenType.Descriptor instead.

func (TokenType) Number

func (x TokenType) Number() protoreflect.EnumNumber

func (TokenType) String

func (x TokenType) String() string

func (TokenType) ToConfigString

func (x TokenType) ToConfigString() (val string, err error)

ToConfigString converts value to string used in encryptor_config

func (TokenType) Type

type TokenValue

type TokenValue struct {
	Value []byte    `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
	Type  TokenType `protobuf:"varint,2,opt,name=type,proto3,enum=common.TokenType" json:"type,omitempty"`
	// contains filtered or unexported fields
}

TokenValue keeps serialized token value.

func TokenValueFromData

func TokenValueFromData(data []byte) (*TokenValue, error)

TokenValueFromData deserializes token value from bytes.

func (*TokenValue) Descriptor deprecated

func (*TokenValue) Descriptor() ([]byte, []int)

Deprecated: Use TokenValue.ProtoReflect.Descriptor instead.

func (*TokenValue) GetType

func (x *TokenValue) GetType() TokenType

func (*TokenValue) GetValue

func (x *TokenValue) GetValue() []byte

func (*TokenValue) ProtoMessage

func (*TokenValue) ProtoMessage()

func (*TokenValue) ProtoReflect

func (x *TokenValue) ProtoReflect() protoreflect.Message

func (*TokenValue) Reset

func (x *TokenValue) Reset()

func (*TokenValue) String

func (x *TokenValue) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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