src/lib/ASN1ContentHandler.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 18 Jul 2021 12:37:40 +0200
branchv_0
changeset 35 bf2c546f49d1
parent 27 d9cc2d356cdb
child 40 85b6f13f1088
permissions -rw-r--r--
format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
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
24
114810ee2386 replace macro with ProxyVector that forwards method calls to all its elements
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    25
#include "ProxyVector.h"
114810ee2386 replace macro with ProxyVector that forwards method calls to all its elements
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    26
1
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace relpipe {
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace in {
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
namespace asn1 {
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
namespace lib {
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
26
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    32
namespace UniversalType {
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    33
static const uint64_t EndOfContent = 0x00;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    34
static const uint64_t Boolean = 0x01;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    35
static const uint64_t Integer = 0x02;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    36
static const uint64_t BitString = 0x03;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    37
static const uint64_t OctetString = 0x04;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    38
static const uint64_t Null = 0x05;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    39
static const uint64_t ObjectIdentifier = 0x06;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    40
static const uint64_t ObjectDescriptor = 0x07;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    41
static const uint64_t External = 0x08;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    42
static const uint64_t Real = 0x09;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    43
static const uint64_t Enumerated = 0xA;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    44
static const uint64_t Embedded = 0xB;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    45
static const uint64_t UTF8String = 0xC;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    46
static const uint64_t RelativeObjectIdentifier = 0xD;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    47
static const uint64_t Time = 0xE;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    48
static const uint64_t Reserved = 0xF;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    49
static const uint64_t Sequence = 0x10;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    50
static const uint64_t Set = 0x11;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    51
static const uint64_t NumericString = 0x12;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    52
static const uint64_t PrintableString = 0x13;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    53
static const uint64_t T61String = 0x14;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    54
static const uint64_t VideotexString = 0x15;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    55
static const uint64_t IA5String = 0x16;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    56
static const uint64_t UTCTime = 0x17;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    57
static const uint64_t GeneralizedTime = 0x18;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    58
static const uint64_t GraphicString = 0x19;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    59
static const uint64_t VisibleString = 0x1A;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    60
static const uint64_t GeneralString = 0x1B;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    61
static const uint64_t UniversalString = 0x1C;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    62
static const uint64_t CharacterString = 0x1D;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    63
static const uint64_t BMPString = 0x1E;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    64
static const uint64_t Date = 0x1F;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    65
static const uint64_t TimeOfDay = 0x20;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    66
static const uint64_t DateTime = 0x21;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    67
static const uint64_t Duration = 0x22;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    68
static const uint64_t ObjectIdentifierIRI = 0x23;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    69
static const uint64_t RelativeObjectIdentifierIRI = 0x24;
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    70
}
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    71
1
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
class ASN1ContentHandler {
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    73
public:
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    74
25
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    75
	enum class TagClass : uint8_t {
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    76
		Universal = 0,
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    77
		Application = 1,
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    78
		ContextSpecific = 2,
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    79
		Private = 3
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    80
	};
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    81
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    82
	enum class PC : uint8_t {
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    83
		Primitive = 0,
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    84
		Constructed = 1
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    85
	};
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    86
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    87
	class Header {
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    88
	public:
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    89
		TagClass tagClass;
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    90
		PC pc;
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    91
		uint64_t tag;
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    92
	};
ba79cebde109 move TagClass, PC and Header to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    93
26
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    94
	// TODO: separate implementation of particular types from the interface, separate SPI from API?
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    95
17
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    96
	class Integer {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    97
	private:
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    98
		// 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
    99
		// 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
   100
		std::vector<uint8_t> data;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   101
	public:
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   102
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   103
		/**
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   104
		 * @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
   105
		 */
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   106
		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
   107
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   108
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   109
		virtual ~Integer() {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   110
		}
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
		size_t size() const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   113
			return data.size();
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   114
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   115
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   116
		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
   117
			return data[index];
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   118
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   119
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   120
		const std::string toHex() const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   121
			std::stringstream hex;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   122
			hex << std::hex << std::setfill('0');
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   123
			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
   124
			return hex.str();
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   125
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   126
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   127
		const std::string toString() const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   128
			try {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   129
				return std::to_string(toInt64());
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   130
			} catch (...) {
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   131
				// 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
   132
				// 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
   133
				// 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
   134
				return "";
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   135
			}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   136
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   137
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   138
		const int64_t toInt64() const {
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   139
			int64_t value = 0;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   140
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   141
			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
   142
			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
   143
18
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   144
			value = data[0];
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   145
			bool negative = data[0] & 0x80;
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   146
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   147
			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
   148
cb85500c4a30 some support for Integers – improved
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   149
			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
   150
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   151
			return value;
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   152
		}
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   153
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   154
	};
f5281ab3e68f some support for Integers
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   155
20
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   156
	class ObjectIdentifier {
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   157
	private:
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   158
		// TODO: use std::string (of octets, not ASCII) instead of std::vector?
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   159
		// TODO: use this class across Relational pipes as one of basic types?
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   160
		std::vector<uint8_t> data;
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   161
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   162
	public:
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   163
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   164
		/**
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   165
		 * @param data integer octets as in BER encoding
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   166
		 */
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   167
		ObjectIdentifier(std::vector<uint8_t> data) : data(data) {
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   168
			// TODO: cache size and element values?
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   169
		}
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   170
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   171
		virtual ~ObjectIdentifier() {
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   172
		}
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   173
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   174
		/**
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   175
		 * @return number of elements, not octets
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   176
		 */
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   177
		size_t size() const {
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   178
			return 0; // FIXME: correct OID size
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   179
		}
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   180
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   181
		/**
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   182
		 * @param index 0 = root element
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   183
		 * @return value of the element at given position
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   184
		 */
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   185
		const uint8_t& operator[](std::size_t index) const {
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   186
			return data[index]; // FIXME: correct OID value
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   187
		}
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   188
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   189
		const std::string toString() const {
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   190
			if (data.size() == 0) return "";
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   191
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   192
			std::stringstream result;
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   193
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   194
			result << (data[0] / 40) << "." << (data[0] % 40); // first two elements are encoded in the first octet
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   195
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   196
			for (size_t i = 1, limit = data.size(), octet = 0, element = 0; i < limit; i++) {
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   197
				octet = data[i];
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   198
				element = element << 7 | (octet & 0xFF >> 1);
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   199
				// TODO: throw exception if the element value overflows? (should not happen) or format even longer values
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   200
				if ((octet & 1 << 7) == 0) {
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   201
					result << "." << element;
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   202
					element = 0;
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   203
				}
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   204
			}
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   205
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   206
			return result.str();
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   207
		}
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   208
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   209
	};
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   210
21
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   211
	class DateTime {
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   212
	public:
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   213
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   214
		enum class Precision {
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   215
			Year,
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   216
			Month,
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   217
			Day,
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   218
			Hour,
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   219
			Minute,
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   220
			Second,
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   221
			Milisecond,
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   222
			Nanosecond
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   223
		};
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   224
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   225
		// TODO: timezone (in minutes or 1/4 hours)
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   226
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   227
		Precision precision = Precision::Second;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   228
		int32_t year = 1970;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   229
		int8_t month = 1;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   230
		int8_t day = 1;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   231
		int8_t hour = 0;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   232
		int8_t minute = 0;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   233
		int8_t second = 0;
22
9b6f86760384 slightly improved UTCTime and GeneralizedTime support
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
   234
		int32_t nanosecond = 0;
9b6f86760384 slightly improved UTCTime and GeneralizedTime support
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
   235
		int8_t timezoneHour = 0;
9b6f86760384 slightly improved UTCTime and GeneralizedTime support
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
   236
		int8_t timezoneMinute = 0;
21
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   237
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   238
		virtual ~DateTime() {
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   239
		}
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   240
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   241
		const std::string toString() const {
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   242
			std::stringstream result;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   243
			result << std::setfill('0');
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   244
			result << std::setw(4) << (int) year;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   245
			result << "-" << std::setw(2) << (int) month;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   246
			result << "-" << std::setw(2) << (int) day;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   247
			result << "T" << std::setw(2) << (int) hour;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   248
			result << ":" << std::setw(2) << (int) minute;
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   249
			result << ":" << std::setw(2) << (int) second;
22
9b6f86760384 slightly improved UTCTime and GeneralizedTime support
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
   250
			if (precision == Precision::Nanosecond) result << "," << (int) nanosecond;
9b6f86760384 slightly improved UTCTime and GeneralizedTime support
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
   251
			result << (timezoneHour < 0 ? "-" : "+");
9b6f86760384 slightly improved UTCTime and GeneralizedTime support
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
   252
			result << std::setw(2) << (int) std::abs(timezoneHour);
9b6f86760384 slightly improved UTCTime and GeneralizedTime support
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
   253
			result << ":" << std::setw(2) << (int) timezoneMinute;
21
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   254
			return result.str();
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   255
		}
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   256
	};
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   257
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   258
	virtual ~ASN1ContentHandler() = default;
20
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   259
19
b7431bc6069b support tag numbers > 30 (multiple octets)
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
   260
	// TODO: more metadata, support OID decoding and ASN.1 modules (schema), probably through a plug-in
21
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   261
	// TODO: support also extension extractor plug-ins? (could decode some opaque structures like octet strings and replace them with nested elements) e.g. subjectAltName in https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   262
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   263
	virtual void writeStreamStart() = 0;
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   264
	virtual void writeStreamEnd() = 0;
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   265
26
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
   266
	virtual void writeCollectionStart(const Header& header) = 0;
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   267
	virtual void writeCollectionEnd() = 0;
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   268
	virtual void writeBoolean(const Header& header, bool value) = 0;
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   269
	virtual void writeNull(const Header& header) = 0;
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   270
	virtual void writeInteger(const Header& header, Integer value) = 0;
23
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   271
	/**
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   272
	 * @param type original type in ASN.1
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   273
	 * @param value original text converted to UTF-8
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   274
	 */
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   275
	virtual void writeTextString(const Header& header, std::string value) = 0;
23
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   276
	/**
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   277
	 * @param value arbitrary sequence of octets (bytes), usually not a human-readable text
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   278
	 */
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   279
	virtual void writeOctetString(const Header& header, std::string value) = 0;
23
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   280
	/**
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   281
	 * @param value arbitrary sequence of bits (booleans), usually not a human-readable text
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   282
	 */
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   283
	virtual void writeBitString(const Header& header, std::vector<bool> value) = 0;
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   284
	virtual void writeOID(const Header& header, ObjectIdentifier value) = 0;
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   285
	virtual void writeDateTime(const Header& header, DateTime value) = 0;
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   286
	// Object descriptor
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   287
	// 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
   288
	// Enumerated
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   289
	// Embedded PVD
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   290
	// Relative OID
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   291
	// OID-IRI
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   292
	// 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
   293
35
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   294
	/**
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   295
	 * Specific value that was not parsed.
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   296
	 * May be processed in a generic way (as binary data or ASCII or UTF-8 string, when possible)
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   297
	 * or according to given application, context or private specification.
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   298
	 * 
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   299
	 * @param value original raw data
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   300
	 */
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   301
	virtual void writeSpecific(const Header& header, std::string value) = 0;
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   302
1
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   303
};
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   304
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   305
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
   306
private:
24
114810ee2386 replace macro with ProxyVector that forwards method calls to all its elements
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
   307
	ProxyVector<ASN1ContentHandler> handlers;
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   308
public:
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   309
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   310
	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
   311
		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
   312
	}
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   313
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   314
	void writeStreamStart() override {
24
114810ee2386 replace macro with ProxyVector that forwards method calls to all its elements
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
   315
		handlers.forward(&ASN1ContentHandler::writeStreamStart);
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   316
	}
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   317
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   318
	void writeStreamEnd() override {
24
114810ee2386 replace macro with ProxyVector that forwards method calls to all its elements
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
   319
		handlers.forward(&ASN1ContentHandler::writeStreamEnd);
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   320
	}
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   321
26
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
   322
	void writeCollectionStart(const Header& header) override {
e39de9b8b3a1 move UniversalType to ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
   323
		handlers.forward(&ASN1ContentHandler::writeCollectionStart, header);
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   324
	}
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   325
9
7a6abdd00ab5 partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   326
	void writeCollectionEnd() override {
24
114810ee2386 replace macro with ProxyVector that forwards method calls to all its elements
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
   327
		handlers.forward(&ASN1ContentHandler::writeCollectionEnd);
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   328
	}
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   329
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   330
	void writeBoolean(const Header& header, bool value) override {
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   331
		handlers.forward(&ASN1ContentHandler::writeBoolean, header, value);
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   332
	}
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   333
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   334
	void writeNull(const Header& header) override {
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   335
		handlers.forward(&ASN1ContentHandler::writeNull, header);
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   336
	}
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   337
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   338
	void writeInteger(const Header& header, Integer value) override {
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   339
		handlers.forward(&ASN1ContentHandler::writeInteger, header, value);
8
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   340
	}
d37c1a5d09ce bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
   341
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   342
	void writeTextString(const Header& header, std::string value) override {
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   343
		handlers.forward(&ASN1ContentHandler::writeTextString, header, value);
23
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   344
	}
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   345
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   346
	void writeOctetString(const Header& header, std::string value) override {
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   347
		handlers.forward(&ASN1ContentHandler::writeOctetString, header, value);
23
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   348
	}
8941a679299f BitString and OctetString support
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   349
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   350
	void writeBitString(const Header& header, std::vector<bool> value) override {
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   351
		handlers.forward(&ASN1ContentHandler::writeBitString, header, value);
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   352
	}
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   353
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   354
	void writeOID(const Header& header, ObjectIdentifier value) override {
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   355
		handlers.forward(&ASN1ContentHandler::writeOID, header, value);
20
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   356
	}
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   357
27
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   358
	void writeDateTime(const Header& header, DateTime value) override {
d9cc2d356cdb add common Header argument to ASN1ContentHandler methods
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
   359
		handlers.forward(&ASN1ContentHandler::writeDateTime, header, value);
21
705036445672 partial UTCTime support
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   360
	}
20
fac034e3e867 support object identifiers (OID)
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
   361
35
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   362
	void writeSpecific(const Header& header, std::string value) override {
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   363
		handlers.forward(&ASN1ContentHandler::writeSpecific, header, value);
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   364
	}
bf2c546f49d1 format specific/unknown/unparsed/raw values in ASN1ContentHandler instead of in ASN1Reader
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   365
4
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   366
};
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   367
7230e1ea0b07 proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   368
1
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   369
}
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   370
}
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   371
}
2179f13227f4 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   372
}