Documentation ¶
Index ¶
- func BytesToUint64Array(data []byte) []uint64
- func CalculateHash(data []byte) (hash string, err error)
- func CompareHashes(hash1, hash2 string) error
- func GetlogLevel(s LogSeverity) slog.Level
- func NewLogger(severity LogSeverity) *slog.Logger
- func PackUI64(dataType types.ValueType, offset uint32, size uint32) (uint64, error)
- func Uint64ArrayToBytes(data []uint64) []byte
- func UnpackUI64(packedData uint64) (dataType types.ValueType, offset uint32, size uint32)
- type LogSeverity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToUint64Array ¶
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 ¶
calculateHash computes the SHA-256 hash of the input byte slice. It returns the hash as a hex-encoded string.
func CompareHashes ¶
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 PackUI64 ¶
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 ¶
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.
Types ¶
type LogSeverity ¶
type LogSeverity uint8
const ( LogDebug LogSeverity = iota + 1 LogInfo LogWarning LogError )