support tag numbers > 30 (multiple octets) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 27 Jun 2021 18:04:34 +0200
branchv_0
changeset 19 b7431bc6069b
parent 18 cb85500c4a30
child 20 fac034e3e867
support tag numbers > 30 (multiple octets)
src/lib/ASN1ContentHandler.h
src/lib/BasicASN1Reader.h
--- a/src/lib/ASN1ContentHandler.h	Sat Jun 26 20:26:29 2021 +0200
+++ b/src/lib/ASN1ContentHandler.h	Sun Jun 27 18:04:34 2021 +0200
@@ -113,6 +113,8 @@
 	};
 
 	virtual ~ASN1ContentHandler() = default;
+	
+	// TODO: more metadata, support OID decoding and ASN.1 modules (schema), probably through a plug-in
 
 	virtual void writeStreamStart() = 0;
 	virtual void writeStreamEnd() = 0;
--- a/src/lib/BasicASN1Reader.h	Sat Jun 26 20:26:29 2021 +0200
+++ b/src/lib/BasicASN1Reader.h	Sun Jun 27 18:04:34 2021 +0200
@@ -88,7 +88,14 @@
 		h.tagClass = (TagClass) (tagByte >> 6);
 		h.pc = (PC) ((tagByte >> 5) & 1);
 		h.tag = tagByte & (0xFF >> 3);
-		if (h.tag > 30) throw relpipe::writer::RelpipeWriterException(L"not yet implemented, ASN.1 tag > 30"); // FIXME: higher tag values → read more bytes
+		if (h.tag == 31) { // all five tag bits are set → tag number (greater than 30) is encoded in following octets
+			h.tag = 0;
+			uint8_t moreTag = 0;
+			do {
+				read(&moreTag, 1);
+				h.tag = h.tag << 7 | (moreTag & (0xFF >> 1));
+			} while (moreTag & (1 << 7));
+		}
 
 		uint8_t lengthByte;
 		read(&lengthByte, 1);