src/ASN1Writer.h
branchv_0
changeset 2 d1b39a9bd591
parent 1 e9b4f3a9e436
child 7 c155b441306f
equal deleted inserted replaced
1:e9b4f3a9e436 2:d1b39a9bd591
    61 		/** The contents octets contain 0, 1, or more element encodings.  */
    61 		/** The contents octets contain 0, 1, or more element encodings.  */
    62 		Constructed = 1,
    62 		Constructed = 1,
    63 	};
    63 	};
    64 
    64 
    65 	enum UniversalType : uint16_t {
    65 	enum UniversalType : uint16_t {
       
    66 		EndOfContent = 0,
    66 		Boolean = 1,
    67 		Boolean = 1,
    67 		Integer = 2,
    68 		Integer = 2,
    68 		OctetString = 4,
    69 		OctetString = 4,
    69 		Null = 5,
    70 		Null = 5,
    70 		ObjectIdentifier = 6,
    71 		ObjectIdentifier = 6,
   104 				}
   105 				}
   105 			}
   106 			}
   106 		}
   107 		}
   107 	}
   108 	}
   108 
   109 
       
   110 	void writeLengthIndefinite() {
       
   111 		output.put('\x80');
       
   112 	}
       
   113 
   109 	static bool isLittleEndian() {
   114 	static bool isLittleEndian() {
   110 		int test = 1;
   115 		int test = 1;
   111 		return (*(char *) &test);
   116 		return (*(char *) &test);
   112 	}
   117 	}
   113 
   118 
   131 		if (sequenceLevel) throw cli::RelpipeCLIException(L"Unable to close ASN1Writer because there are not ended sequences.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // should not happen, error in the program
   136 		if (sequenceLevel) throw cli::RelpipeCLIException(L"Unable to close ASN1Writer because there are not ended sequences.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // should not happen, error in the program
   132 	}
   137 	}
   133 
   138 
   134 	void writeStartSequence() {
   139 	void writeStartSequence() {
   135 		sequenceLevel++;
   140 		sequenceLevel++;
   136 		output.put('\x30');
   141 		writeIdentifier(TagClass::Universal, PC::Constructed, UniversalType::Sequence);
   137 		output.put('\x80');
   142 		writeLengthIndefinite();
   138 	}
   143 	}
   139 
   144 
   140 	void writeEndSequence() {
   145 	void writeEndSequence() {
   141 		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
   146 		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
   142 		sequenceLevel--;
   147 		sequenceLevel--;
   143 		output.put('\x00');
   148 		writeIdentifier(TagClass::Universal, PC::Primitive, UniversalType::EndOfContent);
   144 		output.put('\x00');
   149 		writeLength(0u);
   145 	}
   150 	}
   146 
   151 
   147 	void writeBoolean(const boolean_t& value) {
   152 	void writeBoolean(const boolean_t& value) {
   148 		output.put('\x01');
   153 		writeIdentifier(TagClass::Universal, PC::Primitive, UniversalType::Boolean);
   149 		output.put('\x01');
   154 		writeLength(1u);
   150 		output.put(value ? '\xFF' : '\x00');
   155 		output.put(value ? '\xFF' : '\x00');
   151 
   156 
   152 	}
   157 	}
   153 
   158 
   154 	void writeInteger(const integer_t& value) {
   159 	void writeInteger(const integer_t& value) {