util

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePasswordAndHash

func ComparePasswordAndHash(password, encodedHash string) (bool, error)

func CreateArgon2Hash

func CreateArgon2Hash(password string) (string, error)

func DerefPtr

func DerefPtr[T any](p *T, defaultValue T) T

func GetMachineID

func GetMachineID() string

func HashSHA256Hex added in v1.2.0

func HashSHA256Hex(data []byte) string

func HashStringSHA256Hex added in v1.2.0

func HashStringSHA256Hex(value string) string

func InitArgon2idParams

func InitArgon2idParams(param Argon2idParams)

func InitRSAPrivateKey

func InitRSAPrivateKey(pemStr string) (*rsa.PrivateKey, error)

func IsArgon2Hash

func IsArgon2Hash(s string) bool

func MongoCleanup

func MongoCleanup(mongodbClient *mongo.Client, dbName string) error

func PEMToRSAPublicKey

func PEMToRSAPublicKey(pemBytes string) (*rsa.PublicKey, error)

func Ptr

func Ptr[T any](v T) *T

func RSAPublicKeyToPEM

func RSAPublicKeyToPEM(pub *rsa.PublicKey) ([]byte, error)

Types

type Argon2idParams

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

type GenericMap

type GenericMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

GenericMap is a concurrent safe map with generic key and value types.

func NewGenericMap

func NewGenericMap[K comparable, V any]() *GenericMap[K, V]

NewGenericMap creates a new instance of GenericMap.

func (*GenericMap[K, V]) Clear

func (m *GenericMap[K, V]) Clear()

Clear deletes all the entries, resulting in an empty Map.

func (*GenericMap[K, V]) CompareAndDelete

func (m *GenericMap[K, V]) CompareAndDelete(key K, old V) (deleted bool)

CompareAndDelete deletes the entry for key if its value is equal to old. The old value must be of a comparable type.

If there is no current value for key in the map, CompareAndDelete returns false (even if the old value is the nil interface value).

func (*GenericMap[K, V]) CompareAndSwap

func (m *GenericMap[K, V]) CompareAndSwap(key K, old, new V) (swapped bool)

CompareAndSwap swaps the old and new values for key if the value stored in the map is equal to old. The old value must be of a comparable type.

func (*GenericMap[K, V]) Delete

func (m *GenericMap[K, V]) Delete(key K)

Delete deletes the value for a key.

func (*GenericMap[K, V]) Load

func (m *GenericMap[K, V]) Load(key K) (value V, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*GenericMap[K, V]) LoadAndDelete

func (m *GenericMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*GenericMap[K, V]) LoadOrStore

func (m *GenericMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*GenericMap[K, V]) Range

func (m *GenericMap[K, V]) Range(f func(key K, value V) bool)

func (*GenericMap[K, V]) Store

func (m *GenericMap[K, V]) Store(key K, value V)

Store sets the value for a key.

func (*GenericMap[K, V]) Swap

func (m *GenericMap[K, V]) Swap(key K, value V) (previous V, loaded bool)

Swap swaps the value for a key and returns the previous value if any. The loaded result reports whether the key was present.

type MerkleNode added in v1.2.0

type MerkleNode struct {
	Hash  string
	Left  *MerkleNode
	Right *MerkleNode
}

func BuildMerkleTree added in v1.2.0

func BuildMerkleTree(leafHashes []string) *MerkleNode

func FindMerkleNode added in v1.2.0

func FindMerkleNode(root *MerkleNode, hash string) *MerkleNode

func TruncateMerkleTree added in v1.2.0

func TruncateMerkleTree(root *MerkleNode, depth int64) *MerkleNode

Jump to

Keyboard shortcuts

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