• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lextudio / sharpsnmplib / 11823966615

13 Nov 2024 06:58PM UTC coverage: 49.626% (-3.4%) from 53.042%
11823966615

push

github

lextm
Removed .NET 6.

819 of 1881 branches covered (43.54%)

Branch coverage included in aggregate %.

2232 of 4267 relevant lines covered (52.31%)

15136.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/SharpSnmpLib/Messaging/GetNextRequestMessage.cs
1
// GET NEXT request message type.
2
// Copyright (C) 2008-2010 Malcolm Crowe, Lex Li, and other contributors.
3
// 
4
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5
// software and associated documentation files (the "Software"), to deal in the Software
6
// without restriction, including without limitation the rights to use, copy, modify, merge,
7
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8
// to whom the Software is furnished to do so, subject to the following conditions:
9
// 
10
// The above copyright notice and this permission notice shall be included in all copies or
11
// substantial portions of the Software.
12
// 
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
// DEALINGS IN THE SOFTWARE.
19

20
/*
21
 * Created by SharpDevelop.
22
 * User: lextm
23
 * Date: 2008/5/11
24
 * Time: 12:33
25
 * 
26
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
27
 */
28

29
using System;
30
using System.Collections.Generic;
31
using System.Globalization;
32
using Lextm.SharpSnmpLib.Security;
33

34
namespace Lextm.SharpSnmpLib.Messaging
35
{
36
    /// <summary>
37
    /// GETNEXT request message.
38
    /// </summary>
39
    public sealed class GetNextRequestMessage : ISnmpMessage
40
    {
41
        private readonly byte[] _bytes;
42

43
        /// <summary>
44
        /// Creates a <see cref="GetNextRequestMessage"/> with all contents.
45
        /// </summary>
46
        /// <param name="requestId">The request id.</param>
47
        /// <param name="version">Protocol version</param>
48
        /// <param name="community">Community name</param>
49
        /// <param name="variables">Variables</param>
50
        public GetNextRequestMessage(int requestId, VersionCode version, OctetString community, IList<Variable> variables)
×
51
        {
52
            if (variables == null)
×
53
            {
54
                throw new ArgumentNullException(nameof(variables));
×
55
            }
56

57
            if (community == null)
×
58
            {
59
                throw new ArgumentNullException(nameof(community));
×
60
            }
61

62
            if (version == VersionCode.V3)
×
63
            {
64
                throw new ArgumentException("Only v1 and v2c are supported.", nameof(version));
×
65
            }
66

67
            Version = version;
×
68
            Header = Header.Empty;
×
69
            Parameters = SecurityParameters.Create(community);
×
70
            var pdu = new GetNextRequestPdu(
×
71
                requestId,
×
72
                variables);
×
73
            Scope = new Scope(pdu);
×
74
            Privacy = DefaultPrivacyProvider.DefaultPair;
×
75

76
            _bytes = this.PackMessage(null).ToBytes();
×
77
        }
×
78

79
        /// <summary>
80
        /// Initializes a new instance of the <see cref="GetNextRequestMessage"/> class.
81
        /// </summary>
82
        /// <param name="version">The version.</param>
83
        /// <param name="messageId">The message id.</param>
84
        /// <param name="requestId">The request id.</param>
85
        /// <param name="userName">Name of the user.</param>
86
        /// <param name="variables">The variables.</param>
87
        /// <param name="privacy">The privacy provider.</param>
88
        /// <param name="report">The report.</param>
89
        [Obsolete("Please use other overloading ones.")]
90
        public GetNextRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, IList<Variable> variables, IPrivacyProvider privacy, ISnmpMessage report)
91
            : this(version, messageId, requestId, userName, variables, privacy, 0xFFE3, report)
×
92
        {
93
        }
×
94

95
        /// <summary>
96
        /// Initializes a new instance of the <see cref="GetNextRequestMessage"/> class.
97
        /// </summary>
98
        /// <param name="version">The version.</param>
99
        /// <param name="messageId">The message id.</param>
100
        /// <param name="requestId">The request id.</param>
101
        /// <param name="userName">Name of the user.</param>
102
        /// <param name="contextName">Context name.</param>
103
        /// <param name="variables">The variables.</param>
104
        /// <param name="privacy">The privacy provider.</param>
105
        /// <param name="maxMessageSize">Size of the max message.</param>
106
        /// <param name="report">The report.</param>
107
        public GetNextRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, OctetString contextName, IList<Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report)
