types

package
v0.0.0-...-08dd15f Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const CacheFolder = "cache" + string(os.PathSeparator)

CacheFolder keeps a single reference to password list directory

View Source
const DefaultBitsetFilename = "defaultFilter.json"

DefaultBitsetFilename determines what file the pre-compiled filter exists or gets rebuilt

Variables

This section is empty.

Functions

func DownloadLists

func DownloadLists() (map[int]string, error)

DownloadLists encapsulates code for downloading common password list(s) and provides a returned list of the sizes and paths to downloaded files

func LoadFilters

func LoadFilters() (filters map[Rarity]BloomFilter, err error)

LoadFilters loads the BloomFilters from the Default BitsetFile location

func RebuildFilters

func RebuildFilters() (map[Rarity]BloomFilter, error)

RebuildFilters looks at the default filter paths and rebuilds the Bloomfilters

Types

type BFilter

type BFilter interface {
	Add(item []byte) error          // Adds the item into the Set
	Test(item []byte) (bool, error) // Check if items is maybe in the Set
}

BFilter enforces what a Bloom Filter is (as function prototypes)

type BitSet

type BitSet struct {
	Set []bool `json:"bitset"`
}

BitSet holds a slice of ZeroOneBools for custom Marshall/Unmarshall

func (*BitSet) MarshalJSON

func (bs *BitSet) MarshalJSON() ([]byte, error)

MarshalJSON marshals the boolean types to string 0 or 1

func (*BitSet) UnmarshalJSON

func (bs *BitSet) UnmarshalJSON(data []byte) error

UnmarshalJSON unpacks the string 1 or 0 to a set of sythetic boolean type

type BitSetMap

type BitSetMap struct {
	// map of the bitsets indexed by # of elements (pws) in the filter
	List map[Rarity]BitSet `json:"list"`
}

BitSetMap holds lists of the built filters for json storage/loading

func (*BitSetMap) LoadFromFile

func (bl *BitSetMap) LoadFromFile(pathToFile string) (list map[Rarity]BloomFilter, err error)

LoadFromFile reads in the BitSetMap stored in JSON by BitSetMap.WriteToFile()

func (*BitSetMap) LoadFromRebuild

func (bl *BitSetMap) LoadFromRebuild(filters map[Rarity]BloomFilter) error

LoadFromRebuild takes in the map from LoadFromFile or DownloadLists and puts the filters into the BitSetMap

func (*BitSetMap) MarshalJSON

func (bl *BitSetMap) MarshalJSON() ([]byte, error)

MarshalJSON overrides the interface{} marshalling behavior or BitsetMap

func (*BitSetMap) UnmarshalJSON

func (bl *BitSetMap) UnmarshalJSON(data []byte) error

UnmarshalJSON defines custom interaction with BitSet.UnmarshalJSON

func (*BitSetMap) WriteToFile

func (bl *BitSetMap) WriteToFile(pathToFile string) error

WriteToFile puts the BitSetMap in a persistent filestor in JSON format

type BloomFilter

type BloomFilter struct {
	Bitset []bool // The bloom-filter bitset

	N uint // Number of elements in the filter
	// contains filtered or unexported fields
}

BloomFilter probabilistic bloom filter struct

func NewBloom

func NewBloom(n int) *BloomFilter

NewBloom returns a new BloomFilter struct with n bits and default hash funcs

func (*BloomFilter) Add

func (b *BloomFilter) Add(item []byte) error

Add the item into the bloom filter set by hashing in over the hash functions

func (*BloomFilter) GetBitset

func (b *BloomFilter) GetBitset() []bool

GetBitset for returing the inner slice of booleans is needed for testing the bloom filters

func (*BloomFilter) Test

func (b *BloomFilter) Test(item []byte) (exists bool, failure error)

Test if the item hash in the bloom filter is set by iterating over the hash functions

type HomogeneityError

type HomogeneityError struct {
	Cardinality       int
	LowestProbability float64
}

HomogeneityError creates a switchable type of error for low entropy

func (*HomogeneityError) Error

func (h *HomogeneityError) Error() string

type Rarity

type Rarity int
const (
	Ten             Rarity = 10
	Hundred         Rarity = 100
	Thousand        Rarity = 1_000
	TenThousand     Rarity = 10_000
	HundredThousand Rarity = 100_000
)

type TooCommonError

type TooCommonError struct {
	Occurrences int
	Level       string
}

TooCommonError creates a switchable type of error for common passwords

func (*TooCommonError) Error

func (t *TooCommonError) Error() string

Jump to

Keyboard shortcuts

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