cdkey

package module
v0.0.0-...-9e5d583 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2015 License: MIT Imports: 14 Imported by: 0

README

cdkey

CDKEY generation and management.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyGenN

func KeyGenN(prefix string, keylen, size int) ([]string, error)

KeyGenN generates a set of CDKEYs, which guaranteed to be unique and sorted.

It returns error if 1) `prefix` is not valid base32 format; 2)

32^(keylen-len(prefix)) < size * 100,

which means a randomly generated key has a chance more than 1% to be valid.

func NormalizeKey

func NormalizeKey(key string) (string, bool)

NormalizeKey transforms a key to base32 format.

All lowercase letters will be converted to uppercase, 'O'/'o' will be replaced by '0', 'L'/'l' and 'I'/'i' will be replaced by '1'.

If the given key contains any non-digital non-alphbetic character or 'U'/'u', it returns an empty string and false.

func SetLogger

func SetLogger(l Logger)

SetLogger sets a Logger as the cdkey lib's logger.

Types

type KeyInfo

type KeyInfo struct {
	Key    string `json:"key"`
	Status string `json:"status"`
}

type Logger

type Logger interface {
	Info(v ...interface{})
	Error(v ...interface{})
}

Logger is a simple interface contains 2 log levels. The cdkey lib user is responsable for implementing Logger methods.

type Pack

type Pack struct {
	Name string
	// contains filtered or unexported fields
}

func CreatePack

func CreatePack(path string, name, prefix string, keylen, packsize int, note string) (*Pack, error)

func LoadPack

func LoadPack(path string) (*Pack, error)

func (*Pack) Close

func (p *Pack) Close()

func (*Pack) Disable

func (p *Pack) Disable(msg string) error

func (*Pack) Enable

func (p *Pack) Enable() error

func (*Pack) Info

func (p *Pack) Info() PackInfo

func (*Pack) ListKeys

func (p *Pack) ListKeys() ([]KeyInfo, error)

func (*Pack) UseKey

func (p *Pack) UseKey(key string) error

type PackInfo

type PackInfo struct {
	Name       string     `json:"name"`
	Prefix     string     `json:"prefix"`
	KeyLen     int        `json:"keylen"`
	PackSize   int        `json:"packsize"`
	Status     packStatus `json:"status"`
	Note       string     `json:"note"`
	CreateTime time.Time  `json:"createTime"`
}

type Server

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

func NewServer

func NewServer(path string) *Server

func (*Server) AddPack

func (s *Server) AddPack(name string, prefix string, keylen, packsize int, note string) error

func (*Server) DisablePack

func (s *Server) DisablePack(name string, msg string) error

func (*Server) EnablePack

func (s *Server) EnablePack(name string) error

func (*Server) HTTPServeMux

func (s *Server) HTTPServeMux() *http.ServeMux

func (*Server) ListKeys

func (s *Server) ListKeys(packName string) ([]KeyInfo, error)

func (*Server) ListPacks

func (s *Server) ListPacks() []PackInfo

func (*Server) RemovePack

func (s *Server) RemovePack(name string) error

func (*Server) Stop

func (s *Server) Stop()

func (*Server) UseKey

func (s *Server) UseKey(packName, key string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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