3 #include "dangerous/snmp/logger.hpp"
5 #include "bytestream.hpp"
9 namespace dangerous {
namespace snmp {
26 bool copyTo( std::vector<char>& buffer );
77 template<
typename EncodingClass>
78 bool read(
typename EncodingClass::value_type& value );
86 bool readBytes(
char* buffer,
unsigned int bufferSize,
unsigned int& bytesRead );
121 template<
typename EncodingClass>
122 bool write(
const typename EncodingClass::value_type& value );
131 bool writeBytes(
const char* buffer,
unsigned int bufferSize,
unsigned int& bytesWritten );
144 template<
typename EncodingClass>
150 logger.
out() <<
"BerStream: read<" << EncodingClass::NAME <<
">: Could not read the type." << std::endl;
156 logger.
out() <<
"BerStream: read<" << EncodingClass::NAME <<
">: Looking for a type of " << EncodingClass::TYPE <<
"." << std::endl;
158 if( type != EncodingClass::TYPE ) {
162 unsigned int increment = 0;
166 logger.
out() <<
"BerStream: read<" << EncodingClass::NAME <<
">: Could not read the length." << std::endl;
171 logger.
out() <<
"BerStream: read<" << EncodingClass::NAME <<
">: Got a length of " << increment <<
"." << std::endl;
173 if( increment < 1 ) {
178 logger.
out() <<
"BerStream: read<" << EncodingClass::NAME <<
">: Reading " << increment <<
" bytes." << std::endl;
180 unsigned int bytesRead = 0;
181 char buffer[ increment ];
182 status =
readBytes( buffer, increment, bytesRead );
185 logger.
out() <<
"BerStream: read<" << EncodingClass::NAME <<
">: Could not read the value bytes." << std::endl;
189 status = EncodingClass::read( value, buffer, increment );
192 logger.
out() <<
"BerStream: read<" << EncodingClass::NAME <<
">: Could not parse the value bytes." << std::endl;
206 template<
typename EncodingClass>
209 logger.
out() <<
"BerStream: write<" << EncodingClass::NAME <<
">: Writing a type of " << EncodingClass::TYPE <<
"." << std::endl;
211 bool status =
writeType( EncodingClass::TYPE );
214 logger.
out() <<
"BerStream: write<" << EncodingClass::NAME <<
">: Could not write the type." << std::endl;
219 unsigned int encodedLength = EncodingClass::length( value );
221 logger.
out() <<
"BerStream: write<" << EncodingClass::NAME <<
">: Got a length of " << encodedLength <<
"." << std::endl;
226 logger.
out() <<
"BerStream: write<" << EncodingClass::NAME <<
">: Could not write the length." << std::endl;
232 logger.
out() <<
"BerStream: write<" << EncodingClass::NAME <<
">: Writing " << encodedLength <<
" bytes." << std::endl;
235 char buffer[ encodedLength ];
236 status = EncodingClass::write( value, buffer, encodedLength );
239 logger.
out() <<
"BerStream: write<" << EncodingClass::NAME <<
">: Could not encode the value." << std::endl;
244 unsigned int bytesWritten = 0;
245 status =
writeBytes( buffer, encodedLength, bytesWritten );
248 logger.
out() <<
"BerStream: write<" << EncodingClass::NAME <<
">: Could not write the value." << std::endl;
bool write(const typename EncodingClass::value_type &value)
This performs a full, logical write of a kind of encoded data.
Definition: berstream.hpp:207
bool system(System system)
This returns the logging status for the given system.
Definition: logger.hpp:47
BerStream(ByteStream *byteStream)
TODO.
std::ostream & out()
This returns the output stream for the Logger.
Definition: logger.hpp:77
bool readFullTlv(std::vector< char > &buffer)
This reads a full TLV set of data and fills out the whole thing (including the type, the length, and the value) exactly as read.
A ByteStream is an object that is basically a big wrapper around a character buffer.
Definition: bytestream.hpp:30
bool readBytes(char *buffer, unsigned int bufferSize, unsigned int &bytesRead)
This reads an arbitrary amount of bytes into the specified character buffer.
unsigned int remainingReadLength() const
This returns the number of bytes remaining in the stream.
Definition: berstream.hpp:32
bool readLength(unsigned int &length)
This reads an ASN.1 length from the BerStream.
A BerStream represents a BER-encoded stream of data.
Definition: berstream.hpp:16
bool writeType(uint8_t type)
This writes the given ASN.1 type to the buffer in BER.
bool copyTo(std::vector< char > &buffer)
TODO.
bool writeBytes(const char *buffer, unsigned int bufferSize, unsigned int &bytesWritten)
This writes the bytes given to the BerStream.
unsigned int remainingReadLength() const
This returns the number of bytes remaining in the stream.
unsigned int remainingWriteLength() const
This returns the number of bytes remaining in the stream.
bool peekType(uint8_t &type)
This reads an ASN.1 type from the BerStream.
bool writeLength(unsigned int encodedLength)
This writes the length to the buffer in BER.
Logger logger
We will expose a global Logger instance.
ByteStream * _byteStream
TODO.
Definition: berstream.hpp:135
unsigned int remainingWriteLength() const
This returns the number of bytes remaining in the stream.
Definition: berstream.hpp:38
bool read(typename EncodingClass::value_type &value)
This performs a full, logical read of a kind of encoded data.
Definition: berstream.hpp:145
Logging related to ByteStream.
Definition: logger.hpp:22
bool readType(uint8_t &type)
This reads an ASN.1 type from the BerStream.