Function constant_time_starts_with
Source pub fn constant_time_starts_with(haystack: &[u8], prefix: &[u8]) -> bool
Expand description
恒定时间前缀比较(AGENT.md §4.9 时序安全)
逐字节 XOR 累积差异,不因首个不匹配字节提前退出;
haystack 长度不足时仍完成全长比较后返回 false
(长度检查仅依赖输入长度,长度本身非秘密)。
§Arguments
haystack - 被检查的字节串
prefix - 待匹配的前缀(空前缀恒为命中,与 str::starts_with 语义一致)
§Returns
bool - haystack 是否以 prefix 开头