Skip to content

Commit 5277fcf

Browse files
authored
der: remove Reader::read_value (#1887)
This was added in #1877 but the real value of that PR was the automatic `read_nested` on `DecodeValue` impls. `Reader::read_value` isn't actually necessary for that at all. It may be useful in the future if we introduce a BER reader that can handle decoding constructed e.g. strings from indefinite length encoding, but since we don't actually have anything like that yet, removing this avoids some unnecessary duplication and API surface for the `Reader`.
1 parent 0f4ce04 commit 5277fcf

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

der/src/asn1/internal_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ macro_rules! impl_custom_class {
151151
return Err(header.tag.non_canonical_error().into());
152152
}
153153

154-
// read_value checks if header matches decoded length
155-
let value = reader.read_value(header, |reader| {
154+
// read_nested checks if header matches decoded length
155+
let value = reader.read_nested(header.length, |reader| {
156156
// Decode inner IMPLICIT value
157157
T::decode_value(reader, header)
158158
})?;
@@ -192,7 +192,7 @@ macro_rules! impl_custom_class {
192192
Tag::$class_enum_name { number, .. } => Ok(Self {
193193
tag_number: number,
194194
tag_mode: TagMode::default(),
195-
value: reader.read_value(header, |reader| {
195+
value: reader.read_nested(header.length, |reader| {
196196
// Decode inner tag-length-value of EXPLICIT
197197
T::decode(reader)
198198
})?,

der/src/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
fn decode<R: Reader<'a>>(reader: &mut R) -> Result<T, <T as DecodeValue<'a>>::Error> {
6969
let header = Header::decode(reader)?;
7070
header.tag.assert_eq(T::TAG)?;
71-
reader.read_value(header, |r| T::decode_value(r, header))
71+
reader.read_nested(header.length, |r| T::decode_value(r, header))
7272
}
7373
}
7474

der/src/reader.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ pub trait Reader<'r>: Clone {
3232
E: From<Error>,
3333
F: FnOnce(&mut Self) -> Result<T, E>;
3434

35-
/// Read a value (i.e. the "V" part of a "TLV" field) using the provided header.
36-
///
37-
/// This calls the provided function `f` with a nested reader created using
38-
/// [`Reader::read_nested`].
39-
fn read_value<T, F, E>(&mut self, header: Header, f: F) -> Result<T, E>
40-
where
41-
E: From<Error>,
42-
F: FnOnce(&mut Self) -> Result<T, E>,
43-
{
44-
self.read_nested(header.length, f)
45-
}
46-
4735
/// Attempt to read data borrowed directly from the input as a slice,
4836
/// updating the internal cursor position.
4937
///
@@ -204,7 +192,7 @@ pub trait Reader<'r>: Clone {
204192
{
205193
let header = Header::decode(self)?;
206194
header.tag.assert_eq(Tag::Sequence)?;
207-
self.read_value(header, f)
195+
self.read_nested(header.length, f)
208196
}
209197

210198
/// Obtain a slice of bytes containing a complete TLV production suitable for parsing later.

0 commit comments

Comments
 (0)