Skip to content

Commit c83a771

Browse files
authored
Update asn1 to 0.24.0 (#14497)
* Update `asn1` to 0.24.0 Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com> * Specify error types for Asn1Writable Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com> * Add tests for missing coverage Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com> --------- Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
1 parent 036bfa1 commit c83a771

8 files changed

Lines changed: 118 additions & 125 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rust-version = "1.83.0"
2121
license = "Apache-2.0 OR BSD-3-Clause"
2222

2323
[workspace.dependencies]
24-
asn1 = { version = "0.23.1", default-features = false }
24+
asn1 = { version = "0.24.0", default-features = false }
2525
base64 = "0.22"
2626
cc = "1.2.57"
2727
cfg-if = "1"

src/rust/cryptography-x509-verification/src/policy/extension.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,10 @@ mod tests {
707707
oid: ObjectIdentifier,
708708
critical: bool,
709709
ext: &T,
710-
) -> Vec<u8> {
710+
) -> Vec<u8>
711+
where
712+
<T as SimpleAsn1Writable>::Error: std::fmt::Debug,
713+
{
711714
let ext_value = asn1::write_single(ext).unwrap();
712715
let ext = Extension {
713716
extn_id: oid,

src/rust/cryptography-x509/src/common.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ impl<'a> asn1::Asn1Readable<'a> for RawTlv<'a> {
256256
}
257257
}
258258
impl asn1::Asn1Writable for RawTlv<'_> {
259+
type Error = asn1::WriteError;
259260
fn write(&self, w: &mut asn1::Writer<'_>) -> asn1::WriteResult {
260261
w.write_tlv(self.tag, Some(self.value.len()), move |dest| {
261262
dest.push_slice(self.value)
@@ -315,9 +316,12 @@ impl<'a, T: asn1::SimpleAsn1Readable<'a>, U> asn1::SimpleAsn1Readable<'a>
315316
}
316317
}
317318

318-
impl<T: asn1::SimpleAsn1Writable, U: asn1::SimpleAsn1Writable> asn1::SimpleAsn1Writable
319-
for Asn1ReadableOrWritable<T, U>
319+
impl<
320+
T: asn1::SimpleAsn1Writable<Error = asn1::WriteError>,
321+
U: asn1::SimpleAsn1Writable<Error = asn1::WriteError>,
322+
> asn1::SimpleAsn1Writable for Asn1ReadableOrWritable<T, U>
320323
{
324+
type Error = asn1::WriteError;
321325
const TAG: asn1::Tag = U::TAG;
322326
fn write_data(&self, w: &mut asn1::WriteBuf) -> asn1::WriteResult {
323327
match self {
@@ -655,6 +659,7 @@ impl<'a> asn1::SimpleAsn1Readable<'a> for UnvalidatedVisibleString<'a> {
655659
}
656660

657661
impl asn1::SimpleAsn1Writable for UnvalidatedVisibleString<'_> {
662+
type Error = asn1::WriteError;
658663
const TAG: asn1::Tag = asn1::VisibleString::TAG;
659664
fn write_data(&self, _: &mut asn1::WriteBuf) -> asn1::WriteResult {
660665
unimplemented!();
@@ -675,6 +680,7 @@ impl<'a> Utf8StoredBMPString<'a> {
675680
}
676681

677682
impl asn1::SimpleAsn1Writable for Utf8StoredBMPString<'_> {
683+
type Error = asn1::WriteError;
678684
const TAG: asn1::Tag = asn1::BMPString::TAG;
679685
fn write_data(&self, writer: &mut asn1::WriteBuf) -> asn1::WriteResult {
680686
for ch in self.0.encode_utf16() {
@@ -723,7 +729,8 @@ impl<'a, T: asn1::Asn1Readable<'a>> asn1::Asn1Readable<'a> for WithTlv<'a, T> {
723729
}
724730

725731
impl<T: asn1::Asn1Writable> asn1::Asn1Writable for WithTlv<'_, T> {
726-
fn write(&self, w: &mut asn1::Writer<'_>) -> asn1::WriteResult<()> {
732+
type Error = T::Error;
733+
fn write(&self, w: &mut asn1::Writer<'_>) -> Result<(), T::Error> {
727734
self.value.write(w)
728735
}
729736

src/rust/cryptography-x509/src/name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl<'a> asn1::SimpleAsn1Readable<'a> for UnvalidatedIA5String<'a> {
3636
}
3737

3838
impl asn1::SimpleAsn1Writable for UnvalidatedIA5String<'_> {
39+
type Error = asn1::WriteError;
3940
const TAG: asn1::Tag = asn1::IA5String::TAG;
4041
fn write_data(&self, dest: &mut asn1::WriteBuf) -> asn1::WriteResult {
4142
dest.push_slice(self.0.as_bytes())

src/rust/src/declarative_asn1/asn1.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ pub(crate) fn encode_der<'p>(
1515
) -> pyo3::PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
1616
let class = value.get_type();
1717

18-
// TODO error messages are lost since asn1::WriteError does not allow
19-
// specifying error messages
2018
let annotated_type = asn1_types::python_class_to_annotated(py, &class)?;
2119
let object = asn1_types::AnnotatedTypeObject {
2220
annotated_type: annotated_type.get(),
2321
value: value.clone(),
2422
};
25-
let encoded_bytes = asn1::write(|writer| object.write(writer))
26-
.map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?;
27-
23+
let encoded_bytes = asn1::write(|writer| object.write(writer))?;
2824
Ok(pyo3::types::PyBytes::new(py, &encoded_bytes))
2925
}
3026

@@ -34,9 +30,8 @@ pub(crate) fn decode_der<'p>(
3430
class: &pyo3::Bound<'p, pyo3::types::PyType>,
3531
value: &'p [u8],
3632
) -> pyo3::PyResult<pyo3::Bound<'p, pyo3::PyAny>> {
37-
asn1::parse(value, |parser| {
33+
Ok(asn1::parse(value, |parser| {
3834
let annotated_type = asn1_types::python_class_to_annotated(py, class)?;
3935
decode_annotated_type(py, parser, annotated_type.get())
40-
})
41-
.map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))
36+
})?)
4237
}

0 commit comments

Comments
 (0)