Skip to content

Conversation

benburkert
Copy link

Followup to #25036 to finish moving the asn.1 der encoder & decoder to the Io.Reader/Io.Writer interfaces. It looks like the tests for those types were not being imported, so CI wasn't catching these compile errors.

Fixes #25408

@alexrp
Copy link
Member

alexrp commented Oct 1, 2025

cc @jedisct1

@jedisct1 jedisct1 self-requested a review October 1, 2025 13:22
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. However, I think the APIs that are being touched here need to be reexamined more carefully. Furthermore, if ArrayListReverse is to continue to exist it needs unit test coverage for this new writer functionality.

Comment on lines 95 to 99
var buffer: Io.Writer.Allocating = .init(self.allocator);
defer buffer.deinit();
try buffer.writer.writeSplatAll(@constCast(data), splat);
self.prependSlice(buffer.written()) catch return error.WriteFailed;
return Io.Writer.countSplat(data, splat);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to double-allocate here. Increase capacity then copy the bytes into place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, I pushed a commit that does that instead.

};

pub const DecodeError = error{ InvalidLength, EndOfStream };
pub const DecodeError = error{InvalidLength} || std.Io.Reader.Error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect error set - the fact that a reader is being used is an internal implementation detail that should not leak out here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I made the errors set explicit (error{ InvalidLength, EndOfStream, ReadFailed }), is that preferable?

/// Warning: This writer writes backwards. `fn print` will NOT work as expected.
pub fn writer(self: *Encoder) ArrayListReverse.Writer {
return self.buffer.writer();
pub fn writer(self: *Encoder) *std.Io.Writer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not your fault, but based on the doc comment for this function, it suggests this function should not exist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making it private? I can incorporate that into this PR if you'd like: e7097f8

data: []u8,
capacity: usize,
allocator: Allocator,
writer: std.Io.Writer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's unclear to me that this should be how it works

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean that the writer should not belong to the ArrayListReverse, or is it that an Io.Writer is not the right API here?

@benburkert
Copy link
Author

thanks for the feedback @andrewrk, I tried to address what i could and left some additional questions. I didn't add full unit tests for the ArrayListReverse writer because making that writer private would really shrink the exposed functionality, so once that's settled i'll add unit tests. Also, if there's appetite for large changes to I'd love to propose some ideas for improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crypto.codecs.asn1.der.{Encoder,Decoder} compile errors
4 participants