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

feat(admissions): implement encoding of admissions extension #11892

Merged
merged 11 commits into from
Nov 7, 2024

Conversation

hoefling
Copy link
Contributor

@hoefling hoefling commented Nov 4, 2024

This is the fifth PR for #11875 which adds encoding of the Admissions extension object. Please review with caution - this is the part I am least confident in, and will be grateful for all improvement suggestions. Please also bear with my Rust coding skills - for this PR, I mostly learned from the existing codebase and PyO3 docs.

@hoefling hoefling changed the title feat: implement encoding of admissions extension feat(admissions): implement encoding of admissions extension Nov 4, 2024
py: pyo3::Python<'_>,
ka_str: &'a cryptography_keepalive::KeepAlive<pyo3::pybacked::PyBackedStr>,
py_naming_authority: &pyo3::Bound<'a, pyo3::PyAny>,
) -> Result<extensions::NamingAuthority<'a>, CryptographyError> {
Copy link
Member

Choose a reason for hiding this comment

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

You can use CryptographyResult<extensions::NamingAuthority<'a>> which is marginally shorter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Duly noted :-) also switched to CryptographyResult for consistency in other introduced functions as well.

py_naming_authority: &pyo3::Bound<'a, pyo3::PyAny>,
) -> Result<extensions::NamingAuthority<'a>, CryptographyError> {
let py_oid = py_naming_authority.getattr(pyo3::intern!(py, "id"))?;
let id = if py_oid.is_truthy()? {
Copy link
Member

Choose a reason for hiding this comment

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

Prefer is_none(), it better expresses what we want, and is also a smidge faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a really great hint, thank you! Indeed using it makes sense in all occurences, and by doing that I even uncovered an error I slipped into the codebase in #11881 - the professionOIDs field is optional, but I missed that. Will amend this in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alex what I forgot to ask: what do you prefer more?

let val = if !py_val.is_none() {
    Some(...)
} else {
    None
};

or

let val = if py_val.is_none() {
    None
} else {
    Some(...)
};

Copy link
Member

Choose a reason for hiding this comment

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

Whichever you prefer, I'm sure we're not consistent

src/rust/src/x509/extensions.rs Outdated Show resolved Hide resolved
src/rust/src/x509/extensions.rs Outdated Show resolved Hide resolved
@hoefling hoefling force-pushed the feature/extension/admissions/encode branch from b403042 to 526e083 Compare November 7, 2024 00:02
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