Skip to main content

Module utils

Module utils 

Source
Expand description

工具函数模块

提供常用的工具函数和辅助方法

Functions§

bytes_to_hex
将字节数组转换为十六进制字符串
constant_time_eq
安全地比较两个字节数组(防止时序攻击)
current_timestamp_ms
获取当前时间戳(毫秒)
current_timestamp_secs
获取当前时间戳(秒)
generate_id
生成唯一 ID(基于时间戳和随机数)
generate_short_id
生成简短 ID(仅用于测试或临时标识)
hex_to_bytes
将十六进制字符串转换为字节数组
is_valid_connection_id
验证字符串是否为有效的连接 ID
is_valid_user_id
验证字符串是否为有效的用户 ID
simple_hash
计算数据的哈希值(简单实现)
truncate_string
截断字符串到指定长度(如果超过)