package application import ( "math/big" "strings" "udeServer/internal/apierr" "github.com/google/uuid" "github.com/mattheath/base62" "github.com/segmentio/ksuid" ) // 应用凭证签名算法,与 audit 包保持同一算法字面量(sdf 同源)。 const HmacAlgo = "HmacSM3" // operatorName 无用户体系时的操作人占位,与日志归档/恢复一致。 const operatorName = "admin" // GenerateApiKey 生成对外公钥(KSUID,27 位可排序 ID)。 func GenerateApiKey() string { return ksuid.New().String() } // GenerateApiSecret 生成原始密钥(uuid 16 字节转 base62,22 字符)。 func GenerateApiSecret() string { u := uuid.New() bi := new(big.Int).SetBytes(u[:]) return base62.EncodeBigInt(bi) } // maskSensitive 掩码展示:前 4 后 4 明文,中间打星;长度不大于 8 时原样返回。 func maskSensitive(value string) string { if len(value) <= 8 { return value } return value[:4] + strings.Repeat("*", len(value)-8) + value[len(value)-4:] } // normalizePage 页码/页大小兜底:1/10 起,上限 100。 func normalizePage(page, pageSize int64) (int64, int64) { if page < 1 { page = 1 } if pageSize < 10 { pageSize = 10 } if pageSize > 100 { pageSize = 100 } return page, pageSize } // checkId 主键合法性,与 logic 包同名 helper 行为一致。 func checkId(id int64) error { if id <= 0 { return apierr.BadRequest("id must be greater than 0") } return nil }