lib

package
v1.6.41 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 21 Imported by: 11

Documentation

Overview

Package lib provides additional functionalities to the application:

- AES encryption-decryption - Argon2id hashing - SHA hashing - Two-factor authentication - Email format validation along with MX lookup

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToPNG added in v1.6.1

func ByteToPNG(imgByte []byte, path string) (string, error)

ByteToPNG - generate PNG from bytes and save on the disk

func Decrypt added in v1.6.1

func Decrypt(ciphertext []byte, key []byte) ([]byte, error)

Decrypt using AES algorithm AES128 key size: 16 bytes AES192 key size: 24 bytes AES256 key size: 32 bytes

func Encrypt added in v1.6.1

func Encrypt(plaintext []byte, key []byte) ([]byte, error)

Encrypt using AES algorithm

- AES128 key size: 16 bytes - AES192 key size: 24 bytes - AES256 key size: 32 bytes

func FileExist added in v1.6.1

func FileExist(path string) bool

FileExist returns true if the file exists, otherwise returns false

func HTMLModel added in v1.6.1

func HTMLModel(in []string) map[string]interface{}

HTMLModel takes a slice and builds a model for populating a templated email

func HashPass

func HashPass(config HashPassConfig, pass, secret string) (string, error)

HashPass - securely hash passwords using Argon2id

func InitRateLimiter added in v1.6.27

func InitRateLimiter(formattedRateLimit, trustedPlatform string) (*limiter.Limiter, error)

InitRateLimiter - initialize the rate limiter instance

func NewQR added in v1.6.1

func NewQR(encryptedMessage []byte, issuer string) ([]byte, error)

NewQR - creates a byte array containing QR code encoded PNG image, with level Q error correction, needed for the client apps to generate tokens.

func NewTOTP added in v1.6.1

func NewTOTP(account string, issuer string, hash crypto.Hash, digits int) ([]byte, error)

NewTOTP - creates a new TOTP object and returns a serialized byte array

func RemoveAllSpace

func RemoveAllSpace(s string) string

RemoveAllSpace - remove all spaces and return the result as string

func SecureRandomNumber added in v1.6.1

func SecureRandomNumber(totalDigit uint64) uint64

SecureRandomNumber generates cryptographically secure pseudo-random number. To generate a random number consisting of x number of digits, pass x as the parameter. For example, SecureRandomNumber(3) will generate a number between 100 and 999

func StrArrHTMLModel added in v1.6.1

func StrArrHTMLModel(s string) []string

StrArrHTMLModel first slices a string into all substrings separated by `;` and then slices each substring separated by `:` for `HTMLModel` function

Example: StrArrHTMLModel(key1:value1,key2:value2,key3:value3) will return [key1 value1 key2 value2 key3 value3]

func ValidateEmail

func ValidateEmail(e string) bool

ValidateEmail - check if the email provided passes the required structure and length test. It also checks the domain has a valid MX record.

Credit: Edd Turtle

func ValidateTOTP added in v1.6.1

func ValidateTOTP(encryptedMessage []byte, issuer string, userInput string) ([]byte, error)

ValidateTOTP - validates the user-provided token

Types

type HashPassConfig

type HashPassConfig struct {
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	SaltLength  uint32
	KeyLength   uint32
}

HashPassConfig - params for argon2id

Directories

Path Synopsis
Package middleware contains:
Package middleware contains:
Package renderer uses template engine to render and serve HTML pages
Package renderer uses template engine to render and serve HTML pages

Jump to

Keyboard shortcuts

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