← Back to Pull requests

Implement `hashlib` #988

Closed
unknown closed this pull request without merging on Oct 09, 2026 13:07 UTC
View on GitHub
unknown unknown commented on Oct 07, 2026 12:06 UTC
Author

<!-- This is an auto-generated description by cubic. -->

Summary by cubic


Implements the full hashlib module: every guaranteed algorithm (md5, sha1, sha2, sha3, shake_128/256, blake2b/blake2s), plus new(), pbkdf2_hmac(), and the algorithms_ sets. Hash objects are CPython-compatible in types, attributes, reprs, and error messages, and a hash mid-stream survives a session dump.

  • SHA-1 and SHA-2 are backed by the RustCrypto sha1/sha2 crates (0.11) for hardware-accelerated compression; the other cores are hand-written, and blake2b/blake2s expose the full BLAKE2 parameter block and size constants.

  • SHA-1/SHA-2 state is persisted through the crate's SerializableState, so a crate upgrade that changes that layout is a DUMP_VERSION bump; a test snapshots the serialized state so the change fails visibly. The fixed digest lives on the stack so an HMAC round allocates nothing, and update() lifts the state out of the heap instead of cloning it.

  • SHAKE output lengths and PBKDF2 iteration counts are bounded by the resource tracker; hexdigest() also counts the live digest it keeps while encoding, and PBKDF2 absorbs the salt into the keyed HMAC state once. SHAKE digest()/hexdigest() length errors follow _sha3's messages, through a FromValue for u64 with unsigned_long semantics.

  • Hashing polls the deadline once per 64 KiB of input, so a large update() can be interrupted.

  • Adds type stubs with new() overloaded by name, plus a limitations docs page; file_digest() and scrypt() remain unimplemented.

  • Allows style = def with varargs in FromArgs, needed by hashlib.new(name, args, **kwargs), and fixes typed-argument fallback errors to name 'NoneType' instead of 'None'.

  • Error-path tests accept either wording where CPython's messages depend on the C long width or the OpenSSL build, including the BLAKE2 leaf_size and PBKDF2 dklen bounds; the limitations page records the difference.
  • <sup>Written for commit df2181b4469d18247f01ef1cdb6b363ba458232a. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/988?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/pydantic/monty/988?returnTo=https%3A%2F%2Fgithub.com%2Fpydantic%2Fmonty%2Fpull%2F988&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 396 lines (+297 / -99) across 4 files Reviewer: rewitt94 Review duration: 2941m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 396 lines diff across 4 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.358
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #988"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.2% (MEDIUM) · Higher = larger blast radius
    48.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19% · Safe to merge
    19%
    Repository