Summary

Class:ProjectX.Services.CryptoService
Assembly:ProjectX
File(s):C:\private\projects\projectx\backend\src\ProjectX\Services\CryptoService.cs
Covered lines:10
Uncovered lines:1
Coverable lines:11
Total lines:43
Line coverage:90.9%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
GenerateCode(...)10100100
GenerateHash()10100100
VerifyHash()1000

File(s)

C:\private\projects\projectx\backend\src\ProjectX\Services\CryptoService.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using ServiceBase;
 4using ServiceBase.Extensions;
 5
 6namespace ProjectX.Services
 7{
 8    public class CryptoService
 9    {
 10        private const string _chars = "0123456789";
 11        private readonly Random _random;
 12        private readonly IDateTimeAccessor _dateTimeAccessor;
 13
 314        public CryptoService(IDateTimeAccessor dateTimeAccessor)
 15        {
 316            this._dateTimeAccessor = dateTimeAccessor;
 317            this._random = new Random(this._dateTimeAccessor
 318                .UtcNow.GetUnixTimestamp());
 319        }
 20
 21        public string GenerateCode(int length = 4)
 22        {
 123            return new string(Enumerable.Repeat(_chars, length)
 524              .Select(s => s[this._random.Next(s.Length)]).ToArray());
 25        }
 26
 27        // https://stackoverflow.com/questions/7444586/how-can-i-sign-a-file-using-rsa-and-sha256-with-net
 28        public string GenerateHash()
 29        {
 30            // Lol, das müsste fürs erste reichen...
 31
 132            var chars = "0123456789asdfghjklqwertzuiopyxcvbnm";
 33
 134            return new string(Enumerable.Repeat(chars, 16)
 1735              .Select(s => s[this._random.Next(s.Length)]).ToArray());
 36        }
 37
 38        public bool VerifyHash()
 39        {
 040            throw new NotImplementedException();
 41        }
 42    }
 43}