Example #1
0
 public static ExpressionOpObj Find(ExpressionOp symbol)
 {
     return(Operators.FirstOrDefault(op => op.Symbol == symbol));
 }
		protected override void UnpackageData(ReadingContext SR, UInt32 Length)
		{
			if (Length > 0)
			{
				UInt32 ExpressionVal = SR.ReadUInt32();
				if (ExpressionVal == kReqExpression)
				{
					Expression = ExpressionOp.ReadOperand(SR);
				}
			}
		}
		protected void InitializeFromCert(X509Certificate2 SigningCert, string Bundle, ExpressionOp OldReq = null)
		{
			BundleIdentifier = Bundle;
			int StartIndex = SigningCert.SubjectName.Name.IndexOf("CN=");
			int EndIndex = -1;
			CertificateName = "";
			if (StartIndex > -1)
			{
				// find the next attribute
				StartIndex += 3;
				char SearchChar = ',';
				if (SigningCert.SubjectName.Name[StartIndex] == '\"')
				{
					// quotes are around the string because of special characters
					StartIndex++;
					SearchChar = '\"';
				}
				EndIndex = SigningCert.SubjectName.Name.IndexOf(SearchChar, StartIndex);
				if (EndIndex == -1)
				{
					// must be at the end, so go to the end
					EndIndex = SigningCert.SubjectName.Name.Length;
					if (SearchChar == '\"')
					{
						EndIndex--;
					}
				}
				// get the string
				CertificateName = SigningCert.SubjectName.Name.Substring(StartIndex, EndIndex - StartIndex);
			}
			if (string.IsNullOrEmpty(CertificateName))
			{
				CertificateName = SigningCert.FriendlyName;
			}

			// always use the new  requirements when initializing from cert
			Expression = new AndOp();
			(Expression as AndOp).Op1 = new IdentOp();
			((Expression as AndOp).Op1 as IdentOp).BundleIdentifier = BundleIdentifier;
			(Expression as AndOp).Op2 = new AndOp();
			((Expression as AndOp).Op2 as AndOp).Op1 = new ExpressionOp(kOpGenericAnchor);
			((Expression as AndOp).Op2 as AndOp).Op2 = new AndOp();
			(((Expression as AndOp).Op2 as AndOp).Op2 as AndOp).Op1 = new CertFieldOp();
			(((Expression as AndOp).Op2 as AndOp).Op2 as AndOp).Op2 = new CertGenericOp();
		}
		public static RequirementBlob CreateFromCertificate(X509Certificate2 SigningCert, string Bundle, ExpressionOp OldReq = null)
		{
			RequirementBlob Blob = new RequirementBlob();
			Blob.InitializeFromCert(SigningCert, Bundle, OldReq);
			return Blob;
		}
			public override void ReadData(ReadingContext SR)
			{
				Op1 = ExpressionOp.ReadOperand(SR);
				Op2 = ExpressionOp.ReadOperand(SR);
			}
			static public ExpressionOp ReadOperand(ReadingContext SR)
			{
				UInt32 OpVal = SR.ReadUInt32();
				ExpressionOp Op = null;
				switch (OpVal)
				{
					case kOpAnd:
						Op = new AndOp();
						break;

					case kOpIdent:
						Op = new IdentOp();
						break;

					case kOpGenericAnchor:
						Op = new ExpressionOp(OpVal);
						break;

					case kOpCertField:
						Op = new CertFieldOp();
						break;

					case kOpCertGeneric:
						Op = new CertGenericOp();
						break;

					case kOpAnchorHash:
						Op = new AnchorHashOp();
						break;

					default:
						throw new Exception("Unknown Expression Operand: " + OpVal.ToString());
				}

				Op.ReadData(SR);
				return Op;
			}