Skip to content

Commit

Permalink
implement should execture
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Jul 14, 2023
1 parent 40d8c76 commit 5e244f1
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,35 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Security.Cryptography;

namespace SonarAnalyzer.SymbolicExecution.Roslyn.RuleChecks.CSharp;

public sealed class InitializationVectorShouldBeRandom : InitializationVectorShouldBeRandomBase
{
public static readonly DiagnosticDescriptor S3329 = DescriptorFactory.Create(DiagnosticId, MessageFormat);
protected override DiagnosticDescriptor Rule => S3329;

public override bool ShouldExecute() => true;
public override bool ShouldExecute()
{
var walker = new Walker();
walker.SafeVisit(Node);
return walker.Result;
}

private sealed class Walker : SafeCSharpSyntaxWalker
{
public bool Result { get; private set; }

public override void Visit(SyntaxNode node)
{
if (!Result)
{
base.Visit(node);
}
}

public override void VisitInvocationExpression(InvocationExpressionSyntax node) =>
Result = node.GetIdentifier().GetValueOrDefault() is { } methodName && methodName.ValueText.Equals(nameof(SymmetricAlgorithm.CreateEncryptor));
}
}

0 comments on commit 5e244f1

Please sign in to comment.