×
108
        {
109
            if (variables == null)
×
110
            {
111
                throw new ArgumentNullException(nameof(variables));
×
112
            }
113

114
            if (userName == null)
×
115
            {
116
                throw new ArgumentNullException(nameof(userName));
×
117
            }
118

119
            if (contextName == null)
×
120
            {
121
                throw new ArgumentNullException(nameof(contextName));
×
122
            }
123

124
            if (version != VersionCode.V3)
×
125
            {
126
                throw new ArgumentException("Only v3 is supported.", nameof(version));
×
127
            }
128

129
            if (report == null)
×
130
            {
131
                throw new ArgumentNullException(nameof(report));
×
132
            }
133

134
            Version = version;
×
135
            Privacy = privacy ?? throw new ArgumentNullException(nameof(privacy));
×
136

137
            Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable);
×
138
            var parameters = report.Parameters;
×
139
            var authenticationProvider = Privacy.AuthenticationProvider;
×
140
            Parameters = new SecurityParameters(
×
141
                parameters.EngineId,
×
142
                parameters.EngineBoots,
×
143
                parameters.EngineTime,
×
144
                userName,
×
145
                authenticationProvider.CleanDigest,
×
146
                Privacy.Salt);
×
147
            var pdu = new GetNextRequestPdu(
×
148
                requestId,
×
149
                variables);
×
150
            var scope = report.Scope;
×
151
            var contextEngineId = scope.ContextEngineId == OctetString.Empty ? parameters.EngineId : scope.ContextEngineId;
×
152
            if (contextEngineId == null)
×
153
            {
154
                throw new SnmpException("invalid REPORT message");
×
155
            }
156

157
            Scope = new Scope(contextEngineId, contextName, pdu);
×
158

159
            Privacy.ComputeHash(Version, Header, Parameters, Scope);
×
160
            _bytes = this.PackMessage(null).ToBytes();
×
161
        }
×
162

163

164
        /// <summary>
165
        /// Initializes a new instance of the <see cref="GetNextRequestMessage"/> class.
166
        /// </summary>
167
        /// <param name="version">The version.</param>
168
        /// <param name="messageId">The message id.</param>
169
        /// <param name="requestId">The request id.</param>
170
        /// <param name="userName">Name of the user.</param>
171
        /// <param name="variables">The variables.</param>
172
        /// <param name="privacy">The privacy provider.</param>
173
        /// <param name="maxMessageSize">Size of the max message.</param>
174
        /// <param name="report">The report.</param>
175
        [Obsolete("Please use other overloading ones.")]
176
        public GetNextRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, IList<Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report)
177
            : this(version, messageId, requestId, userName, OctetString.Empty, variables, privacy, maxMessageSize, report)
×
178
        { }
×
179

180
        internal GetNextRequestMessage(VersionCode version, Header header, SecurityParameters parameters, Scope scope, IPrivacyProvider privacy, byte[]? length)
×
181
        {
182
            Version = version;
×
183
            Header = header ?? throw new ArgumentNullException(nameof(header));
×
184
            Parameters = parameters ?? throw new ArgumentNullException(nameof(parameters));
×
185
            Scope = scope ?? throw new ArgumentNullException(nameof(scope));
×
186
            Privacy = privacy ?? throw new ArgumentNullException(nameof(privacy));
×
187

188
            _bytes = this.PackMessage(length).ToBytes();
×
189
        }
×
190

191
        /// <summary>
192
        /// Gets the header.
193
        /// </summary>
194
        public Header Header { get; }
195

196
        /// <summary>
197
        /// Gets the privacy provider.
198
        /// </summary>
199
        /// <value>The privacy provider.</value>
200
        public IPrivacyProvider Privacy { get; }
201

202
        /// <summary>
203
        /// Converts to byte format.
204
        /// </summary>
205
        /// <returns></returns>
206
        public byte[] ToBytes()
207
        {
208
            return _bytes;
×
209
        }
210

211
        /// <summary>
212
        /// Gets the parameters.
213
        /// </summary>
214
        /// <value>The parameters.</value>
215
        public SecurityParameters Parameters { get; }
216

217
        /// <summary>
218
        /// Gets the scope.
219
        /// </summary>
220
        /// <value>The scope.</value>
221
        public Scope Scope { get; }
222

223
        /// <summary>
224
        /// Gets the version.
225
        /// </summary>
226
        /// <value>The version.</value>
227
        public VersionCode Version { get; }
228

229
        /// <summary>
230
        /// Returns a <see cref="string"/> that represents this <see cref="GetNextRequestMessage"/>.
231
        /// </summary>
232
        /// <returns></returns>
233
        public override string ToString()
234
        {
235
            return string.Format(CultureInfo.InvariantCulture, "GET NEXT request message: version: {0}; {1}; {2}", Version, Parameters.UserName, Scope.Pdu);
×
236
        }
237
    }
238
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc