Skip to content
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

Fix handling of OctetStrings with NUL bytes #40

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@kgraefe
Copy link
Contributor

commented Jul 10, 2019

This changes the OctetString class to access the C buffer using .raw instead of .value to bypass the NUL termination checks. For that it must handle the data size itself.

I think OctetString.value() should return a bytes() array instead of a string since decoding might fail for some values? (I did not change that since it would break the API and I don't know how you rate API stability in this project.)

FTR, as in #28 I use OctetString for MAC addresses, which may contain NUL bytes.

Fix handling of OctetStrings with NUL bytes
Fixes #28.

Signed-off-by: Konrad Gräfe <konradgraefe@aol.com>

@kgraefe kgraefe force-pushed the kgraefe:fix-octetstrings-with-nul-bytes branch from 3775f70 to 15c9b07 Jul 12, 2019

@kgraefe

This comment has been minimized.

Copy link
Contributor Author

commented Jul 12, 2019

I removed the OctetString.update() function. Writing to self._cvar.value does not do NUL termination checks so we can reuse _MaxSizeVarType.update().

@pief

This comment has been minimized.

Copy link
Owner

commented Jul 13, 2019

Thanks for the PR, looks good to me, I just need to try it out myself yet.

Your argument about OctetString.value() returning bytes() makes sense to me. I mean, so far OctetStrings were more like a not-so-useful proof-of-concept and I do mention at one place or another that the API is not completely stable yet, so I would welcome your change related to this, as long as it works with both Python 2.x and 3.x.

@kgraefe kgraefe force-pushed the kgraefe:fix-octetstrings-with-nul-bytes branch from 8a7324e to 8aca894 Jul 15, 2019

OctetStrings.value(): Return bytes() instead of a string
Signed-off-by: Konrad Gräfe <konradgraefe@aol.com>

@kgraefe kgraefe force-pushed the kgraefe:fix-octetstrings-with-nul-bytes branch from 8aca894 to 3a8392a Jul 15, 2019

@kgraefe

This comment has been minimized.

Copy link
Contributor Author

commented Jul 16, 2019

I pushed that change yesterday to that PR. (I don't know if you get notifications for pushes; no pressure intended.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.