utils

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package utils contain useful helper functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(encryptedString string, keyString string) (decryptedString string, err error)

AESDecrypt decrypts using AES. keyString must be 128, 196 or 256 bits.

func AESEncrypt

func AESEncrypt(stringToEncrypt string, keyString string) (encryptedString string, err error)

AESEncrypt encrypts using AES. keyString must be 128, 196 or 256 bits.

func Bcrypt

func Bcrypt(body string) (string, error)

Bcrypt returns the b-crypt digest of a string

It uses 4 as the cost of computing

func BcryptCompare

func BcryptCompare(input, truth string) bool

BcryptCompare takes an input and a truth digest and compares them

Use this instead of direct comparisons because this function is safe.

func CheckFileExists

func CheckFileExists(path string) bool

CheckFileExists takes a path string and returns true if it exists

func GenerateJWT

func GenerateJWT(data map[string]interface{}, secret string) (jwtString string, err error)

GenerateJWT generates a JWT from map

func IsHex

func IsHex(s string) bool

IsHex takes a string and returns true if it is a hex string

func MakeRequest

func MakeRequest(router *gin.Engine, method, endpoint string, body io.Reader, cookies ...*http.Cookie) *httptest.ResponseRecorder

MakeRequest runs a single request. This is used by test functions that run requests on the router

func Min

func Min(a, b int) int

Min returns the minimum of two integers

func MustAtoi

func MustAtoi(value string) int

MustAtoi is like strconv.Atoi, but panics if it fails

func RemoveAccessToken

func RemoveAccessToken(ctx *gin.Context, secureCookie bool)

RemoveAccessToken deletes the user access token

func SHA256

func SHA256(body string) string

SHA256 returns the sha256 digest of a string

func UniqueInts

func UniqueInts(values []int) []int

UniqueInts takes a slice of integers and returns a new slice without duplicates

func ValidateJWT

func ValidateJWT(tokenString, secret string) (*jwt.Token, error)

ValidateJWT takes a JWT token string and validates it

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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