--- a/src/lib/ASN1ContentHandler.h Sat Jul 03 20:17:17 2021 +0200
+++ b/src/lib/ASN1ContentHandler.h Sun Jul 04 11:37:27 2021 +0200
@@ -29,6 +29,46 @@
namespace asn1 {
namespace lib {
+namespace UniversalType {
+static const uint64_t EndOfContent = 0x00;
+static const uint64_t Boolean = 0x01;
+static const uint64_t Integer = 0x02;
+static const uint64_t BitString = 0x03;
+static const uint64_t OctetString = 0x04;
+static const uint64_t Null = 0x05;
+static const uint64_t ObjectIdentifier = 0x06;
+static const uint64_t ObjectDescriptor = 0x07;
+static const uint64_t External = 0x08;
+static const uint64_t Real = 0x09;
+static const uint64_t Enumerated = 0xA;
+static const uint64_t Embedded = 0xB;
+static const uint64_t UTF8String = 0xC;
+static const uint64_t RelativeObjectIdentifier = 0xD;
+static const uint64_t Time = 0xE;
+static const uint64_t Reserved = 0xF;
+static const uint64_t Sequence = 0x10;
+static const uint64_t Set = 0x11;
+static const uint64_t NumericString = 0x12;
+static const uint64_t PrintableString = 0x13;
+static const uint64_t T61String = 0x14;
+static const uint64_t VideotexString = 0x15;
+static const uint64_t IA5String = 0x16;
+static const uint64_t UTCTime = 0x17;
+static const uint64_t GeneralizedTime = 0x18;
+static const uint64_t GraphicString = 0x19;
+static const uint64_t VisibleString = 0x1A;
+static const uint64_t GeneralString = 0x1B;
+static const uint64_t UniversalString = 0x1C;
+static const uint64_t CharacterString = 0x1D;
+static const uint64_t BMPString = 0x1E;
+static const uint64_t Date = 0x1F;
+static const uint64_t TimeOfDay = 0x20;
+static const uint64_t DateTime = 0x21;
+static const uint64_t Duration = 0x22;
+static const uint64_t ObjectIdentifierIRI = 0x23;
+static const uint64_t RelativeObjectIdentifierIRI = 0x24;
+}
+
class ASN1ContentHandler {
public:
@@ -51,12 +91,6 @@
uint64_t tag;
};
- enum class CollectionType : uint64_t {
- Constructed, // TODO: special event?
- Sequence = 16,
- Set = 17
- };
-
enum class StringType : uint64_t {
UTF8String = 0xC,
NumericString = 0x12,
@@ -83,6 +117,9 @@
// TODO: review date/time types
};
+
+ // TODO: separate implementation of particular types from the interface, separate SPI from API?
+
class Integer {
private:
// TODO: use std::string (of octets, not ASCII) instead of std::vector?
@@ -253,7 +290,7 @@
virtual void writeStreamStart() = 0;
virtual void writeStreamEnd() = 0;
- virtual void writeCollectionStart(CollectionType type) = 0;
+ virtual void writeCollectionStart(const Header& header) = 0;
virtual void writeCollectionEnd() = 0;
virtual void writeBoolean(bool value) = 0;
virtual void writeNull() = 0;
@@ -300,8 +337,8 @@
handlers.forward(&ASN1ContentHandler::writeStreamEnd);
}
- void writeCollectionStart(CollectionType type) override {
- handlers.forward(&ASN1ContentHandler::writeCollectionStart, type);
+ void writeCollectionStart(const Header& header) override {
+ handlers.forward(&ASN1ContentHandler::writeCollectionStart, header);
}
void writeCollectionEnd() override {
--- a/src/lib/BasicASN1Reader.h Sat Jul 03 20:17:17 2021 +0200
+++ b/src/lib/BasicASN1Reader.h Sun Jul 04 11:37:27 2021 +0200
@@ -37,46 +37,6 @@
bool started = false;
- enum UniversalType : uint64_t {
- EndOfContent = 0x00,
- Boolean = 0x01,
- Integer = 0x02,
- BitString = 0x03,
- OctetString = 0x04,
- Null = 0x05,
- ObjectIdentifier = 0x06,
- ObjectDescriptor = 0x07,
- External = 0x08,
- Real = 0x09,
- Enumerated = 0xA,
- Embedded = 0xB,
- UTF8String = 0xC,
- RelativeObjectIdentifier = 0xD,
- Time = 0xE,
- Reserved = 0xF,
- Sequence = 0x10,
- Set = 0x11,
- NumericString = 0x12,
- PrintableString = 0x13,
- T61String = 0x14,
- VideotexString = 0x15,
- IA5String = 0x16,
- UTCTime = 0x17,
- GeneralizedTime = 0x18,
- GraphicString = 0x19,
- VisibleString = 0x1A,
- GeneralString = 0x1B,
- UniversalString = 0x1C,
- CharacterString = 0x1D,
- BMPString = 0x1E,
- Date = 0x1F,
- TimeOfDay = 0x20,
- DateTime = 0x21,
- Duration = 0x22,
- ObjectIdentifierIRI = 0x23,
- RelativeObjectIdentifierIRI = 0x24,
- };
-
class BasicHeader : public ASN1ContentHandler::Header {
public:
bool definiteLength;
@@ -171,13 +131,13 @@
handlers.writeCollectionEnd();
} else if (typeHeader.tag == UniversalType::Sequence) {
level.push_back({typeHeader.definiteLength, typeHeader.length, getBytesRead()}); // TODO: transaction
- handlers.writeCollectionStart(ASN1ContentHandler::CollectionType::Sequence);
+ handlers.writeCollectionStart(typeHeader);
} else if (typeHeader.tag == UniversalType::Set) {
level.push_back({typeHeader.definiteLength, typeHeader.length, getBytesRead()}); // TODO: transaction
- handlers.writeCollectionStart(ASN1ContentHandler::CollectionType::Set);
+ handlers.writeCollectionStart(typeHeader);
} else if (typeHeader.pc == PC::Constructed) {
level.push_back({typeHeader.definiteLength, typeHeader.length, getBytesRead()}); // TODO: transaction
- handlers.writeCollectionStart(ASN1ContentHandler::CollectionType::Constructed);
+ handlers.writeCollectionStart(typeHeader);
} else if (typeHeader.tag == UniversalType::Null && typeHeader.length == 0) {
handlers.writeNull();
} else if (typeHeader.tag == UniversalType::Boolean && typeHeader.definiteLength && typeHeader.length == 1) {
--- a/src/lib/GenericASN1ContentHandler.h Sat Jul 03 20:17:17 2021 +0200
+++ b/src/lib/GenericASN1ContentHandler.h Sun Jul 04 11:37:27 2021 +0200
@@ -52,11 +52,10 @@
handlers.writeEndElement();
}
- void writeCollectionStart(CollectionType type) override {
- if (type == CollectionType::Sequence) handlers.writeStartElement("sequence");
- else if (type == CollectionType::Set) handlers.writeStartElement("set");
- else if (type == CollectionType::Constructed) handlers.writeStartElement("constructed");
- else handlers.writeStartElement("unknown-collection"); // TODO: exception?
+ void writeCollectionStart(const Header& header) override {
+ if (header.tag == UniversalType::Sequence) handlers.writeStartElement("sequence");
+ else if (header.tag == UniversalType::Set) handlers.writeStartElement("set");
+ else handlers.writeStartElement("constructed");
}
void writeCollectionEnd() override {