--- a/src/lib/GenericASN1ContentHandler.h Thu Jul 22 01:06:14 2021 +0200
+++ b/src/lib/GenericASN1ContentHandler.h Thu Jul 22 20:01:03 2021 +0200
@@ -22,6 +22,7 @@
#include "ASN1ContentHandler.h"
#include "XMLContentHandler.h"
+#include "uri.h"
namespace relpipe {
namespace in {
@@ -37,6 +38,18 @@
private:
XMLContentHandlerProxy handlers;
+ std::string rootName = "asn1";
+ bool treeWithNamespaces = false;
+
+ /**
+ * TODO: use a common method
+ */
+ bool parseBoolean(const std::string& value) {
+ if (value == "true") return true;
+ else if (value == "false") return false;
+ else throw std::invalid_argument(std::string("Unable to parse boolean value: ") + value + " (expecting true or false)");
+ }
+
std::vector<std::string> getCommonAttributes(const Header& header, std::vector<std::string> attributes = {}) {
std::string tag = std::to_string(header.tag);
std::string tagClass = std::to_string((uint64_t) header.tagClass);
@@ -80,8 +93,20 @@
virtual ~GenericASN1ContentHandler() {
}
+ bool setOption(const std::string& uri, const std::string& value) override {
+ if (uri == xml::RootName) rootName = value;
+ else if (uri == xml::TreeWithNamespaces) treeWithNamespaces = parseBoolean(value);
+ else if (uri == xml::TreeStyle && value == "standard"); // the only style currently supported
+ else if (uri == xml::TreeStyle && value == "literal") throw std::invalid_argument("Tree style 'literal' is not yet supported"); // will require ASN.1 schema, might be implemented in another class
+ else if (uri == xml::TreeStyle) throw std::invalid_argument("Unsupported tree-style: " + value);
+ else return false;
+
+ return true;
+ }
+
void writeStreamStart() override {
- handlers.writeStartElement("asn1");
+ if (treeWithNamespaces) handlers.writeStartElement(rootName,{"xmlns", xml::XMLNS}); // TODO: actual namespace instead of a mere attribute
+ else handlers.writeStartElement(rootName);
}
void writeStreamEnd() override {