detector

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: MIT Imports: 11 Imported by: 0

README

detector模块 实现说明

DetectorAPI接口

  1. GetRuleInfo() string
  • GetRuleInfo returns rule as string
  1. GetRuleID() int32
  • GetRuleID returns RuleID
  1. GetMaskRuleName() string
  • GetMaskRuleName returns MaskRuleName
  1. IsValue() bool
  • IsValue checks whether RuleType is VALUE
  1. IsKV() bool
  • IsValue checks whether RuleType is KV
  1. DetectBytes(inputBytes []byte) ([]*dlpheader.DetectResult, error)
  • DetectBytes detects sensitive info for bytes
  1. DetectMap(inputMap map[string]string) ([]*dlpheader.DetectResult, error)
  • DetectMap detects sensitive info for map
  1. Close()
  • Close release detector object

Documentation

Overview

Package detector implements detector functions

Index

Constants

View Source
const (
	RULE_TYPE_VALUE        = 0
	RULE_TYPE_KV           = 1
	RESULT_TYPE_VALUE      = "VALUE"
	RESULT_TYPE_KV         = "KV"
	BLACKLIST_ALGO_MASKED  = "MASKED"
	VERIFY_ALGO_IDCARD     = "IDCARD"
	VERIFY_ALGO_ABAROUTING = "ABAROUTING"
	VERIFY_ALGO_CREDITCARD = "CREDITCARD"
	VERIFY_ALGO_BITCOIN    = "BITCOIN"
	VERIFY_ALGO_DOMAIN     = "DOMAIN"
	MASKED_CHARLIST        = "*#"
	DEF_RESULT_SIZE        = 4
	DEF_CONTEXT_RANGE      = 32
	DEF_IDCARD_LEN         = 18
)

RuleType is different with ResultType, bacause for input string contains KV object, KV rule will generate Value Detect Type

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextVerifyFunc

type ContextVerifyFunc func(*Detector, []byte, *dlpheader.DetectResult) bool

ContextVerifyFunc defines verify by context function

type Detector

type Detector struct {
	RuleType int // VALUE if there is no KReg and KDict
	// Detect section in conf
	KReg  []*regexp.Regexp    // regex list for Key
	KDict map[string]struct{} // Dict for Key
	VReg  []*regexp.Regexp    // Regex list for Value
	VDict []string            // Dict for Value
	// Filter section in conf
	BAlgo []string         // algorithm for blacklist, supports MASKED
	BDict []string         // Dict for blacklist
	BReg  []*regexp.Regexp // Regex list for blacklist
	// Verify section in conf
	CDict []string         // Dict for Context Verification
	CReg  []*regexp.Regexp // Regex List for Context Verification
	VAlgo []string         // algorithm for Verifycation, such as IDCARD
	// contains filtered or unexported fields
}

func (*Detector) Close

func (I *Detector) Close()

Close release detector object

func (*Detector) DetectBytes

func (I *Detector) DetectBytes(inputBytes []byte) ([]*dlpheader.DetectResult, error)

DetectBytes detects sensitive info for bytes, is called from Detect()

func (*Detector) DetectList

func (I *Detector) DetectList(kvList []*KVItem) ([]*dlpheader.DetectResult, error)

func (*Detector) DetectMap

func (I *Detector) DetectMap(inputMap map[string]string) ([]*dlpheader.DetectResult, error)

DetectMap detects for Map, is called from DetectMap() and DetectJSON()

func (*Detector) GetMaskRuleName

func (I *Detector) GetMaskRuleName() string

GetMaskRuleName returns MaskRuleName used in Detect Rule

func (*Detector) GetRuleID

func (I *Detector) GetRuleID() int32

GetRuleID returns RuleID

func (*Detector) GetRuleInfo

func (I *Detector) GetRuleInfo() string

GetRuleInfo returns rule as string

func (*Detector) IsKV

func (I *Detector) IsKV() bool

IsKV checks whether Detect RuleType is KV

func (*Detector) IsValue

func (I *Detector) IsValue() bool

IsValue checks whether Detect RuleType is VALUE

func (*Detector) UseRegex

func (I *Detector) UseRegex() bool

type DetectorAPI

type DetectorAPI interface {
	// GetRuleInfo returns rule as string
	GetRuleInfo() string
	// GetRuleID returns RuleID
	GetRuleID() int32
	// GetMaskRuleName returns MaskRuleName
	GetMaskRuleName() string
	// IsValue checks whether RuleType is VALUE
	IsValue() bool
	// IsValue checks whether RuleType is KV
	IsKV() bool
	// UseRegex checks whether Rule use Regex
	UseRegex() bool
	// DetectBytes detects sensitive info for bytes
	DetectBytes(inputBytes []byte) ([]*dlpheader.DetectResult, error)
	// DetectMap detects sensitive info for map
	DetectMap(inputMap map[string]string) ([]*dlpheader.DetectResult, error)

	DetectList(kvList []*KVItem) ([]*dlpheader.DetectResult, error)
	// Close release detector object
	Close()
}

func NewDetector

func NewDetector(ruleItem conf.RuleItem) (DetectorAPI, error)

NewDetector creates detector object from rule

type KVItem

type KVItem struct {
	Key   string
	Value string
	Start int
	End   int
}

Jump to

Keyboard shortcuts

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