test(entropy,hmac,ed25519): cover fixture invariants#727
Conversation
…/debug invariants entropy: - Pin DOMAIN_ENTROPY_FIXTURE constant (part of every consumer's cache key). - bytes(0) returns empty; fill_bytes(&mut []) is a no-op. - fill_bytes_with_variant matches bytes_with_variant for the same variant. - Clone preserves bytes, label, variant. - Debug includes label/variant but never byte material (hex form check). - Default variant on the fixture handle propagates through bytes() and variant-bound fixtures produce the same material as explicit variant calls on the default fixture. hmac: - Pin DOMAIN_HMAC_SECRET constant. - Clone preserves secret_bytes, label, spec (single + chained clones). - Debug must not contain raw secret bytes (hex form check). - JWK use_ field is exactly "sig" across HS256/HS384/HS512. - JWKS keys array has exactly one entry. ed25519: - Pin DOMAIN_ED25519_KEYPAIR constant. - PKCS#8 / SPKI DER outputs meet minimum length invariants. - PEM outputs have correct BEGIN headers. - public_jwk() exercises every OKP field shape and the x base64url decodes to 32 bytes; private_key_jwk() d decodes to 32 bytes. - public_jwks() cardinality is exactly 1; public_jwks_json() matches public_jwks().to_value(). - Clone preserves private/public DER and label.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive test coverage for the ed25519, entropy, and hmac crates, focusing on domain constant stability, clone semantics, and ensuring Debug implementations do not leak sensitive material. Feedback suggests tightening length assertions for Ed25519 DER outputs to use exact equality and strengthening the Debug leak checks in the entropy tests to include standard byte slice representations, ensuring consistency with the HMAC implementation and the repository's security guidelines.
| let kp = fx.ed25519("svc", Ed25519Spec::new()); | ||
|
|
||
| // PKCS#8 v1 Ed25519 PrivateKeyInfo is fixed length (48 bytes). | ||
| assert!(kp.private_key_pkcs8_der().len() >= 48); |
There was a problem hiding this comment.
Since the comment explicitly states that Ed25519 PKCS#8 v1 is fixed length (48 bytes), this assertion should use equality to provide a stronger invariant check and catch any unexpected structural changes.
| assert!(kp.private_key_pkcs8_der().len() >= 48); | |
| assert_eq!(kp.private_key_pkcs8_der().len(), 48); |
| // PKCS#8 v1 Ed25519 PrivateKeyInfo is fixed length (48 bytes). | ||
| assert!(kp.private_key_pkcs8_der().len() >= 48); | ||
| // SPKI for Ed25519 is fixed length (44 bytes). | ||
| assert!(kp.public_key_spki_der().len() >= 44); |
There was a problem hiding this comment.
|
|
||
| // Debug must not contain the materialized byte stream as contiguous hex. | ||
| let hex = bytes.iter().map(|b| format!("{b:02x}")).collect::<String>(); | ||
| assert!(!dbg.contains(&hex), "debug leaked hex bytes: {dbg}"); |
There was a problem hiding this comment.
The current Debug leak check only verifies the absence of a contiguous hex string. To more thoroughly enforce the security requirement that Debug implementations must never leak material (Repository Style Guide, line 49), it should also check for the standard Debug representation of the byte slice (e.g., [1, 2, 3]). This aligns with the more robust check implemented in hmac_extra_coverage.rs.
assert!(!dbg.contains(&hex), "debug leaked hex bytes: {dbg}");
let bytes_dbg = format!("{bytes:?}");
assert!(!dbg.contains(&bytes_dbg), "debug leaked byte array: {dbg}");References
- Debug implementations must never leak key material. (link)
Summary
Files added/changed
Validation
Non-goals
What this enables next