Esempio n. 1
0
        public SourceAndMetadata(IEntropySource source, string uniqueName)
        {
            Source     = source ?? throw new ArgumentNullException(nameof(source));
            UniqueName = uniqueName ?? throw new ArgumentNullException(nameof(uniqueName));
#if NETSTANDARD1_3
            AsyncHint = IsAsync.Unknown;
#else
            var maybeHintAttribute = source.GetType().GetCustomAttributesData().FirstOrDefault(x => x.AttributeType == typeof(AsyncHintAttribute));
            if (maybeHintAttribute != null)
            {
                AsyncHint = (IsAsync)maybeHintAttribute.ConstructorArguments.First(x => x.ArgumentType == typeof(IsAsync)).Value;
            }
#endif
            if (AsyncHint == IsAsync.AfterInit)
            {
                AsyncScore = -8;
            }
            else if (AsyncHint == IsAsync.Never)
            {
                AsyncScore = -10;
            }
            else if (AsyncHint == IsAsync.Rarely)
            {
                AsyncScore = 5;
            }
            else
            {
                AsyncScore = 10;
            }
        }
Esempio n. 2
0
        private async Task FuzzEntropySource(int iterations, IEntropySource source, string filename, Action extra)
        {
            using (var sw = new StreamWriter(filename + ".txt", false, Encoding.UTF8))
            {
                await sw.WriteLineAsync($"{source.GetType().FullName} - {iterations:N0} iterations");

                for (int i = 0; i < iterations; i++)
                {
                    var bytes = await source.GetEntropyAsync(EntropyPriority.High);

                    if (bytes == null)
                    {
                        await sw.WriteLineAsync("<null>");
                    }
                    else
                    {
                        await sw.WriteLineAsync(bytes.ToHexString());
                    }
                    extra();
                }
            }
        }