Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lifetime errors in asn1.rs with gil-refs disabled #10778

Merged
merged 4 commits into from
Apr 13, 2024

Conversation

facutuesca
Copy link
Contributor

Part of #10676

This should be merged after the keepalive PR is merged

Fixes all of the lifetime errors in asn1.rs, changing a return type of py_uint_to_big_endian_bytes from &'p [u8] to PyBackedBytes.
It uses the new keepalive in the places where the PyBackedBytes object is borrowed for longer than its lifetime.

cc @alex @reaperhulk

Comment on lines 23 to 24
// SAFETY: `PyBackedBytes`'s data is on the heap, so as long as it's not mutated, the
// slice returned by `deref` remains valid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes are immutable in python, so the comment here should say that, not that it's fine as long as it's not mutated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -52,9 +52,13 @@ pub(crate) fn encode_authority_key_identifier<'a>(
} else {
None
};
let ka = cryptography_keepalive::KeepAlive::new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed, you just need to change the scope of the serial_bytes local to be function, rather than block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, fixed!

@alex
Copy link
Member

alex commented Apr 12, 2024

Should be good to rebase

@@ -52,10 +53,11 @@ pub(crate) fn encode_authority_key_identifier<'a>(
} else {
None
};
let serial_bytes: PyBackedBytes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let serial_bytes: PyBackedBytes;
let serial_bytes;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -188,7 +189,8 @@ fn create_ocsp_request(
(issuer_name_hash, issuer_key_hash, py_serial, py_hash) = builder
.getattr(pyo3::intern!(py, "_request_hash"))?
.extract()?;
let serial_number = asn1::BigInt::new(py_uint_to_big_endian_bytes(py, py_serial)?).unwrap();
let serial_number_bytes = ka.add(py_uint_to_big_endian_bytes(py, py_serial)?);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a ka is needed here. Can just do the scoping trick.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed

@facutuesca facutuesca marked this pull request as ready for review April 13, 2024 19:41
src/rust/src/x509/ocsp_req.rs Outdated Show resolved Hide resolved
@alex alex enabled auto-merge (squash) April 13, 2024 19:45
@alex alex merged commit bdb2d8b into pyca:main Apr 13, 2024
58 checks passed
@facutuesca facutuesca deleted the asn1-lifetime-pyo3 branch April 13, 2024 19:51
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.

2 participants