models

package
v0.0.0-...-8aef909 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const MaxObjectContentLen = 1024 * 5000

MaxObjectContentLen contains the maximum size for the content of an object.

Variables

This section is empty.

Functions

func GroupObjectsByMetadata

func GroupObjectsByMetadata(objects []Object, k string) map[string][]Object

func GroupObjectsByPrimaryKeyHash

func GroupObjectsByPrimaryKeyHash(objects []Object) map[string][]Object

Types

type Exception

type Exception struct {
	Name string

	// Regular expresion that should match the name of the rule.
	Rule *regexp.Regexp

	// Regular expresion that should match the name of the object.
	Object *regexp.Regexp

	// Number of line where the secret is found in the contect of the object.
	Nline *int

	// Regular expresion that should match the content of the object.
	Content *regexp.Regexp
}

Represents an Exception. In order for a secret to be considered as exception all non-nill attributes should match with the secret information. That means it's considered like and AND statement.

func NewException

func NewException() *Exception

NewException creates a new exception.

func (*Exception) Run

func (x *Exception) Run(s *Secret) bool

Run executes the exception into a secret to determine if it's an exception or not.

func (*Exception) SetContent

func (x *Exception) SetContent(content string) error

SetContent sets the regular expresion that should match the content of the object.

func (*Exception) SetNline

func (x *Exception) SetNline(nLine int) error

SetNline sets the number of line where secret should be found.

func (*Exception) SetObject

func (x *Exception) SetObject(object string) error

SetObject sets the regular expresion that should match the name of the object.

func (*Exception) SetRule

func (x *Exception) SetRule(rule string) error

SetRule sets the regular expresion that should match the name of the rule.

type KeyHash

type KeyHash *[]byte

Contains a KeyHash or nil

type MetadataAttributes

type MetadataAttributes struct {
	// All objects with same value on this key has the same content. It's used
	// to optimise the inspection.
	PrimaryKey bool
}

Represents the attributes of metadata.

type MetadataData

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

Represents the metadata of an object.

type Object

type Object struct {
	Type    string
	SubType string

	Name    string
	Content []byte

	Metadata       map[string]MetadataData
	PrimaryKeyHash KeyHash
}

Represents an object.

func NewObject

func NewObject(name string, t string, st string, content []byte) *Object

NewObject creates a new object.

func (*Object) GetMetadata

func (o *Object) GetMetadata(key string) (string, error)

SetMetadata gets a metadata value from the object.

func (*Object) GetMetadataAll

func (o *Object) GetMetadataAll(attr bool) map[string]string

GetMetadataAll gets a map that contains all metadata of the object.

func (*Object) GetPrimaryKeyHash

func (o *Object) GetPrimaryKeyHash() KeyHash

GetPrimaryKeyHash returns the primary key hash of the object. This hash is calculated by using the information of all metadata marked as primary key.

func (*Object) SetMetadata

func (o *Object) SetMetadata(key string, value string, attr MetadataAttributes) error

SetMetadata sets a metadata value for the object.

type Rule

type Rule struct {
	// Contains the name of the rule.
	Name string

	// Specifies if the rule is enabled or not.
	Enabled bool

	// All lines of the content are analised separatelly.
	// For a line to be considered a secret it should match the Match regular
	// expression and not match any of the regular expressions contained on the
	// Unmacth array.
	Match   *regexp.Regexp
	Unmatch []*regexp.Regexp
}

Represents a Rule.

func NewRule

func NewRule(name string, match string) (*Rule, error)

NewRule creates a new rule.

func (*Rule) AddUnmatch

func (r *Rule) AddUnmatch(unmatch string) error

AddUnmatch adds a refular expression into the unmatch list.

func (*Rule) Disable

func (r *Rule) Disable()

Enable marks the rule as disabled.

func (*Rule) Enable

func (r *Rule) Enable()

Enable marks the rule as enabled.

func (*Rule) Run

func (r *Rule) Run(line string) bool

Run executes the rule on a line passed in and returns a boolean

type RunResult

type RunResult struct {
	Line  string
	Nline int
}

type Secret

type Secret struct {
	// Object in witch the secret is found.
	Object *Object

	// Rule that matches.
	Rule *Rule

	// Number of line in the content that contains the secret.
	Nline int

	// Content of the specific line.
	Line string

	// Specifies if this matches an exception too.
	Exception bool
}

Represents a found secret.

func NewSecret

func NewSecret(object *Object, rule *Rule, nLine int, line string) *Secret

NewSecret creates a new secret.

func (*Secret) SetException

func (s *Secret) SetException(exception bool)

SetException specifies that a found secret is an exception (of false positive).

Jump to

Keyboard shortcuts

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