validations

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 16 Imported by: 0

README

validations

Documentation

Index

Constants

View Source
const (
	STR         = "Case-sensitive string"
	IP          = "IP"
	EMAIL       = "Email"
	FQDN        = "FQDN"
	INTEGER     = "Integer"
	CIDR        = "CIDR"
	CITY        = "City"
	COUNTRY     = "Country"
	FLOAT       = "Float"
	URL         = "URL"
	MD5         = "MD5"
	HEXADECIMAL = "Hexadecimal"
	BASE64      = "BASE64"
	DATE        = "Date"
	MAC         = "MAC"
	MIME        = "MIME type"
	PHONE       = "Phone"
	SHA1        = "SHA-1"
	SHA224      = "SHA-224"
	SHA256      = "SHA-256"
	SHA384      = "SHA-384"
	SHA512      = "SHA-512"
	SHA3_224    = "SHA3-224"
	SHA3_256    = "SHA3-256"
	SHA3_384    = "SHA3-384"
	SHA3_512    = "SHA3-512"
	SHA512_224  = "SHA512-224"
	SHA512_256  = "SHA512-256"
	DATETIME    = "Datetime"
	UUID        = "UUID"
	BOOLEAN     = "Boolean"
	ISTR        = "String"
	PATH        = "Path"
	OBJECT      = "UUID|MD5|SHA3-256"
	ADVERSARY   = "Adversary"
	REGEX       = "Regex"
	PORT        = "Port"
)

Variables

View Source
var Definitions = []Definition{}/* 128 elements not displayed */

Functions

func GenerateSHA3256

func GenerateSHA3256(value string) string

GenerateSHA3256 generates a SHA3-256 hash from the given string.

func ValidateAdversary

func ValidateAdversary(value interface{}) (string, string, error)

ValidateAdversary validates if the given value is a valid adversary. It checks if the value is a valid URL, UUID, email, IP, phone or FQDN. If any of these validations pass, it returns an error. If the value is not a string, it returns an error. Otherwise, it returns the value and its SHA3-256 hash.

func ValidateBase64

func ValidateBase64(value interface{}) (string, string, error)

ValidateBase64 validates if a given string is a valid base64 encoded string. It returns the original string, its SHA3-256 hash and an error if the validation fails.

func ValidateBoolean

func ValidateBoolean(value interface{}) (bool, string, error)

ValidateBoolean validates if a given value is a boolean and generates a SHA3-256 hash of the value. Returns a boolean indicating if the value is a boolean, the SHA3-256 hash of the value and an error if any.

func ValidateCIDR

func ValidateCIDR(value interface{}) (string, string, error)

ValidateCIDR validates if a given string is a valid CIDR notation and returns the CIDR string and its SHA3-256 hash.

func ValidateCity

func ValidateCity(value interface{}) (string, string, error)

ValidateCity validates a city name by converting it to title case and generating a SHA3-256 hash. It takes a value of type interface{} and returns the validated city name, its SHA3-256 hash, and an error (if any).

func ValidateCountry

func ValidateCountry(value interface{}) (string, string, error)

ValidateCountry validates a given country string value by converting it to title case and generating a SHA3-256 hash. Returns the validated country string value, its SHA3-256 hash, and an error if the value is not a string.

func ValidateDate

func ValidateDate(value interface{}) (string, string, error)

ValidateDate validates a date string in the format "2006-01-02" and returns the formatted date string and its SHA3-256 hash.

func ValidateDatetime

func ValidateDatetime(value interface{}) (string, string, error)

ValidateDatetime validates a datetime string in the RFC3339Nano format and returns the formatted datetime string and its SHA3-256 hash.

func ValidateEmail

func ValidateEmail(value interface{}) (string, string, error)

ValidateEmail validates if a given string is a valid email address. It returns the email address, its SHA3-256 hash and an error if any.

func ValidateFQDN

func ValidateFQDN(value interface{}) (string, string, error)

ValidateFQDN validates a fully qualified domain name (FQDN) string. It returns the validated FQDN, its SHA3-256 hash, and an error if the validation fails.

func ValidateFloat

func ValidateFloat(value interface{}) (float64, string, error)

ValidateFloat validates if the given value is a float64 or an int64 that can be converted to a float64. It returns the validated float64 value, its SHA3-256 hash, and an error if the value is not a float64 or an int64.

func ValidateHexadecimal

func ValidateHexadecimal(value interface{}) (string, string, error)

ValidateHexadecimal validates if the given value is a valid hexadecimal string. It returns the hexadecimal string in lowercase format, its SHA3-256 hash and an error if any.

func ValidateIP

func ValidateIP(value interface{}) (string, string, error)

ValidateIP validates if the given IP address is valid and not private, multicast, loopback, or unspecified. It returns the validated IP address and its SHA3-256 hash.

func ValidateInteger

func ValidateInteger(value interface{}) (int64, string, error)

ValidateInteger validates if a value is an integer and returns its int64 representation, its SHA3-256 hash and an error if the value is not an integer.

func ValidateMAC

func ValidateMAC(value interface{}) (string, string, error)

ValidateMAC validates if a given string is a valid MAC address and returns the MAC address in uppercase and its SHA3-256 hash.

func ValidateMD5

func ValidateMD5(value interface{}) (string, string, error)

ValidateMD5 validates if a given string is a valid MD5 hash. It receives a value of type interface{} and returns the validated string, its SHA3-256 hash and an error.

func ValidateMime

func ValidateMime(value interface{}) (string, string, error)

ValidateMime validates if a given string is a valid MIME type and returns the validated string, its SHA3-256 hash and an error if any.

func ValidateObject

func ValidateObject(value interface{}) (string, string, error)

