Skip to content

Commit 809ba21

Browse files
authored
Batch 1: Add data_length implementations (#553)
- Add data_length to BitString<'_> - Add data_length to OwnedBitString - Add data_length to BigUint<'_> - Add data_length to OwnedBigUint - Add data_length to BigInt<'_> - Add data_length to OwnedBigInt - Add data_length to Enumerated
1 parent 1853d8e commit 809ba21

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/types.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,10 @@ impl SimpleAsn1Writable for BigUint<'_> {
776776
fn write_data(&self, dest: &mut WriteBuf) -> WriteResult {
777777
dest.push_slice(self.as_bytes())
778778
}
779+
780+
fn data_length(&self) -> Option<usize> {
781+
Some(self.as_bytes().len())
782+
}
779783
}
780784

781785
/// Arbitrary sized unsigned integer which owns its data. Contents may be
@@ -814,6 +818,10 @@ impl SimpleAsn1Writable for OwnedBigUint {
814818
fn write_data(&self, dest: &mut WriteBuf) -> WriteResult {
815819
dest.push_slice(self.as_bytes())
816820
}
821+
822+
fn data_length(&self) -> Option<usize> {
823+
Some(self.as_bytes().len())
824+
}
817825
}
818826

819827
/// Arbitrary sized signed integer. Contents may be accessed as `&[u8]` of
@@ -858,6 +866,10 @@ impl SimpleAsn1Writable for BigInt<'_> {
858866
fn write_data(&self, dest: &mut WriteBuf) -> WriteResult {
859867
dest.push_slice(self.as_bytes())
860868
}
869+
870+
fn data_length(&self) -> Option<usize> {
871+
Some(self.as_bytes().len())
872+
}
861873
}
862874

863875
/// Arbitrary sized signed integer which owns its contents. Contents may be
@@ -900,6 +912,10 @@ impl SimpleAsn1Writable for OwnedBigInt {
900912
fn write_data(&self, dest: &mut WriteBuf) -> WriteResult {
901913
dest.push_slice(self.as_bytes())
902914
}
915+
916+
fn data_length(&self) -> Option<usize> {
917+
Some(self.as_bytes().len())
918+
}
903919
}
904920

905921
impl<'a> SimpleAsn1Readable<'a> for ObjectIdentifier {
@@ -934,6 +950,10 @@ impl SimpleAsn1Writable for BitString<'_> {
934950
dest.push_byte(self.padding_bits())?;
935951
dest.push_slice(self.as_bytes())
936952
}
953+
954+
fn data_length(&self) -> Option<usize> {
955+
Some(1 + self.as_bytes().len())
956+
}
937957
}
938958
impl<'a> SimpleAsn1Readable<'a> for OwnedBitString {
939959
const TAG: Tag = Tag::primitive(0x03);
@@ -947,6 +967,10 @@ impl SimpleAsn1Writable for OwnedBitString {
947967
fn write_data(&self, dest: &mut WriteBuf) -> WriteResult {
948968
self.as_bitstring().write_data(dest)
949969
}
970+
971+
fn data_length(&self) -> Option<usize> {
972+
self.as_bitstring().data_length()
973+
}
950974
}
951975

952976
fn read_byte(data: &mut &[u8]) -> ParseResult<u8> {
@@ -1348,6 +1372,10 @@ impl SimpleAsn1Writable for Enumerated {
13481372
fn write_data(&self, dest: &mut WriteBuf) -> WriteResult {
13491373
u32::write_data(&self.value(), dest)
13501374
}
1375+
1376+
fn data_length(&self) -> Option<usize> {
1377+
self.value().data_length()
1378+
}
13511379
}
13521380

13531381
impl<'a, T: Asn1Readable<'a>> Asn1Readable<'a> for Option<T> {

0 commit comments

Comments
 (0)