# HG changeset patch # User František Kučera # Date 1553907114 -3600 # Node ID d1b39a9bd591785168b444c61f9f477e1f54a949 # Parent e9b4f3a9e4364a87efb8f7e2a5e19ced711327c0 use more writeIdentifier() and writeLength() methods diff -r e9b4f3a9e436 -r d1b39a9bd591 src/ASN1Writer.h --- a/src/ASN1Writer.h Sat Mar 30 01:39:05 2019 +0100 +++ b/src/ASN1Writer.h Sat Mar 30 01:51:54 2019 +0100 @@ -63,6 +63,7 @@ }; enum UniversalType : uint16_t { + EndOfContent = 0, Boolean = 1, Integer = 2, OctetString = 4, @@ -106,6 +107,10 @@ } } + void writeLengthIndefinite() { + output.put('\x80'); + } + static bool isLittleEndian() { int test = 1; return (*(char *) &test); @@ -133,20 +138,20 @@ void writeStartSequence() { sequenceLevel++; - output.put('\x30'); - output.put('\x80'); + writeIdentifier(TagClass::Universal, PC::Constructed, UniversalType::Sequence); + writeLengthIndefinite(); } void writeEndSequence() { if (sequenceLevel == 0) throw cli::RelpipeCLIException(L"Unable to writeEndSequence() if not sequence is currently started.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // should not happen, error in the program sequenceLevel--; - output.put('\x00'); - output.put('\x00'); + writeIdentifier(TagClass::Universal, PC::Primitive, UniversalType::EndOfContent); + writeLength(0u); } void writeBoolean(const boolean_t& value) { - output.put('\x01'); - output.put('\x01'); + writeIdentifier(TagClass::Universal, PC::Primitive, UniversalType::Boolean); + writeLength(1u); output.put(value ? '\xFF' : '\x00'); }