Dangerous SNMP
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
usmsecurityparameters.hpp
1 #pragma once
2 
3 namespace dangerous { namespace snmp { namespace encoding {
4 
6 public:
7  // OCTET STRING
8  std::string msgAuthoritativeEngineID;
9  // INTEGER (0..2147483647)
10  int32_t msgAuthoritativeEngineBoots;
11  // INTEGER (0..2147483647)
12  int32_t msgAuthoritativeEngineTime;
13  // OCTET STRING (SIZE(0..32))
14  std::string msgUserName;
15  // OCTET STRING
16  std::string msgAuthenticationParameters;
17  // OCTET STRING
18  std::string msgPrivacyParameters;
19 };
20 
25 public:
26  static constexpr const char* NAME = "UsmSecurityParameters";
27  static const int TYPE = asn1::helper::SEQUENCE::TYPE;
29 
30  static unsigned int length( const value_type& parameters ) {
31  unsigned int size = 0;
32 
33  size += asn1::encodedSize<encoding::OCTET_STRING>( parameters.msgAuthoritativeEngineID );
34  size += asn1::encodedSize<encoding::INTEGER>( parameters.msgAuthoritativeEngineBoots );
35  size += asn1::encodedSize<encoding::INTEGER>( parameters.msgAuthoritativeEngineTime );
36  size += asn1::encodedSize<encoding::OCTET_STRING>( parameters.msgUserName );
37  size += asn1::encodedSize<encoding::OCTET_STRING>( parameters.msgAuthenticationParameters );
38  size += asn1::encodedSize<encoding::OCTET_STRING>( parameters.msgPrivacyParameters );
39 
40  return size;
41  }
42 
43  static bool write( const value_type& parameters, char* buffer, unsigned int bufferSize ) {
44  ByteStream byteStream;
45  byteStream.linkFrom( buffer, bufferSize, ByteStream::READ_WRITE );
46 
47  BerStream berStream( &byteStream );
48 
49  bool success = true;
50 
51  success = berStream.write<encoding::OCTET_STRING>( parameters.msgAuthoritativeEngineID );
52  if( ! success ) {
53  return false;
54  }
55 
56  success = berStream.write<encoding::INTEGER>( parameters.msgAuthoritativeEngineBoots );
57  if( ! success ) {
58  return false;
59  }
60 
61  success = berStream.write<encoding::INTEGER>( parameters.msgAuthoritativeEngineTime );
62  if( ! success ) {
63  return false;
64  }
65 
66  success = berStream.write<encoding::OCTET_STRING>( parameters.msgUserName );
67  if( ! success ) {
68  return false;
69  }
70 
71  success = berStream.write<encoding::OCTET_STRING>( parameters.msgAuthenticationParameters );
72  if( ! success ) {
73  return false;
74  }
75 
76  success = berStream.write<encoding::OCTET_STRING>( parameters.msgPrivacyParameters );
77  if( ! success ) {
78  return false;
79  }
80 
81  return true;
82  }
83 
84  static bool read( value_type& parameters, char* buffer, unsigned int bufferSize ) {
85  ByteStream byteStream;
86  byteStream.linkFrom( buffer, bufferSize, ByteStream::READ_ONLY );
87 
88  BerStream berStream( &byteStream );
89 
90  bool success = true;
91 
92  success = berStream.read<encoding::OCTET_STRING>( parameters.msgAuthoritativeEngineID );
93  if( ! success ) {
94  return false;
95  }
96 
97  success = berStream.read<encoding::INTEGER>( parameters.msgAuthoritativeEngineBoots );
98  if( ! success ) {
99  return false;
100  }
101 
102  success = berStream.read<encoding::INTEGER>( parameters.msgAuthoritativeEngineTime );
103  if( ! success ) {
104  return false;
105  }
106 
107  success = berStream.read<encoding::OCTET_STRING>( parameters.msgUserName );
108  if( ! success ) {
109  return false;
110  }
111 
112  success = berStream.read<encoding::OCTET_STRING>( parameters.msgAuthenticationParameters );
113  if( ! success ) {
114  return false;
115  }
116 
117  success = berStream.read<encoding::OCTET_STRING>( parameters.msgPrivacyParameters );
118  if( ! success ) {
119  return false;
120  }
121 
122  return true;
123  }
124 };
125 
126 } } }
127 
bool write(const typename EncodingClass::value_type &value)
This performs a full, logical write of a kind of encoded data.
Definition: berstream.hpp:207
This is the encoder/decoder for the "UsmSecurityParameters" class.
Definition: usmsecurityparameters.hpp:24
A ByteStream is an object that is basically a big wrapper around a character buffer.
Definition: bytestream.hpp:30
Definition: encoding.hpp:20
Only read operations may be performed.
Definition: bytestream.hpp:38
A BerStream represents a BER-encoded stream of data.
Definition: berstream.hpp:16
Both read and write operations may be performed.
Definition: bytestream.hpp:40
void linkFrom(char *bytes, unsigned int bytesSize, Access access)
This links the bytes given to the ByteStream's character buffer.
Definition: encoding.hpp:25
bool read(typename EncodingClass::value_type &value)
This performs a full, logical read of a kind of encoded data.
Definition: berstream.hpp:145
Definition: usmsecurityparameters.hpp:5