本文整理汇总了C#中Lextm.SharpSnmpLib.Security.UserRegistry.Find方法的典型用法代码示例。如果您正苦于以下问题:C# UserRegistry.Find方法的具体用法?C# UserRegistry.Find怎么用?C# UserRegistry.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lextm.SharpSnmpLib.Security.UserRegistry
的用法示例。
在下文中一共展示了UserRegistry.Find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseMessage
private static ISnmpMessage ParseMessage(int first, Stream stream, UserRegistry registry)
{
ISnmpData array = DataFactory.CreateSnmpData(first, stream);
if (array == null)
{
return null;
}
if (array.TypeCode != SnmpType.Sequence)
{
throw new SnmpException("not an SNMP message");
}
Sequence body = (Sequence)array;
if (body.Count != 3 && body.Count != 4)
{
throw new SnmpException("not an SNMP message");
}
VersionCode version = (VersionCode)((Integer32)body[0]).ToInt32();
Header header;
SecurityParameters parameters;
IPrivacyProvider privacy;
Scope scope;
if (body.Count == 3)
{
header = Header.Empty;
parameters = new SecurityParameters(null, null, null, (OctetString)body[1], null, null);
privacy = DefaultPrivacyProvider.DefaultPair;
scope = new Scope((ISnmpPdu)body[2]);
}
else
{
header = new Header(body[1]);
parameters = new SecurityParameters((OctetString)body[2]);
privacy = registry.Find(parameters.UserName);
if (privacy == null)
{
// handle decryption exception.
return new MalformedMessage(header.MessageId, parameters.UserName);
}
var code = body[3].TypeCode;
if (code == SnmpType.Sequence)
{
// v3 not encrypted
scope = new Scope((Sequence)body[3]);
}
else if (code == SnmpType.OctetString)
{
// v3 encrypted
try
{
scope = new Scope((Sequence)privacy.Decrypt(body[3], parameters));
}
catch (DecryptionException)
{
// handle decryption exception.
return new MalformedMessage(header.MessageId, parameters.UserName);
}
}
else
{
throw new SnmpException(string.Format(CultureInfo.InvariantCulture, "invalid v3 packets scoped data: {0}", code));
}
if (!privacy.AuthenticationProvider.VerifyHash(version, header, parameters, body[3], privacy))
{
throw new SnmpException("invalid v3 packet data");
}
}
var scopeCode = scope.Pdu.TypeCode;
switch (scopeCode)
{
case SnmpType.TrapV1Pdu:
return new TrapV1Message(body);
case SnmpType.TrapV2Pdu:
return new TrapV2Message(version, header, parameters, scope, privacy);
case SnmpType.GetRequestPdu:
return new GetRequestMessage(version, header, parameters, scope, privacy);
case SnmpType.ResponsePdu:
return new ResponseMessage(version, header, parameters, scope, privacy, false);
case SnmpType.SetRequestPdu:
return new SetRequestMessage(version, header, parameters, scope, privacy);
case SnmpType.GetNextRequestPdu:
return new GetNextRequestMessage(version, header, parameters, scope, privacy);
case SnmpType.GetBulkRequestPdu:
return new GetBulkRequestMessage(version, header, parameters, scope, privacy);
case SnmpType.ReportPdu:
return new ReportMessage(version, header, parameters, scope, privacy);
case SnmpType.InformRequestPdu:
return new InformRequestMessage(version, header, parameters, scope, privacy);
default:
throw new SnmpException(string.Format(CultureInfo.InvariantCulture, "unsupported pdu: {0}", scopeCode));
}
}