Skip to content

Commit

Permalink
couple more nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Jul 20, 2023
1 parent 2cd9d9c commit 5a4f895
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public abstract class HashesShouldHaveUnpredictableSaltBase : CryptographyRuleBa
protected override ProgramState PreProcessSimple(SymbolicContext context)
{
var state = base.PreProcessSimple(context);
var instance = context.Operation.Instance;
if (instance.AsObjectCreation() is { } objectCreation)
if (context.Operation.Instance.AsObjectCreation() is { } objectCreation)
{
ProcessObjectCreation(state, objectCreation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,39 @@ protected override ProgramState PreProcessSimple(SymbolicContext context)
var operation = context.Operation.Instance;
if (operation.AsAssignment() is { } assignment)
{
return ProcessAssignmentToIVProperty(state, assignment) ?? state;
return ProcessAssignmentToIVProperty(state, assignment);
}
else if (operation.AsPropertyReference() is { } property
&& property.Instance is { } propertyInstance
&& state.ResolveCaptureAndUnwrapConversion(propertyInstance).TrackedSymbol() is { } propertyInstanceSymbol
&& IsIVProperty(property, propertyInstanceSymbol)
&& state[propertyInstance]?.Constraint<ByteCollectionConstraint>() is { } constraint)
else if (operation.AsPropertyReference() is { } property)
{
return state.SetOperationConstraint(property, constraint);
return ProcessProperyReference(state, property);
}
else if (operation.AsInvocation() is { } invocation)
{
return ProcessGenerateIV(state, invocation)
?? ProcessCreateEncryptorMethodInvocation(state, invocation)
?? state;
?? ProcessCreateEncryptorMethodInvocation(state, invocation);
}
else
{
return state;
}
}

private static ProgramState ProcessProperyReference(ProgramState state, IPropertyReferenceOperationWrapper property) =>
property.Instance is { } propertyInstance
&& state.ResolveCaptureAndUnwrapConversion(propertyInstance).TrackedSymbol() is { } propertyInstanceSymbol
&& IsIVProperty(property, propertyInstanceSymbol)
&& state[propertyInstance]?.Constraint<ByteCollectionConstraint>() is { } constraint
? state.SetOperationConstraint(property, constraint)
: state;

private static ProgramState ProcessAssignmentToIVProperty(ProgramState state, IAssignmentOperationWrapper assignment) =>
assignment.Target?.AsPropertyReference() is { } property
&& property.Instance is { } propertyInstance
&& state.ResolveCaptureAndUnwrapConversion(propertyInstance).TrackedSymbol() is { } propertyInstanceSymbol
&& IsIVProperty(property, propertyInstanceSymbol)
&& state[assignment.Value]?.HasConstraint(ByteCollectionConstraint.CryptographicallyWeak) is true
? state.SetSymbolConstraint(propertyInstanceSymbol, ByteCollectionConstraint.CryptographicallyWeak)
: null;
: state;

private static ProgramState ProcessGenerateIV(ProgramState state, IInvocationOperationWrapper invocation) =>
invocation.TargetMethod.Name == nameof(SymmetricAlgorithm.GenerateIV)
Expand Down

0 comments on commit 5a4f895

Please sign in to comment.