package charsets

import "git.sr.ht/~seirdy/moac/v2/charsets"

Package charsets contains types, functions, and defaults for charsets used in passwords.

Index

Package Files

charsets.go defaults.go

Variables

DefaultCharsets contains pre-built named charsets. This makes identifying a charset by name (e.g. as a CLI argument) much easier.

func IsDefault

func IsDefault(c Charset) bool

IsDefault returns true if the charset c is represented in DefaultCharsets.

type Charset

type Charset interface {
    String() string
    Runes() []rune
}

Charset is the interface implemented by any charset used to build passwords. It contains a charset's name as well as string and []rune representations of its glyphs.

type CharsetCollection

type CharsetCollection []Charset

CharsetCollection holds a list of charsets, and can bulk-convert them to strings, runes, and names.

func ParseCharsets

func ParseCharsets(charsetNames []string) (cs CharsetCollection)

ParseCharsets creates a CharsetCollection from string identifiers. The strings "lowercase", "uppercase", "numbers", and "symbols" all refer to their respective constants; "ascii" is an alias for all four. The same goes for "latin1", "latinExtendedA", "latinExtendedB", and "ipaExtensions"; "latin" is an alias for these four. Any other strings have their runes extracted and turned into a new CustomCharset. See CharsetCollection.Add() for docs on how each entry is added.

func (*CharsetCollection) Add

func (cs *CharsetCollection) Add(newCharsets ...Charset)

Add adds a charset to a CharsetCollection after de-duplicating its contents and the existing entries. All newCharsets are first individually deduplicated/sorted first. Whether an existing charset or the new entry gets extra deduplication depends on whichever will be bigger afterward; Add will try to maximize charset sizes while eliminating any redundancies.

func (*CharsetCollection) AddDefault

func (cs *CharsetCollection) AddDefault(newCharsets ...DefaultCharset)

AddDefault is equivalent to Add, but skips sorting/deduplication. This makes adding default charsets a bit faster, since those are already sorted/deduplicated.

type CustomCharset

type CustomCharset []rune

CustomCharset is a charset constructed from an existing rune array. It also features methods for mutability, allowing de-duplication and sorting of contents.

func (CustomCharset) Runes

func (cc CustomCharset) Runes() []rune

Runes returns the underlying []rune the CustomCharset is based on.

func (CustomCharset) String

func (cc CustomCharset) String() string

type DefaultCharset

type DefaultCharset int

DefaultCharset is a pre-built charset, with a name and string/rune representations.

const (
    // Lowercase contains runes in the range [a-z].
    Lowercase DefaultCharset = iota
    // Uppercase contains runes in the range [A-Z].
    Uppercase
    // Numbers contains runes in the range [0-9].
    Numbers
    // Symbols contains all the ASCII symbols.
    Symbols
    // Latin1 contains all the glyphs in the Latin-1 Unicode block.
    Latin1
    // LatinExtendedA contains all the glyphs in the Latin Extended-A Unicode block.
    LatinExtendedA
    // LatinExtendedB contains all the glyphs in the Latin Extended-B Unicode block.
    LatinExtendedB
    // IPAExtensions contains all the glyphs in the IPA Extensions Unicode block.
    IPAExtensions
)

func (DefaultCharset) Name

func (dc DefaultCharset) Name() string

Name outputs the human-readable name for a charset, useful for matching user input.

func (DefaultCharset) Runes

func (dc DefaultCharset) Runes() []rune

Runes outputs all the runes in a charset.

func (DefaultCharset) String

func (dc DefaultCharset) String() string

Package charsets imports 1 packages (graph).

Version v2.0.2 (latest) | Published Oct 5, 2021 | Platform: linux/amd64 | Updated 1 month ago

.
Tools for package owners.