Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Asn1Decode.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ library Asn1Decode {
*/
function bitstring(bytes memory der, Asn1Ptr ptr) internal pure returns (Asn1Ptr) {
if (der[ptr.header()] != 0x03) revert InvalidAsn1Type();
if (ptr.length() == 0) revert InvalidAsn1Length();
// Only 00 padded bitstr can be converted to bytestr!
if (der[ptr.content()] != 0x00) revert InvalidAsn1Value();
return LibAsn1Ptr.toAsn1Ptr(ptr.header(), ptr.content() + 1, ptr.length() - 1);
Expand Down
5 changes: 5 additions & 0 deletions test/Asn1Decode.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ contract Asn1DecodeTest is Test {
h.bitstringContent(hex"0401ff");
}

function test_bitstring_empty_reverts() public {
vm.expectRevert(Asn1Decode.InvalidAsn1Length.selector);
h.bitstringContent(hex"0300");
}

function test_bitstring_nonZeroPadded_reverts() public {
vm.expectRevert(Asn1Decode.InvalidAsn1Value.selector);
h.bitstringContent(hex"03020100"); // pad byte is 0x01, not 0x00
Expand Down
Loading