src/lib/ASN1ContentHandler.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 26 Jun 2021 20:26:29 +0200
branchv_0
changeset 18 cb85500c4a30
parent 17 f5281ab3e68f
child 19 b7431bc6069b
permissions -rw-r--r--
some support for Integers – improved
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    19
#include <memory>
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    20
#include <vector>
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    21
#include <sstream>
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    22
#include <iomanip>
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    23
#include <cmath>
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    24
1
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
namespace relpipe {
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
namespace in {
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace asn1 {
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace lib {
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
class ASN1ContentHandler {
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    31
public:
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    32
14
02725d301010 somehow parse nested SEQUENCEs and SETs + support definite long form of lengths (multiple length octets)
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    33
	enum class CollectionType : uint64_t {
15
95ca127ba816 support constructed (like a collection)
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    34
		Constructed, // TODO: special event?
14
02725d301010 somehow parse nested SEQUENCEs and SETs + support definite long form of lengths (multiple length octets)
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    35
		Sequence = 16,
02725d301010 somehow parse nested SEQUENCEs and SETs + support definite long form of lengths (multiple length octets)
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    36
		Set = 17
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    37
	};
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    38
14
02725d301010 somehow parse nested SEQUENCEs and SETs + support definite long form of lengths (multiple length octets)
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    39
	enum class StringType : uint64_t {
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    40
		OctetString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    41
		UTF8String,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    42
		NumericString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    43
		PrintableString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    44
		T61String,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    45
		VideotexString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    46
		IA5String,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    47
		GraphicString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    48
		VisibleString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    49
		GeneralString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    50
		UniversalString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    51
		CharacterString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    52
		BMPString,
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    53
	};
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    54
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    55
	class Integer {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    56
	private:
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    57
		// TODO: use std::string (of octets, not ASCII) instead of std::vector?
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    58
		// TODO: use this class as BigInteger across Relational pipes?
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    59
		std::vector<uint8_t> data;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    60
	public:
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    61
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    62
		/**
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    63
		 * @param data integer octets as in BER encoding
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    64
		 */
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    65
		Integer(std::vector<uint8_t> data) : data(data) {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    66
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    67
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    68
		virtual ~Integer() {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    69
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    70
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    71
		size_t size() const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    72
			return data.size();
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    73
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    74
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    75
		const uint8_t& operator[](std::size_t index) const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    76
			return data[index];
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    77
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    78
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    79
		const std::string toHex() const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    80
			std::stringstream hex;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    81
			hex << std::hex << std::setfill('0');
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    82
			for (uint8_t b : data) hex << std::setw(2) << (int) b;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    83
			return hex.str();
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    84
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    85
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    86
		const std::string toString() const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    87
			try {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    88
				return std::to_string(toInt64());
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    89
			} catch (...) {
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    90
				// integer has more than 64 bits → only HEX form value will be available
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    91
				// TODO: support longer values than 64 bits
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    92
				// TODO: do not ignore zero-length error?
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    93
				return "";
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    94
			}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    95
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    96
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    97
		const int64_t toInt64() const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    98
			int64_t value = 0;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    99
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   100
			if (data.size() > sizeof (value)) throw std::invalid_argument("Integer is too long");
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   101
			else if (data.size() == 0) throw std::invalid_argument("Integer has zero length");
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   102
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   103
			value = data[0];
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   104
			bool negative = data[0] & 0x80;
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   105
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   106
			for (size_t i = 1, limit = data.size(); i < limit; i++) value = (value << 8) | data[i];
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   107
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   108
			if (negative) value -= std::pow(256, data.size());
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   109
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   110
			return value;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   111
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   112
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   113
	};
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   114
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   115
	virtual ~ASN1ContentHandler() = default;
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   116
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   117
	virtual void writeStreamStart() = 0;
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   118
	virtual void writeStreamEnd() = 0;
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   119
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   120
	virtual void writeCollectionStart(CollectionType type) = 0;
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   121
	virtual void writeCollectionEnd() = 0;
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   122
	virtual void writeBoolean(bool value) = 0;
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   123
	virtual void writeNull() = 0;
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   124
	virtual void writeInteger(Integer value) = 0;
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   125
	virtual void writeString(StringType type, std::string value) = 0;
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   126
	// virtual void writeOID(std::string value) = 0;
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   127
	// Object descriptor
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   128
	// virtual void writeReal(float value) = 0;
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   129
	// Enumerated
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   130
	// Embedded PVD
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   131
	// Relative OID
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   132
	// TIME
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   133
	// UTC time
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   134
	// Generalized time
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   135
	// Date
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   136
	// Time of day
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   137
	// Date-time
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   138
	// Duration
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   139
	// OID-IRI
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   140
	// Relative OID-IRI
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   141
1
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   142
};
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   143
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   144
class ASN1ContentHandlerProxy : public ASN1ContentHandler {
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   145
private:
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   146
	std::vector<std::shared_ptr<ASN1ContentHandler>> handlers;
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   147
public:
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   148
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   149
	void addHandler(std::shared_ptr<ASN1ContentHandler> handler) {
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   150
		handlers.push_back(handler);
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   151
	}
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   152
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   153
#define handler for (auto ___h : handlers) ___h
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   154
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   155
	void writeStreamStart() override {
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   156
		handler->writeStreamStart();
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   157
	}
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   158
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   159
	void writeStreamEnd() override {
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   160
		handler->writeStreamEnd();
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   161
	}
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   162
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   163
	void writeCollectionStart(CollectionType type) override {
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   164
		handler->writeCollectionStart(type);
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   165
	}
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   166
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   167
	void writeCollectionEnd() override {
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   168
		handler->writeCollectionEnd();
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   169
	}
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   170
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   171
	void writeBoolean(bool value) override {
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   172
		handler->writeBoolean(value);
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   173
	}
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   174
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   175
	void writeNull() override {
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   176
		handler->writeNull();
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   177
	}
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   178
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   179
	void writeInteger(Integer value) override {
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   180
		handler->writeInteger(value);
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   181
	}
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   182
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   183
	void writeString(StringType type, std::string value) override {
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   184
		handler->writeString(type, value);
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   185
	}
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   186
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   187
#undef handler
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   188
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   189
};
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   190
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   191
1
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   192
}
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   193
}
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   194
}
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   195
}