Documentation
¶
Index ¶
- Constants
- func ComputeFileHMAC(filePath string, key []byte) (string, error)
- func ComputeFileHMACAndWrite(filePath string, key []byte) error
- func Copy(srcFile, dstFile string) error
- func GetExecDir() string
- func GetSystemRootDir() string
- func MandatoryValidateHMAC(filePath string, key []byte) error
- func Mov(srcFile, dstFile string) error
- func PathExists(path string) (bool, error)
- func ReadFileLines(path string, delim byte) []string
- func ReadFileLinesTrimDelim(path string, delim byte, isTrim bool) []string
- func ValidateHMAC(filePath string, key []byte) error
Constants ¶
View Source
const PathSeparatorStr = string(os.PathSeparator)
Variables ¶
This section is empty.
Functions ¶
func ComputeFileHMAC ¶
ComputeFileHMAC 计算指定文件的HMAC-SM3值
参数:
- filePath: 要计算的文件路径
- key: 用于HMAC计算的密钥
返回值:
- string: 计算得到的HMAC十六进制字符串
- error: 操作过程中遇到的错误
func ComputeFileHMACAndWrite ¶
ComputeFileHMACAndWrite 计算指定文件的HMAC值并写入.hmac文件
参数:
filePath: 要计算HMAC的文件路径 key: 用于HMAC计算的密钥
返回:
error: 操作过程中发生的错误,包括HMAC计算失败或文件写入失败
func Copy ¶
Copy 复制文件或目录。如果目标路径不存在,会自动创建对应目录。 参数:
- srcFile: 源文件或目录路径。
- dstFile: 目标文件或目录路径。
返回值:
- error: 错误信息。
func GetSystemRootDir ¶
func GetSystemRootDir() string
GetSystemRootDir 返回操作系统安装位置的根目录 Windows: C:\ (基于 SystemDrive/SystemRoot 环境变量) Unix: /
func MandatoryValidateHMAC ¶
MandatoryValidateHMAC 校验文件及其HMAC签名文件是否存在并验证签名
参数:
filePath - 需要校验的文件路径 key - 用于HMAC校验的密钥
返回:
error - 如果HMAC文件不存在或校验失败则返回错误
注意:
- 会查找同目录下以.hmac为后缀的HMAC签名文件进行比对
func Mov ¶
Mov 移动文件或目录。如果目标路径已存在,会覆盖目标文件或目录。 参数:
- srcFile: 源文件或目录路径。
- dstFile: 目标文件或目录路径。
返回值:
- error: 错误信息。
func PathExists ¶
PathExists 检查指定路径是否存在。 参数:
- path: 需要检查的文件或目录路径。
返回值:
- bool: 如果路径存在,返回 true;否则返回 false。
- error: 如果检查过程中发生错误(非“路径不存在”错误),返回该错误;否则返回 nil。
注意:
- 如果路径不存在,不会返回错误,而是返回 false 和 nil。
- 其他错误(如权限不足)会直接返回。
func ReadFileLines ¶
ReadFileLines 读取文件内容并按指定分隔符分割为多行字符串。 参数:
- path: 文件路径。
- delim: 行分隔符。
返回值:
- []string: 分割后的字符串数组。
func ReadFileLinesTrimDelim ¶
func ValidateHMAC ¶
ValidateHMAC 验证指定文件的HMAC签名是否匹配 参数:
- filePath: 要验证的文件路径
- key: 用于HMAC计算的密钥
返回:
- error: 如果验证失败或发生错误则返回错误信息,验证成功返回nil
注意:
- 会查找同目录下以.hmac为后缀的HMAC签名文件进行比对
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.