Skip to content

fix: cache parsed PEM private key to avoid re-parsing per request#124

Closed
Bortlesboat wants to merge 1 commit intocoinbase:masterfrom
Bortlesboat:fix/cache-pem-key-121
Closed

fix: cache parsed PEM private key to avoid re-parsing per request#124
Bortlesboat wants to merge 1 commit intocoinbase:masterfrom
Bortlesboat:fix/cache-pem-key-121

Conversation

@Bortlesboat
Copy link
Copy Markdown

Summary

  • Parse the PEM private key once in APIBase.__init__() instead of on every request
  • Pass the cached key through build_rest_jwt() and build_ws_jwt() via an optional private_key parameter
  • Backward-compatible: callers that don't pass private_key get the original parsing behavior
  • Avoids redundant load_pem_private_key() ASN.1/DER parsing on every HTTP request

Fixes #121

Parse the PEM private key once during client initialization and reuse it
for subsequent JWT generation. Previously, load_pem_private_key() was
called on every REST and WebSocket request, performing redundant ASN.1/DER
parsing.

The private_key parameter is optional and backward-compatible — callers
that don't pass it still get the original parsing behavior.

Fixes #121
@cb-heimdall
Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@cb-heimdall
Copy link
Copy Markdown

Review Error for JTCombs95-commits @ 2026-03-06 21:19:28 UTC
User failed mfa authentication, see go/mfa-help

@Bortlesboat
Copy link
Copy Markdown
Author

Quick follow-up from my side: I’m treating review-required PRs as top priority this week. If you want any specific changes, rebase, or split, I can turn them around quickly.

@Bortlesboat
Copy link
Copy Markdown
Author

Reopened this fix from a live fork in #128 after this PR was closed when the original head repo disappeared. The code path still reproduces cleanly on current \master\, so the replacement PR carries the same optimization plus focused regression coverage and fresh review context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

PEM private key is re-parsed from scratch on every REST request

3 participants