private Task<IPolicyExpression> ParseLexicon(string lexicon) { return Task.Run(() => { var parser = new SimpleTextV1LexiconPolicyParser(); return parser.Parse(lexicon.ToStream()); }); }
public void testParse_extraniousOperator_assertGrammarException() { using (Stream stream = "1 = 1 =".ToStream()) { var parser = new SimpleTextV1LexiconPolicyParser(); Assert.Throws<PolicyGrammarException>(() => parser.Parse(stream)); } }
public void TestParse_NoOperator_AssertGrammarException() { using (Stream stream = "(1".ToStream()) { var parser = new SimpleTextV1LexiconPolicyParser(); Assert.Throws<PolicyGrammarException>(() => parser.Parse(stream)); } }
public Boolean IsValidLexicon(CertPolicy policy) { try { //might get parser from policy.Lexicon in the future var parser = new SimpleTextV1LexiconPolicyParser(); parser.Parse(policy.Data.ToMemoryStream()); return true; } catch (Exception) { return false; } }
public IPolicyExpression GetPolicyExpression(byte[] policy) { try { //might get parser from policy.Lexicon in the future var parser = new SimpleTextV1LexiconPolicyParser(); IPolicyExpression expression = parser.Parse(policy.ToMemoryStream()); return expression; } catch (Exception) { return null; } }
public void TestExtensionBasicContraint_CA_AssertTrue() { var parser = new SimpleTextV1LexiconPolicyParser(); using (Stream stream = ("X509.TBS.EXTENSION.BasicConstraints.CA = true").ToStream()) { IList<SimpleTextV1LexiconPolicyParser.TokenTypeAssociation> tokens = parser.ParseToTokens(stream); tokens.Count.Should().Be(3); } using (Stream stream = ("X509.TBS.EXTENSION.BasicConstraints.CA = true").ToStream()) { IPolicyExpression expression = parser.Parse(stream); expression.Should().BeAssignableTo<OperationPolicyExpression>(); var operationPolicyExpression = expression as OperationPolicyExpression; operationPolicyExpression.GetOperands().Count.Should().Be(2); } }