validators

package module
v0.0.0-...-0999fdb Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

README

validators

GoDoc Build Status

validators provides utilities for validating user input. Most of them are structured for use in jsonmap

Documentation

Index

Constants

View Source
const (
	// RFC5890_4_2LabelMaxLength defines the maximum length of a single IDNA label
	RFC5890_4_2LabelMaxLength = 252
)

Variables

View Source
var SimpleCaseFolding = map[rune]rune{}/* 1245 elements not displayed */

SimpleCaseFolding table

Functions

func ContextualRules

func ContextualRules(val []rune, idx int) bool

ContextualRules is an implementation of the contextual rules registery found in RFC5892 Appendix A.1-A.9 val: a rune-slice of the label being validated idx: the index of the currently considered rune returns: true if pPVALID, false otherwise

func NewMultiValidator

func NewMultiValidator(v jsonmap.Validator) jsonmap.TypeMap

Used for StringsArray, which has a "V" field containing []string. Optionally can take a string validator to apply to each entry.

func RFC5891DNS

func RFC5891DNS(record string) error

RFC5891DNS is the RFC5891 complaint validator for hostnames DNS records, and ensures compliance with IDNA

func RFC5891DNSIgnoreCase

func RFC5891DNSIgnoreCase(record string) error

RFC5891DNSIgnoreCase ensures that a label is RFC5891 compliant, while ignoring "case", which is probably useful for validation, since most clients will kindly lowercase things for their users. The strict RFC compliant is used after lowercasing. Both are exposed in case using this turns out to have been a bad idea

func RFC5892

func RFC5892(label string) error

RFC5892 ensures a label complies with IDNP for labels (less strict than the rules for IDNA DNS records, but used by it)

func ToNFKC

func ToNFKC(c rune) rune

ToNFKC uses the NFKC normalization for individual runes

func ZeroWidthNonJoiner

func ZeroWidthNonJoiner(val []rune, idx int) (ok bool)

ZeroWidthNonJoiner Helper for the schematic parsing for zero width non-joiners

Types

type HostNameAndPortValidator

type HostNameAndPortValidator struct{}

HostNameAndPortValidator implements the jsonmap Validator interface.

func (*HostNameAndPortValidator) Validate

func (h *HostNameAndPortValidator) Validate(v interface{}) (munged interface{}, err error)

Validate ensures that the hostname given is a valid unicode hostname and optional port. v: the the value to be verified, should be a string returns:

munged: the, possibly modified, value
err: any errors encountered

type HostNameValidator

type HostNameValidator struct{}

HostNameValidator implements the jsonmap Validator interface.

func (*HostNameValidator) Validate

func (h *HostNameValidator) Validate(v interface{}) (munged interface{}, err error)

Validate ensures that the hostname given is a valid unicode hostname v: the the value to be verified, should be a string returns:

munged: the, possibly modified, value
err: any errors encountered

type HostnameOrIpValidator

type HostnameOrIpValidator struct{}

IPValidator is a type implementing the jsonmap Validator interface for IP Addresses

func (*HostnameOrIpValidator) Validate

func (h *HostnameOrIpValidator) Validate(v interface{}) (munged interface{}, err error)

Validate confirms that its input is a string, and is a valid IP (IPv4 or IPv6)

type IPValidator

type IPValidator struct{}

IPValidator is a type implementing the jsonmap Validator interface for IP Addresses

func (*IPValidator) Validate

func (h *IPValidator) Validate(v interface{}) (munged interface{}, err error)

Validate confirms that its input is a string, and is a valid IP (IPv4 or IPv6)

type JWTValidator

type JWTValidator struct {
	Clock clockwork.Clock
	Key   []byte
}

JWTValidator provides a mechanism to verify that a string is a valid representation of a JWT token, and that it has the required "exp" and "iat" claims, has not expired, and is not in the future. The validate method does *NOT* verfiy that the token's signature is valid

func (*JWTValidator) Validate

func (valid *JWTValidator) Validate(v interface{}) (munged interface{}, err error)

Validate confirms that a JWT can be parsed and isn't expired. it does *NOT* verify the signature.

type JoinType

type JoinType int

JoinType is The unicode joining types

const (
	JoinU JoinType = iota // non-joining
	JoinR                 // Right-joining
	JoinL                 // left-joining
	JoinD                 // dual-joining
	JoinC                 // join-causing
	JoinT                 // transparent
)

The unicode joining types

func GetJoinType

func GetJoinType(r rune) JoinType

GetJoinType takes a rune and returns the joining class for it

type MultiValidator

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

shamelessly stolen from https://github.com/russellhaering/jsonmap/blob/master/validators.go but made to accept any validator instead of explicitely a StringValidator

func (*MultiValidator) Marshal

func (s *MultiValidator) Marshal(ctx jsonmap.Context, parent *reflect.Value, src reflect.Value) (json.Marshaler, error)

func (*MultiValidator) Unmarshal

func (ss *MultiValidator) Unmarshal(ctx jsonmap.Context, parent *reflect.Value, partial interface{}, dstValue reflect.Value) error

type PortValidator

type PortValidator struct{}

PortValidator implements the jsonmap Validator interface.

func (*PortValidator) Validate

func (h *PortValidator) Validate(v interface{}) (munged interface{}, err error)

Validate ensures that the port given is valid (empty OR non-zero uint16). 0 ports are legal but will fail this validator. v: the the value to be verified, should be a string returns:

munged: the, possibly modified, value
err: any errors encountered

type X509CertificateValidator

type X509CertificateValidator struct {
	Clock clockwork.Clock
}

func (*X509CertificateValidator) Validate

func (valid *X509CertificateValidator) Validate(v interface{}) (munged interface{}, err error)

Jump to

Keyboard shortcuts

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