mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibCrypto: Allow the user to override the DER read kind and class
This is useful for parsing non-universal types.
This commit is contained in:
parent
581f9ff6bb
commit
65de2d236d
1 changed files with 36 additions and 2 deletions
|
@ -64,8 +64,42 @@ public:
|
||||||
ValueType value;
|
ValueType value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Optional<DecodeError> drop()
|
||||||
|
{
|
||||||
|
if (m_stack.is_empty())
|
||||||
|
return DecodeError::NoInput;
|
||||||
|
|
||||||
|
if (eof())
|
||||||
|
return DecodeError::EndOfStream;
|
||||||
|
|
||||||
|
auto previous_position = m_stack;
|
||||||
|
|
||||||
|
auto tag_or_error = peek();
|
||||||
|
if (tag_or_error.is_error()) {
|
||||||
|
m_stack = move(previous_position);
|
||||||
|
return tag_or_error.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto length_or_error = read_length();
|
||||||
|
if (length_or_error.is_error()) {
|
||||||
|
m_stack = move(previous_position);
|
||||||
|
return length_or_error.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto length = length_or_error.value();
|
||||||
|
|
||||||
|
auto bytes_result = read_bytes(length);
|
||||||
|
if (bytes_result.is_error()) {
|
||||||
|
m_stack = move(previous_position);
|
||||||
|
return bytes_result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_current_tag.clear();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ValueType>
|
template<typename ValueType>
|
||||||
Result<ValueType, DecodeError> read()
|
Result<ValueType, DecodeError> read(Optional<Class> class_override = {}, Optional<Kind> kind_override = {})
|
||||||
{
|
{
|
||||||
if (m_stack.is_empty())
|
if (m_stack.is_empty())
|
||||||
return DecodeError::NoInput;
|
return DecodeError::NoInput;
|
||||||
|
@ -90,7 +124,7 @@ public:
|
||||||
auto tag = tag_or_error.value();
|
auto tag = tag_or_error.value();
|
||||||
auto length = length_or_error.value();
|
auto length = length_or_error.value();
|
||||||
|
|
||||||
auto value_or_error = read_value<ValueType>(tag.class_, tag.kind, length);
|
auto value_or_error = read_value<ValueType>(class_override.value_or(tag.class_), kind_override.value_or(tag.kind), length);
|
||||||
if (value_or_error.is_error()) {
|
if (value_or_error.is_error()) {
|
||||||
m_stack = move(previous_position);
|
m_stack = move(previous_position);
|
||||||
return value_or_error.error();
|
return value_or_error.error();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue