From b1d80b35af1d05e0fff8ce3da76f58dd5b5a4fd0 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Mon, 3 Apr 2023 18:53:29 +0200 Subject: [PATCH] LibCrypto: Add ability to rewrite current tag kind This is used for IMPLICIT tags where the expected kind is overriden by the encoding instructions. --- Userland/Libraries/LibCrypto/ASN1/DER.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Userland/Libraries/LibCrypto/ASN1/DER.h b/Userland/Libraries/LibCrypto/ASN1/DER.h index d4333e5b94..63829c95b2 100644 --- a/Userland/Libraries/LibCrypto/ASN1/DER.h +++ b/Userland/Libraries/LibCrypto/ASN1/DER.h @@ -58,6 +58,25 @@ public: ValueType value; }; + ErrorOr rewrite_tag(Kind kind) + { + if (m_stack.is_empty()) + return Error::from_string_view("Nothing on stack to rewrite"sv); + + if (eof()) + return Error::from_string_view("Stream is empty"sv); + + if (m_current_tag.has_value()) { + m_current_tag->kind = kind; + return {}; + } + + auto tag = TRY(read_tag()); + m_current_tag = tag; + m_current_tag->kind = kind; + return {}; + } + ErrorOr drop() { if (m_stack.is_empty())