package common import ( "fmt" ) type SDRError uint32 const ( SDR_OK SDRError = 0x0 // 操作成功 SDR_BASE SDRError = 0x01000000 // 错误码基础值 SDR_UNKNOWERR SDRError = SDR_BASE + 0x00000001 // 未知错误 SDR_NOTSUPPORT SDRError = SDR_BASE + 0x00000002 // 不支持的接口调用 SDR_COMMFAIL SDRError = SDR_BASE + 0x00000003 // 与设备通信失败 SDR_HARDFAIL SDRError = SDR_BASE + 0x00000004 // 运算模块无响应 SDR_OPENDEVICE SDRError = SDR_BASE + 0x00000005 // 打开设备失败 SDR_OPENSESSION SDRError = SDR_BASE + 0x00000006 // 创建会话失败 SDR_PARDENY SDRError = SDR_BASE + 0x00000007 // 无私钥使用权限 SDR_KEYNOTEXIST SDRError = SDR_BASE + 0x00000008 // 不存在的密钥调用 SDR_ALGNOTSUPPORT SDRError = SDR_BASE + 0x00000009 // 不支持的算法调用 SDR_ALGMODNOTSUPPORT SDRError = SDR_BASE + 0x0000000A // 不支持的算法模式调用 SDR_PKOPERR SDRError = SDR_BASE + 0x0000000B // 公钥运算失败 SDR_SKOPERR SDRError = SDR_BASE + 0x0000000C // 私钥运算失败 SDR_SIGNERR SDRError = SDR_BASE + 0x0000000D // 签名运算失败 SDR_VERIFYERR SDRError = SDR_BASE + 0x0000000E // 验证签名失败 SDR_SYMOPERR SDRError = SDR_BASE + 0x0000000F // 对称算法运算失败 SDR_STEPERR SDRError = SDR_BASE + 0x00000010 // 多步运算步骤错误 SDR_FILESIZEERR SDRError = SDR_BASE + 0x00000011 // 文件长度超出限制 SDR_FILENOEXIST SDRError = SDR_BASE + 0x00000012 // 指定的文件不存在 SDR_FILEOFSERR SDRError = SDR_BASE + 0x00000013 // 文件起始位置错误 SDR_KEYTYPEERR SDRError = SDR_BASE + 0x00000014 // 密钥类型错误 SDR_KEYERR SDRError = SDR_BASE + 0x00000015 // 密钥错误 SDR_ENCDATAERR SDRError = SDR_BASE + 0x00000016 // ECC加密数据错误 SDR_RANDERR SDRError = SDR_BASE + 0x00000017 // 随机数产生失败 SDR_PRKRERR SDRError = SDR_BASE + 0x00000018 // 私钥使用权限获取失败 SDR_MACERR SDRError = SDR_BASE + 0x00000019 // MAC运算失败 SDR_FILEEXISTS SDRError = SDR_BASE + 0x0000001A // 指定文件已存在 SDR_FILEWERR SDRError = SDR_BASE + 0x0000001B // 文件写入失败 SDR_NOBUFFER SDRError = SDR_BASE + 0x0000001C // 存储空间不足 SDR_INARGERR SDRError = SDR_BASE + 0x0000001D // 输入参数错误 SDR_OUTARGERR SDRError = SDR_BASE + 0x0000001E // 输出参数错误 ) func (s SDRError) Error() string { return s.String() } func (s SDRError) String() string { switch s { case SDR_UNKNOWERR: return fmt.Sprintf("0x%08x: 未知错误", uint32(SDR_UNKNOWERR)) case SDR_NOTSUPPORT: return fmt.Sprintf("0x%08x: 不支持的接口调用", uint32(SDR_NOTSUPPORT)) case SDR_COMMFAIL: return fmt.Sprintf("0x%08x: 与设备通信失败", uint32(SDR_COMMFAIL)) case SDR_HARDFAIL: return fmt.Sprintf("0x%08x: 运算模块无响应", uint32(SDR_HARDFAIL)) case SDR_OPENDEVICE: return fmt.Sprintf("0x%08x: 打开设备失败", uint32(SDR_OPENDEVICE)) case SDR_OPENSESSION: return fmt.Sprintf("0x%08x: 创建会话失败", uint32(SDR_OPENSESSION)) case SDR_PARDENY: return fmt.Sprintf("0x%08x: 无私钥使用权限", uint32(SDR_PARDENY)) case SDR_KEYNOTEXIST: return fmt.Sprintf("0x%08x: 不存在的密钥调用", uint32(SDR_KEYNOTEXIST)) case SDR_ALGNOTSUPPORT: return fmt.Sprintf("0x%08x: 不支持的算法调用", uint32(SDR_ALGNOTSUPPORT)) case SDR_ALGMODNOTSUPPORT: return fmt.Sprintf("0x%08x: 不支持的算法模式调用", uint32(SDR_ALGMODNOTSUPPORT)) case SDR_PKOPERR: return fmt.Sprintf("0x%08x: 公钥运算失败", uint32(SDR_PKOPERR)) case SDR_SKOPERR: return fmt.Sprintf("0x%08x: 私钥运算失败", uint32(SDR_SKOPERR)) case SDR_SIGNERR: return fmt.Sprintf("0x%08x: 签名运算失败", uint32(SDR_SIGNERR)) case SDR_VERIFYERR: return fmt.Sprintf("0x%08x: 验证签名失败", uint32(SDR_VERIFYERR)) case SDR_SYMOPERR: return fmt.Sprintf("0x%08x: 对称算法运算失败", uint32(SDR_SYMOPERR)) case SDR_STEPERR: return fmt.Sprintf("0x%08x: 多步运算步骤错误", uint32(SDR_STEPERR)) case SDR_FILESIZEERR: return fmt.Sprintf("0x%08x: 文件长度超出限制", uint32(SDR_FILESIZEERR)) case SDR_FILENOEXIST: return fmt.Sprintf("0x%08x: 指定的文件不存在", uint32(SDR_FILENOEXIST)) case SDR_FILEOFSERR: return fmt.Sprintf("0x%08x: 文件起始位置错误", uint32(SDR_FILEOFSERR)) case SDR_KEYTYPEERR: return fmt.Sprintf("0x%08x: 密钥类型错误", uint32(SDR_KEYTYPEERR)) case SDR_KEYERR: return fmt.Sprintf("0x%08x: 密钥错误", uint32(SDR_KEYERR)) case SDR_ENCDATAERR: return fmt.Sprintf("0x%08x: ECC加密数据错误", uint32(SDR_ENCDATAERR)) case SDR_RANDERR: return fmt.Sprintf("0x%08x: 随机数产生失败", uint32(SDR_RANDERR)) case SDR_PRKRERR: return fmt.Sprintf("0x%08x: 私钥使用权限获取失败", uint32(SDR_PRKRERR)) case SDR_MACERR: return fmt.Sprintf("0x%08x: MAC运算失败", uint32(SDR_MACERR)) case SDR_FILEEXISTS: return fmt.Sprintf("0x%08x: 指定文件已存在", uint32(SDR_FILEEXISTS)) case SDR_FILEWERR: return fmt.Sprintf("0x%08x: 文件写入失败", uint32(SDR_FILEWERR)) case SDR_NOBUFFER: return fmt.Sprintf("0x%08x: 存储空间不足", uint32(SDR_NOBUFFER)) case SDR_INARGERR: return fmt.Sprintf("0x%08x: 输入参数错误", uint32(SDR_INARGERR)) case SDR_OUTARGERR: return fmt.Sprintf("0x%08x: 输出参数错误", uint32(SDR_OUTARGERR)) default: return "未知错误" } }