ValidateObject validates an object by checking if it's a valid UUID, MD5 or SHA3256 hash. If the object is valid, it returns the string representation of the hash, the hash itself and no error. If the object is invalid, it returns empty strings and an error.

func ValidatePath

func ValidatePath(value interface{}) (string, string, error)

ValidatePath validates if the given value is a valid path and returns the path in lowercase and its SHA3-256 hash. If the value is not a string or contains "://" it returns an error.

func ValidatePhone

func ValidatePhone(value interface{}) (string, string, error)

ValidatePhone validates a phone number and returns the validated phone number and its SHA3-256 hash. If the value is not a string, it returns an error.

func ValidatePort added in v1.0.1

func ValidatePort(value interface{}) (string, string, error)

ValidatePort validates a port with protocol. It returns the validated PORT, its SHA3-256 hash, and an error if the validation fails.

func ValidateRegEx

func ValidateRegEx(regex, value string) error

ValidateRegEx validates if a given value matches a regular expression. It returns an error if the value does not match the expression.

func ValidateRegexComp

func ValidateRegexComp(value interface{}) (string, string, error)

ValidateRegexComp validates if a given value is a valid regular expression. It returns the validated value, its SHA3-256 hash, and an error if the value is not a string or is not a valid regular expression.

func ValidateSHA1

func ValidateSHA1(value interface{}) (string, string, error)

ValidateSHA1 validates if a given value is a valid SHA1 hash. It receives a value of any type and returns the validated SHA1 hash as a string, its SHA3-256 hash as a string and an error if the value is not a string or if it is not a valid SHA1 hash.

func ValidateSHA224

func ValidateSHA224(value interface{}) (string, string, error)

ValidateSHA224 validates if a given string is a valid SHA-224 hash and returns the hash in lowercase and its SHA3-256 hash.

func ValidateSHA256

func ValidateSHA256(value interface{}) (string, string, error)

ValidateSHA256 validates that a given value is a valid SHA256 hash. It takes an interface{} value and returns the validated value as a string, the SHA3256 hash of the value as a string, and an error if the value is not a valid SHA256 hash.

func ValidateSHA3224

func ValidateSHA3224(value interface{}) (string, string, error)

ValidateSHA3224 validates if a given string is a valid SHA3-224 hash and returns the hash in lowercase and its SHA3-256 hash.

func ValidateSHA3256

func ValidateSHA3256(value interface{}) (string, string, error)

ValidateSHA3256 validates if the given value is a valid SHA3-256 hash.

func ValidateSHA3384

func ValidateSHA3384(value interface{}) (string, string, error)

ValidateSHA3256 validates if a given string is a valid SHA3-256 hash and returns the hash in lowercase and its SHA3-256 hash.

func ValidateSHA3512

func ValidateSHA3512(value interface{}) (string, string, error)

ValidateSHA3512 validates if a given string is a valid SHA3-512 hash and returns the hash in lowercase and its SHA3-256 hash.

func ValidateSHA384

func ValidateSHA384(value interface{}) (string, string, error)

ValidateSHA384 validates a string value as a SHA384 hash and returns the hash value, its SHA3256 hash, and an error if any.

func ValidateSHA512

func ValidateSHA512(value interface{}) (string, string, error)

ValidateSHA512 validates if a given value is a valid SHA512 hash. It receives a value of any type and returns the validated hash as a string, its SHA3256 hash as a string and an error if the value is not a valid SHA512 hash.

func ValidateSHA512224

func ValidateSHA512224(value interface{}) (string, string, error)

ValidateSHA512224 validates if a given value is a valid SHA512/224 hash. It receives a value of any type and returns the validated hash as a string, the hash generated using SHA3-256 and an error if the value is not a string or if it doesn't match the expected format.

func ValidateSHA512256

func ValidateSHA512256(value interface{}) (string, string, error)

ValidateSHA512256 validates that a given value is a valid SHA512-256 hash. It takes an interface{} value and returns the validated hash as a string, the hash generated by the GenerateSHA3256 function, and an error if any.

func ValidateString

func ValidateString(value interface{}, insensitive bool) (string, string, error)

ValidateString validates a string value and returns the original value, its SHA3-256 hash and an error. If the insensitive flag is set to true, the value is converted to lowercase before hashing.

func ValidateURL

func ValidateURL(value interface{}) (string, string, error)

ValidateURL validates a given URL string and returns the URL in lowercase and its SHA3-256 hash. If the value is not a string, it returns an error.

func ValidateUUID

func ValidateUUID(value interface{}) (uuid.UUID, string, error)

ValidateUUID validates if a given value is a valid UUID string and returns the UUID, its SHA3-256 hash and an error if any.

func ValidateValue

func ValidateValue(value interface{}, t string) (interface{}, string, error)

Types

type Definition

type Definition struct {
	Type         string       `json:"type" example:"object"`
	Description  string       `json:"description" example:"Important description about the type"`
	DataType     string       `json:"dataType" example:"String"`
	Example      *Entity      `json:"example,omitempty"`
	Attributes   []Definition `json:"attributes,omitempty"`
	Associations []Definition `json:"associations,omitempty"`
	Tags         []string     `json:"tags,omitempty"`
	Correlate    []string     `json:"correlate,omitempty"`
	Label        string       `json:"label,omitempty"`
}

type Entity

type Entity struct {
	Type         string                 `json:"type"  example:"object"`
	Attributes   map[string]interface{} `json:"attributes"`
	Associations []Entity               `json:"associations"`
	Reputation   int                    `json:"reputation" example:"-1"`
	Correlate    []string               `json:"correlate"`
	Tags         []string               `json:"tags"`
	VisibleBy    []string               `json:"visibleBy"`
}

Jump to

Keyboard shortcuts

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