-
-
Notifications
You must be signed in to change notification settings - Fork 3k
switch generic asn.1 der reader/writer to Io.Reader/Writer #25409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
cc @jedisct1 |
There was a problem hiding this 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.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/std/crypto/codecs/asn1.zig
Outdated
}; | ||
|
||
pub const DecodeError = error{ InvalidLength, EndOfStream }; | ||
pub const DecodeError = error{InvalidLength} || std.Io.Reader.Error; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
33eac1b
to
946ed0d
Compare
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 |
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