当前位置: 首页>>代码示例>>C#>>正文


C# UserRegistry.Find方法代码示例

本文整理汇总了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));
			}
		}
开发者ID:moljac,项目名称:MonoMobile.SharpSNMP,代码行数:97,代码来源:MessageFactory.cs


注:本文中的Lextm.SharpSnmpLib.Security.UserRegistry.Find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。