utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToUint64Array

func BytesToUint64Array(data []byte) []uint64

BytesToUint64Array converts a slice of bytes to a slice of uint64 integers. This function is typically used to convert a slice of bytes (which might have been stored in linear memory) back into packed data in the form of uint64 integers.

func CalculateHash

func CalculateHash(data []byte) (hash string, err error)

calculateHash computes the SHA-256 hash of the input byte slice. It returns the hash as a hex-encoded string.

func CompareHashes

func CompareHashes(hash1, hash2 string) error

The `ConstantTimeCompare` function is used here to securely compare two hash values. It prevents timing-based attacks by ensuring that the comparison takes the same amount of time, regardless of whether the values match or not. If the hashes are not equal, an error is returned.

func GetlogLevel

func GetlogLevel(s LogSeverity) slog.Level

GetlogLevel gets 'slog' level based on severity specified by user

func NewLogger

func NewLogger(severity LogSeverity) *slog.Logger

NewLogger returns new slog ref

func PackUI64

func PackUI64(dataType types.ValueType, offset uint32, size uint32) (uint64, error)

PackUI64 takes a data type (in the form of a byte), a pointer (offset in memory), and a size (amount of memory/data to consider). It returns a packed uint64 representation.

Structure of the packed uint64: - Highest 8 bits: data type - Next 32 bits: offset - Lowest 24 bits: size

This function will return error if the provided size is larger than what can be represented in 24 bits (i.e., larger than 16,777,215).

func Uint64ArrayToBytes

func Uint64ArrayToBytes(data []uint64) []byte

uint64ArrayToBytes converts a slice of uint64 integers to a slice of bytes. This function is typically used to convert a slice of packed data into bytes, which can then be stored in linear memory.

func UnpackUI64

func UnpackUI64(packedData uint64) (dataType types.ValueType, offset uint32, size uint32)

UnpackUI64 reverses the operation done by PackUI64. Given a packed uint64, it will extract and return the original dataType, offset (ptr), and size.

Types

type LogSeverity

type LogSeverity uint8
const (
	LogDebug LogSeverity = iota + 1
	LogInfo
	LogWarning
	LogError
)

Jump to

Keyboard shortcuts

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