mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:37:35 +00:00
LibCrypto: Implement custom BitStringView for ASN.1 decoder
The ASN.1 decoder was originally using AK::BitmapView for decoded BitStrings, however the specification requires that the bits are stored in a byte from the most significant to the least significant. Storing three bits '110' would result in a byte '1100 0000', i.e. 0xC0. However, AK::BitmapView expects the bits to be stored at the bottom like '0000 0110', i.e. 0x06. For the current uses the data was always a multiple of eight bits, resulting in complete bytes, which could directly be interpreted correctly. For the implementation of the key usage extension of certificates the correct implementation of the BitString is required.
This commit is contained in:
parent
b16b61f6bc
commit
a6e465fba2
3 changed files with 33 additions and 7 deletions
|
@ -169,7 +169,7 @@ Result<StringView, DecodeError> Decoder::decode_printable_string(ReadonlyBytes d
|
|||
return StringView { data };
|
||||
}
|
||||
|
||||
Result<const BitmapView, DecodeError> Decoder::decode_bit_string(ReadonlyBytes data)
|
||||
Result<BitStringView, DecodeError> Decoder::decode_bit_string(ReadonlyBytes data)
|
||||
{
|
||||
if (data.size() < 1)
|
||||
return DecodeError::InvalidInputFormat;
|
||||
|
@ -180,7 +180,7 @@ Result<const BitmapView, DecodeError> Decoder::decode_bit_string(ReadonlyBytes d
|
|||
if (unused_bits > total_size_in_bits)
|
||||
return DecodeError::Overflow;
|
||||
|
||||
return BitmapView { const_cast<u8*>(data.offset_pointer(1)), total_size_in_bits - unused_bits };
|
||||
return BitStringView { data.slice(1), unused_bits };
|
||||
}
|
||||
|
||||
Result<Tag, DecodeError> Decoder::peek()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue