using System; using System.Collections.Generic; using System.Security.Cryptography; public class Nest01 { private readonly SHA256 _sha; public Nest01() { _sha = SHA256.Create(); } } public class Nest02 { private readonly Nest01 _n; public Nest02() { _n = new Nest01(); } } public class ListNonStatic { private List _shaList; public ListNonStatic() { _shaList = new List(); } } /// /// Positive results (classes are not thread safe) /// public class Nest03 { private static readonly Nest01 _n = new Nest01(); } public class Nest04 { static ListNonStatic _list = new ListNonStatic(); } public static class StaticMemberChildUsage { public enum DigestAlgorithm { SHA1, SHA256, } private static readonly IDictionary HashMap = new Dictionary { { DigestAlgorithm.SHA1, SHA1.Create() }, { DigestAlgorithm.SHA256, SHA256.Create() }, }; } public class StaticMember { private static SHA1 _sha1 = SHA1.Create(); } public class IndirectStatic2 { static Nest02 _n = new Nest02(); } /// /// Should not be flagged (thread safe) /// public class IndirectStatic { StaticMember tc; } public class TokenCacheFP { /// /// Should be OK. Not shared between threads /// [ThreadStatic] private static SHA1 _sha1 = SHA1.Create(); private string ComputeHash(string password) { return password; } } public class TokenCacheNonStat { /// /// Should be OK. Not shared between threads /// private SHA1 _sha1; public TokenCacheNonStat() { _sha1 = SHA1.Create(); } private string ComputeHash(string password) { return password; } } public class FuncTest { /// /// Should be OK. Does not store the field. /// public static Func function; }