Skip to content

Commit 2e18af4

Browse files
authored
Bump rust-asn1 version (#13098)
1 parent c1cada5 commit 2e18af4

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

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.74.0"
2121
license = "Apache-2.0 OR BSD-3-Clause"
2222

2323
[workspace.dependencies]
24-
asn1 = { version = "0.21.3", default-features = false }
24+
asn1 = { version = "0.22.0", default-features = false }
2525
pyo3 = { version = "0.25", features = ["abi3"] }
2626
pyo3-build-config = { version = "0.25" }
2727
openssl = "0.10.73"

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,14 @@ impl<'a> asn1::Asn1Readable<'a> for RawTlv<'a> {
243243
}
244244
impl asn1::Asn1Writable for RawTlv<'_> {
245245
fn write(&self, w: &mut asn1::Writer<'_>) -> asn1::WriteResult {
246-
w.write_tlv(self.tag, move |dest| dest.push_slice(self.value))
246+
w.write_tlv(self.tag, Some(self.value.len()), move |dest| {
247+
dest.push_slice(self.value)
248+
})
249+
}
250+
251+
fn encoded_length(&self) -> Option<usize> {
252+
// TODO: we're missing an API to make this easy.
253+
None
247254
}
248255
}
249256

@@ -304,6 +311,13 @@ impl<T: asn1::SimpleAsn1Writable, U: asn1::SimpleAsn1Writable> asn1::SimpleAsn1W
304311
Asn1ReadableOrWritable::Write(v) => U::write_data(v, w),
305312
}
306313
}
314+
315+
fn data_length(&self) -> Option<usize> {
316+
match self {
317+
Asn1ReadableOrWritable::Read(v) => T::data_length(v),
318+
Asn1ReadableOrWritable::Write(v) => U::data_length(v),
319+
}
320+
}
307321
}
308322

309323
pub trait Asn1Operation {
@@ -579,6 +593,10 @@ impl asn1::SimpleAsn1Writable for UnvalidatedVisibleString<'_> {
579593
fn write_data(&self, _: &mut asn1::WriteBuf) -> asn1::WriteResult {
580594
unimplemented!();
581595
}
596+
597+
fn data_length(&self) -> Option<usize> {
598+
None
599+
}
582600
}
583601

584602
/// A BMPString ASN.1 element, where it is stored as a UTF-8 string in memory.
@@ -598,6 +616,10 @@ impl asn1::SimpleAsn1Writable for Utf8StoredBMPString<'_> {
598616
}
599617
Ok(())
600618
}
619+
620+
fn data_length(&self) -> Option<usize> {
621+
Some(self.0.encode_utf16().count() * 2)
622+
}
601623
}
602624

603625
#[derive(Clone)]
@@ -638,6 +660,10 @@ impl<T: asn1::Asn1Writable> asn1::Asn1Writable for WithTlv<'_, T> {
638660
fn write(&self, w: &mut asn1::Writer<'_>) -> asn1::WriteResult<()> {
639661
self.value.write(w)
640662
}
663+
664+
fn encoded_length(&self) -> Option<usize> {
665+
self.value.encoded_length()
666+
}
641667
}
642668

643669
impl<T: PartialEq> PartialEq for WithTlv<'_, T> {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ impl asn1::SimpleAsn1Writable for UnvalidatedIA5String<'_> {
4040
fn write_data(&self, dest: &mut asn1::WriteBuf) -> asn1::WriteResult {
4141
dest.push_slice(self.0.as_bytes())
4242
}
43+
fn data_length(&self) -> Option<usize> {
44+
Some(self.0.len())
45+
}
4346
}
4447

4548
#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)