Skip to content

Commit 8b55f65

Browse files
Bump cryptography-x509 from 44.0.3 to 45.0.2 in the actions group across 1 directory (#149)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alexis <alexis.challande@trailofbits.com>
1 parent 4fecc6f commit 8b55f65

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ members = [
77
]
88

99
[workspace.dependencies]
10-
asn1 = "0.20"
11-
cryptography-x509 = { git = "https://github.com/pyca/cryptography.git", tag = "44.0.3" }
10+
asn1 = "0.21.3"
11+
cryptography-x509 = { git = "https://github.com/pyca/cryptography.git", tag = "45.0.2" }
1212
hex = "0.4"
1313

1414
[workspace.package]

rust/src/name.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use asn1::SimpleAsn1Readable;
12
use pyo3::types::IntoPyDict;
23
use pyo3::types::{PyAnyMethods, PyListMethods};
34

@@ -12,23 +13,27 @@ fn parse_name_attribute<'p>(
1213
)
1314
})?;
1415
let py_tag = crate::util::ASN1_TYPE_TO_ENUM.get(py)?.get_item(tag_val)?;
15-
let py_data = match attribute.value.tag().as_u8() {
16-
// BitString tag value
17-
Some(3) => pyo3::types::PyBytes::new(py, attribute.value.data()).into_any(),
18-
// BMPString tag value
19-
Some(30) => {
20-
let py_bytes = pyo3::types::PyBytes::new(py, attribute.value.data());
21-
py_bytes.call_method1(pyo3::intern!(py, "decode"), ("utf_16_be",))?
16+
let py_data = match &attribute.value {
17+
cryptography_x509::common::AttributeValue::AnyString(s) => {
18+
if s.tag() == asn1::BitString::TAG {
19+
pyo3::types::PyBytes::new(py, s.data()).into_any()
20+
} else {
21+
let parsed = std::str::from_utf8(s.data()).map_err(|_| {
22+
pyo3::exceptions::PyValueError::new_err("Parsing error in ASN1")
23+
})?;
24+
pyo3::types::PyString::new(py, parsed).into_any()
25+
}
26+
}
27+
cryptography_x509::common::AttributeValue::PrintableString(printable_string) => {
28+
pyo3::types::PyString::new(py, printable_string.as_str()).into_any()
2229
}
23-
// UniversalString
24-
Some(28) => {
25-
let py_bytes = pyo3::types::PyBytes::new(py, attribute.value.data());
30+
cryptography_x509::common::AttributeValue::UniversalString(universal_string) => {
31+
let py_bytes = pyo3::types::PyBytes::new(py, universal_string.as_utf32_be_bytes());
2632
py_bytes.call_method1(pyo3::intern!(py, "decode"), ("utf_32_be",))?
2733
}
28-
_ => {
29-
let parsed = std::str::from_utf8(attribute.value.data())
30-
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Parsing error in ASN1"))?;
31-
pyo3::types::PyString::new(py, parsed).into_any()
34+
cryptography_x509::common::AttributeValue::BmpString(bmp_string) => {
35+
let py_bytes = pyo3::types::PyBytes::new(py, bmp_string.as_utf16_be_bytes());
36+
py_bytes.call_method1(pyo3::intern!(py, "decode"), ("utf_16_be",))?
3237
}
3338
};
3439
let kwargs = [(pyo3::intern!(py, "_validate"), false)].into_py_dict(py)?;

0 commit comments

Comments
 (0)