Explorar o código

LibCrypto: Add ability to rewrite current tag kind

This is used for IMPLICIT tags where the expected kind is overriden
by the encoding instructions.
stelar7 %!s(int64=2) %!d(string=hai) anos
pai
achega
b1d80b35af
Modificáronse 1 ficheiros con 19 adicións e 0 borrados
  1. 19 0
      Userland/Libraries/LibCrypto/ASN1/DER.h

+ 19 - 0
Userland/Libraries/LibCrypto/ASN1/DER.h

@@ -58,6 +58,25 @@ public:
         ValueType value;
     };
 
+    ErrorOr<void> 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<void> drop()
     {
         if (m_stack.is_empty())