Skip to content

Commit ec1f480

Browse files
authored
Batch 4: Add data_length implementations (#556)
- Add data_length to Sequence<'_> (returns data slice length) - Add data_length to SequenceOfWriter<'_, T, V> (sums encoded_length of all elements) - Add data_length to SetOfWriter<'_, T, V> (sums encoded_length of all elements)
1 parent c9a1956 commit ec1f480

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/types.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,10 @@ impl SimpleAsn1Writable for Sequence<'_> {
15391539
fn write_data(&self, data: &mut WriteBuf) -> WriteResult {
15401540
data.push_slice(self.data)
15411541
}
1542+
1543+
fn data_length(&self) -> Option<usize> {
1544+
Some(self.data.len())
1545+
}
15421546
}
15431547

15441548
/// Writes an ASN.1 `SEQUENCE` using a callback that writes the inner
@@ -1733,6 +1737,11 @@ impl<T: Asn1Writable, V: Borrow<[T]>> SimpleAsn1Writable for SequenceOfWriter<'_
17331737

17341738
Ok(())
17351739
}
1740+
1741+
fn data_length(&self) -> Option<usize> {
1742+
let vals = self.vals.borrow();
1743+
vals.iter().map(|v| v.encoded_length()).sum()
1744+
}
17361745
}
17371746

17381747
/// Represents an ASN.1 `SET OF`. This is an `Iterator` over values that
@@ -1897,6 +1906,11 @@ impl<T: Asn1Writable, V: Borrow<[T]>> SimpleAsn1Writable for SetOfWriter<'_, T,
18971906

18981907
Ok(())
18991908
}
1909+
1910+
fn data_length(&self) -> Option<usize> {
1911+
let vals = self.vals.borrow();
1912+
vals.iter().map(|v| v.encoded_length()).sum()
1913+
}
19001914
}
19011915

19021916
/// `Implicit` is a type which wraps another ASN.1 type, indicating that the tag is an ASN.1

0 commit comments

Comments
 (0)