swca1

package module
v0.0.0-...-5ee7b30 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: MIT Imports: 9 Imported by: 1

README

swca1 GoDoc

swca1 is zero dependency sha-512 based hash implementation with a custom alphabet.

features

  • hash alphabet customization in wkt|alphabet format, where wkt is a well-known tokens:
    • n or 1 - numbers;
    • u or A - uppercase letters;
    • l or a - lowercase letters;
    • s or @ - symbols;
    • rest of tokens string after | is a custom runes which will append to result alphabet.
  • hash size specification in range [0:64] where 0 is reserved for specifying max hash size within required complexity;
  • hash complexity specification:
    • unique - ensures uniqueness of each character in hash;
    • no type repetition - guarantees any pair of adjacent characters in the hash will have a different type;
    • no characters repetition - guarantees that in any pair of adjacent characters there will be no more than one letter, regardless of case.

installation

Standard go get:

go get github.com/unqnown/swca1

usage & example

package test

import (
	"fmt"

	"github.com/unqnown/swca1"
)

func Example() {
	h := swca1.New(
		swca1.Size(swca1.Max),
		swca1.Alphabet(swca1.NULS),
		swca1.Unique,
		swca1.NoTypeRepetition,
		swca1.NoCharacterRepetition,
	)

	_, _ = h.Write([]byte("salt"))

	_, _ = h.Write([]byte("hint"))

	fmt.Printf("%s", h.Sum(nil))
	// output: e@c*x6d-q#J8U&F^%H+t7Y!L1P4M5I$g0S2A?R3o9n
}

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/unqnown/swca1"
)

func main() {
	h := swca1.New(
		swca1.Size(swca1.Max),
		swca1.Alphabet(swca1.NULS),
		swca1.Unique,
		swca1.NoTypeRepetition,
		swca1.NoCharacterRepetition,
	)

	_, _ = h.Write([]byte("salt"))

	_, _ = h.Write([]byte("hint"))

	fmt.Printf("%s", h.Sum(nil))
}
Output:

e@c*x6d-q#J8U&F^%H+t7Y!L1P4M5I$g0S2A?R3o9n

Index

Examples

Constants

View Source
const (
	// NULS represents default alphabet's tokens.
	NULS = "nuls"
	// ABC represents default alphabet.
	ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?!@#$%^&*-+"
	// Enough is an optimal hash size for default alphabet.
	Enough = 20
	// Max is reserved identifier for maximum hash size within required complexity.
	Max = 0
)

Variables

View Source
var ErrUnreachableComplexity = errors.New("swca1: unreachable complexity")

ErrUnreachableComplexity means that there is no way to generate a hash of such size with requested complexity.

Functions

func New

func New(opts ...Option) hash.Hash

New returns sha-512 based hash.Hash with custom alphabet.

func NoCharacterRepetition

func NoCharacterRepetition(o *Options)

NoCharacterRepetition guarantees that in any pair of adjacent characters there will be no more than one letter, regardless of case.

func NoTypeRepetition

func NoTypeRepetition(o *Options)

NoTypeRepetition guarantees any pair of adjacent characters in the hash will have a different type.

func Unique

func Unique(o *Options)

Unique ensures uniqueness of each character in hash.

Types

type Option

type Option func(*Options)

Option is an type of go idiomatic options representation.

func Alphabet

func Alphabet(tokens string) Option

Alphabet allows to customize hash alphabet in "wkt|alphabet" format where "wkt" is a well known tokens:

  • n(1) - numbers;
  • u(A) - uppercase letters;
  • l(a) - lowercase letters;
  • s(@) - symbols.

Rest of tokens string after "|" is a custom runes which will append to result alphabet.

func Size

func Size(size int) Option

Size allows to specify hash size. Allowed hash size is in range [0:64] where 0 is reserved for specifying max hash size within required complexity.

type Options

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

Options represents hash generation configuration.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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