Beispiel #1
0
        private void BenchmarkTransfer()
        {
            this.butStart.Enabled = false;

            {
                ICompareService comparer = CreateComparer(TransportProtocolEnum.Http);
                comparer.SetClientCredentials("lnpair", "lnpair", "wsdev");
                comparer.DataSent += new EventHandler <DataSentArgs>(comparer_CompareProgress);

                comparer.BenchmarkTransferAsync(1024 * 1024, 50 * 1024 * 1024);
            }

            //{
            //    ICompareService comparer = CreateComparer( TransportProtocolEnum.Tcp );
            //    comparer.SetClientCredentials( "lnpair", "lnpair", "wsdev" );
            //    comparer.DataSent += new EventHandler<DataSentArgs>( comparer_CompareProgress );

            //    comparer.BenchmarkTransferAsync( 1024 * 1024, 50 * 1024 * 1024 );
            //}

            //{
            //    ICompareService comparer = CreateComparer( TransportProtocolEnum.NamedPipe );
            //    comparer.SetClientCredentials( "lnpair", "lnpair", "wsdev" );
            //    comparer.DataSent += new EventHandler<DataSentArgs>( comparer_CompareProgress );

            //    comparer.BenchmarkTransferAsync( 1024 * 1024, 50 * 1024 * 1024 );
            //}
        }
 public FileWalkerTests()
 {
     _compareService    = Substitute.For <ICompareService>();
     _configService     = Substitute.For <IConfigService>();
     _fileSystemService = Substitute.For <IFileSystemService>();
     _fileWalker        = new FileWalker(_compareService, _configService, _fileSystemService);
 }
        private static unsafe bool Loop23Hash(uint *pt, byte *tmp, ICompareService comparer)
        {
            // The added value below is the fixed first char('S')=0x53 shifted left 24 places
            pt[8]  = 0b01010011_00000000_00000000_00000000U | (uint)tmp[1] << 16 | (uint)tmp[2] << 8 | tmp[3];
            pt[9]  = (uint)tmp[4] << 24 | (uint)tmp[5] << 16 | (uint)tmp[6] << 8 | tmp[7];
            pt[10] = (uint)tmp[8] << 24 | (uint)tmp[9] << 16 | (uint)tmp[10] << 8 | tmp[11];
            pt[11] = (uint)tmp[12] << 24 | (uint)tmp[13] << 16 | (uint)tmp[14] << 8 | tmp[15];
            pt[12] = (uint)tmp[16] << 24 | (uint)tmp[17] << 16 | (uint)tmp[18] << 8 | tmp[19];
            // The added value below is the SHA padding and the last added ? char equal to 0x3f shifted right 8 places
            pt[13] = (uint)tmp[20] << 24 | (uint)tmp[21] << 16 | 0b00000000_00000000_00111111_10000000U;
            // from 6 to 14 = 0
            pt[23] = 184; // 23 *8 = 184

            Sha256Fo.Init(pt);
            Sha256Fo.Compress23(pt);

            if ((pt[0] & 0b11111111_00000000_00000000_00000000U) == 0)
            {
                // The actual key is SHA256 of 22 char key (without '?')
                // SHA working vector is already set, only the last 2 bytes ('?' and pad) and the length have to change
                pt[13] ^= 0b00000000_00000000_10111111_10000000U;
                // from 6 to 14 (remain) = 0
                pt[23] = 176; // 22 *8 = 176

                Sha256Fo.Init(pt);
                Sha256Fo.Compress22(pt);

                return(comparer.Compare(pt));
            }
Beispiel #4
0
 public FileWalker(ICompareService compareService, IConfigService configService,
                   IFileSystemService fileSystemService)
 {
     _compareService    = compareService;
     _fileSystemService = fileSystemService;
     _filterExtension   = configService.GetFilterExtension();
 }
 public ComparePageService(ICompareService compareAppService, ICartService cartAppService, IMapper mapper, ILogger <ComparePageService> logger)
 {
     _compareAppService = compareAppService ?? throw new ArgumentNullException(nameof(compareAppService));
     _cartAppService    = cartAppService ?? throw new ArgumentNullException(nameof(cartAppService));
     _mapper            = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public CompareViewModel()
 {
     _service = ClassFactory.GetInstance <ICompareService>();
     _appInfo = new AppInfo();
     DicError.Add(1, "对象不一致");
     DicError.Add(2, "对象丢失");
     DicError.Add(3, "对象冗余");
 }
Beispiel #7
0
 public SwaggerDiffController(ILogger <SwaggerDiffController> logger, IInitializationService initializationService, IClientRequestService clientRequestService, ICompareService compareService, IDocumentationStoreService documentationStoreService)
 {
     _logger = logger;
     _initializationService     = initializationService;
     _clientRequestService      = clientRequestService;
     _compareService            = compareService;
     _documentationStoreService = documentationStoreService;
 }
Beispiel #8
0
 public DuplicateFinder(ICompareService compareService, IFileWalker fileWalker,
                        IFileSystemService fileSystemServices, IConfigService configService)
 {
     _compareService     = compareService;
     _fileWalker         = fileWalker;
     _fileSystemServices = fileSystemServices;
     _configService      = configService;
 }
Beispiel #9
0
 public ProductPageService(IProductService productAppService, ICategoryService categoryAppService, ICartService cartAppService, IWishlistService wishlistAppService, ICompareService compareAppService, IMapper mapper, ILogger <ProductPageService> logger)
 {
     _productAppService  = productAppService ?? throw new ArgumentNullException(nameof(productAppService));
     _categoryAppService = categoryAppService ?? throw new ArgumentNullException(nameof(categoryAppService));
     _cartAppService     = cartAppService ?? throw new ArgumentNullException(nameof(cartAppService));
     _wishlistAppService = wishlistAppService ?? throw new ArgumentNullException(nameof(wishlistAppService));
     _compareAppService  = compareAppService ?? throw new ArgumentNullException(nameof(compareAppService));
     _mapper             = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        /// <summary>
        /// Actually calls into Control.dll to perform comparison. This call fires DataSent event and
        /// ComparisonStarted event. We need to set the client credentials for the call before it's executed.
        /// </summary>
        /// <param name="originalFile"></param>
        /// <param name="modifiedFile"></param>
        /// <param name="optionSet"></param>
        /// <param name="responseOptions"></param>
        /// <param name="uploadInfo"></param>
        /// <returns></returns>
        private CompareResults DoComparison(HttpPostedFile originalPostedFile, HttpPostedFile modifiedPostedFile, string optionSet, ResponseOptions responseOptions, ref UploadInfo uploadInfo)
        {
            ICompareService compareService = CreateAppropriateService();

            compareService.ComparisonStarted += new EventHandler(CompareService_OnComparisonStarted);
            compareService.DataSent          += new EventHandler <DataSentArgs>(CompareService_OnDataSent);

            uploadInfo.IsReady         = true;
            uploadInfo.PercentComplete = 10;
            uploadInfo.Message         = "Authenticating request ...";

            string username = (string)Session["UserName"];
            string domain   = (string)Session["Domain"];
            string password = (string)Session["Passw"];

            password = CodePassword(password);
            compareService.SetClientCredentials(username, password, domain);

            string serviceVersion;
            string compositorVersion;

            if (!compareService.VerifyConnection(out serviceVersion, out compositorVersion))
            {
                uploadInfo.IsReady = false;
                return(null);
            }

            uploadInfo.PercentComplete = 15;
            uploadInfo.Message         = "Authentication was successful ... reading files";

            uploadInfo.PercentComplete = 20;
            uploadInfo.Message         = "Chunking files ...";

            compareService.CompareOptions   = optionSet;
            compareService.ComparisonOutput = responseOptions;
            compareService.UseChunking      = true;
            compareService.ChunkSize        = _chunkSize;

            var originalFile = originalPostedFile.InputStream;
            var modifiedFile = modifiedPostedFile.InputStream;

            originalFile.Seek(0, SeekOrigin.Begin);
            modifiedFile.Seek(0, SeekOrigin.Begin);

            // As _lastModifiedFileIndex is zero-based, so increment it befor displaying
            uploadInfo.PairInfo = "Comparing File Pair " + (_lastModifiedFileIndex + 1).ToString();

            CompareResults results = compareService.CompareEx(originalFile, modifiedFile, CreateDocumentInfo(originalPostedFile.FileName), CreateDocumentInfo(modifiedPostedFile.FileName));

            uploadInfo.PercentComplete = 100;
            uploadInfo.Message         = "Comparison completed ...";
            uploadInfo.IsReady         = false;

            return(results);
        }
Beispiel #11
0
    public DuplicateFinderTests()
    {
        _fileWalker        = Substitute.For <IFileWalker>();
        _compareService    = Substitute.For <ICompareService>();
        _fileSystemService = Substitute.For <IFileSystemService>();
        _fileDetailService = Substitute.For <IFileDetailService>();
        _configService     = Substitute.For <IConfigService>();

        _duplicateFinder =
            new DuplicateFinder.DuplicateFinder(_compareService, _fileWalker, _fileSystemService, _configService);
    }
Beispiel #12
0
 public bool TryGetCompareService(InputType inType, string input, out ICompareService result)
 {
     result = inType switch
     {
         InputType.AddrComp => new PrvToAddrCompComparer(),
         InputType.AddrUnComp => new PrvToAddrUncompComparer(),
         InputType.AddrBoth => new PrvToAddrBothComparer(),
         InputType.AddrNested => new PrvToAddrNestedComparer(),
         InputType.Pubkey => new PrvToPubComparer(),
         InputType.PrivateKey => new PrvToPrvComparer(),
         _ => null
     };
     return(!(result is null) && result.Init(input));
 }
        public void CloneTest()
        {
            PrvToAddrNestedComparer original = new();

            Assert.True(original.Init(KeyHelper.Pub1NestedSegwit)); // Make sure it is successfully initialized
            ICompareService cloned = original.Clone();

            // Change original field value to make sure it is cloned not a reference copy
            Assert.True(original.Init(KeyHelper.Pub2NestedSegwit));

            byte[] key = KeyHelper.Prv1.ToBytes();

            // Since the original was changed it should fail when comparing
            Assert.False(original.Compare(key));
            Assert.True(cloned.Compare(key));
        }
Beispiel #14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                // Only activated if postedback
                // Dont do anything on startup

                if (this.IsPostBack)
                {
                    TransportProtocolEnum transportProtocol = (TransportProtocolEnum)Enum.Parse(typeof(TransportProtocolEnum), this.Protocol.Text, true);
                    int chunkingSize = 512;
                    try
                    {
                        if (this.Chunksize.Text != null)
                        {
                            chunkingSize = Convert.ToInt32(this.Chunksize.Text);
                        }
                    }
                    catch
                    {
                        chunkingSize = 512;
                    }

                    ICompareService cp = CreateAppropriateService(transportProtocol);

                    string user   = (string)Session["UserName"];
                    string pass   = CodePassword((string)Session["Passw"]);
                    string domain = (string)Session["Domain"];

                    cp.SetClientCredentials(user, pass, domain);

                    // We need to hook into this event to calculate the progress and data rate.
                    cp.DataSent += new EventHandler <DataSentArgs>(CompareService_OnDataSent);

                    //Call into benchmarking with specified chunk size and 40 MB of dummy data
                    cp.BenchmarkTransfer(chunkingSize * 1024, 40 * 1024 * 1024);
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }
Beispiel #15
0
        public static bool AreSame(this ICompareService compareService, string file1, string file2)
        {
            if (string.IsNullOrWhiteSpace(file1))
            {
                throw new ArgumentNullException("file1");
            }

            if (string.IsNullOrWhiteSpace(file2))
            {
                throw new ArgumentNullException("file2");
            }

            //var f1 = new File(file1);
            //var f2 = new File(file2);

            //return compareService.AreSame(f1, f2);

            return(false);
        }
Beispiel #16
0
        private void BenchmarkCompare()
        {
            System.IO.FileStream fsOriginal = System.IO.File.OpenRead(this.textOriginalFile.Text);
            System.IO.FileStream fsModified = System.IO.File.OpenRead(this.textModifiedFile.Text);

            ICompareService comparer = CreateComparer(TransportProtocolEnum.Http);

            comparer.SetClientCredentials("lnpair", "lnpair", "wsdev");
            comparer.SetTimeouts(1, 1, 10, 10);

            comparer.DataSent += new EventHandler <DataSentArgs>(comparer_CompareProgress);

            PerformanceResults result = comparer.BenchmarkCompare(fsOriginal, fsModified);

            this.labelOriginalConversionTime.Text = result.OriginalConversionTime.TotalMilliseconds + " ms";
            this.labelModifiedConversionTime.Text = result.ModifiedConversionTime.TotalMilliseconds + " ms";
            this.labelOriginalPreTime.Text        = result.OriginalPreProcessingTime.TotalMilliseconds + " ms";
            this.labelModifiedPreTime.Text        = result.ModifiedPreProcessingTime.TotalMilliseconds + " ms";
            this.labelComparisonTime.Text         = result.ComparisonTime.TotalMilliseconds + " ms";
            this.labelResultsTime.Text            = result.ResultsProcessingTime.TotalMilliseconds + " ms";

            this.labelTotal.Text = result.TotalExecutionTime.TotalMilliseconds + " ms";
        }
Beispiel #17
0
 public CompareController(ICompareService service, IOptions <ApiConfig> configuration)
 {
     _service       = service;
     _configuration = configuration.Value;
 }
Beispiel #18
0
 public HallsController(IHallsRepository exhibitRepository, IHallsService hallsService, ICompareService compareService)
 {
     _hallsRepository = exhibitRepository;
     _hallsService    = hallsService;
     _compareService  = compareService;
 }
Beispiel #19
0
 public CompareModel(ICompareService compareService, ITuristPlaceService turistPlaceService)
 {
     this.compareService     = compareService;
     this.turistPlaceService = turistPlaceService;
 }
Beispiel #20
0
 public DiffController(ICompareService service)
 {
     _service = service;
 }
 public CompareHandler(ICompareService compareService, IReportService reportService)
 {
     this.compareService = compareService;
     this.reportService  = reportService;
 }
Beispiel #22
0
 public CompareController(ICompareService compareService, IMapper mapper)
 {
     Service = compareService;
     Mapper  = mapper;
 }
Beispiel #23
0
        public unsafe bool SetBip32(ulong *bigBuffer, ICompareService comparer)
        {
            ulong *hPt    = bigBuffer;
            ulong *wPt    = hPt + Sha512Fo.HashStateSize;
            ulong *seedPt = wPt + Sha512Fo.WorkingVectorSize;
            ulong *iPt    = seedPt + Sha512Fo.HashStateSize;
            ulong *oPt    = iPt + Sha512Fo.WorkingVectorSize;

            // *** BIP32 ***
            // Set from entropy/seed by computing HMAC(data=seed, key="Bitcoin seed")

            // Final result is SHA512(outer_pad | SHA512(inner_pad | data)) where data is 64-byte seed
            // 1. Compute SHA512(inner_pad | data)
            Sha512Fo.Init_InnerPad_Bitcoinseed(hPt);
            *(Block64 *)wPt = *(Block64 *)seedPt;
            // from wPt[8] to wPt[15] didn't change
            Sha512Fo.Compress192SecondBlock(hPt, wPt);

            // 2. Compute SHA512(outer_pad | hash)
            *(Block64 *)wPt = *(Block64 *)hPt; // ** Copy hashState before changing it **
                                               // from wPt[8] to wPt[15] didn't change
            Sha512Fo.Init_OuterPad_Bitcoinseed(hPt);
            Sha512Fo.Compress192SecondBlock(hPt, wPt);
            // Master key is set. PrivateKey= first 32-bytes of hPt and ChainCode is second 32-bytes

            // Each child is derived by computing HMAC(data=(hardened? 0|prvKey : pubkey) | index, key=ChainCode)
            // ChainCode is the second 32-byte half of the hash. Set pad items that never change here:
            // TODO: this part can be set by the caller outside its loop
            iPt[4]  = 0x3636363636363636U;
            iPt[5]  = 0x3636363636363636U;
            iPt[6]  = 0x3636363636363636U;
            iPt[7]  = 0x3636363636363636U;
            iPt[8]  = 0x3636363636363636U;
            iPt[9]  = 0x3636363636363636U;
            iPt[10] = 0x3636363636363636U;
            iPt[11] = 0x3636363636363636U;
            iPt[12] = 0x3636363636363636U;
            iPt[13] = 0x3636363636363636U;
            iPt[14] = 0x3636363636363636U;
            iPt[15] = 0x3636363636363636U;

            oPt[4]  = 0x5c5c5c5c5c5c5c5cU;
            oPt[5]  = 0x5c5c5c5c5c5c5c5cU;
            oPt[6]  = 0x5c5c5c5c5c5c5c5cU;
            oPt[7]  = 0x5c5c5c5c5c5c5c5cU;
            oPt[8]  = 0x5c5c5c5c5c5c5c5cU;
            oPt[9]  = 0x5c5c5c5c5c5c5c5cU;
            oPt[10] = 0x5c5c5c5c5c5c5c5cU;
            oPt[11] = 0x5c5c5c5c5c5c5c5cU;
            oPt[12] = 0x5c5c5c5c5c5c5c5cU;
            oPt[13] = 0x5c5c5c5c5c5c5c5cU;
            oPt[14] = 0x5c5c5c5c5c5c5c5cU;
            oPt[15] = 0x5c5c5c5c5c5c5c5cU;

            Scalar sclrParent = new(hPt, out int overflow);

            if (overflow != 0)
            {
                return(false);
            }

            foreach (uint index in path.Indexes)
            {
                if ((index & 0x80000000) != 0) // IsHardened
                {
                    // First _byte_ is zero
                    // private-key is the first 32 bytes (4 items) of hPt (total 33 bytes)
                    // 4 bytes index + SHA padding are also added
                    wPt[0] = (ulong)sclrParent.b7 << 24 | (ulong)sclrParent.b6 >> 8;
                    wPt[1] = (ulong)sclrParent.b6 << 56 | (ulong)sclrParent.b5 << 24 | (ulong)sclrParent.b4 >> 8;
                    wPt[2] = (ulong)sclrParent.b4 << 56 | (ulong)sclrParent.b3 << 24 | (ulong)sclrParent.b2 >> 8;
                    wPt[3] = (ulong)sclrParent.b2 << 56 | (ulong)sclrParent.b1 << 24 | (ulong)sclrParent.b0 >> 8;
                    wPt[4] = (ulong)sclrParent.b0 << 56 |
                             (ulong)index << 24 |
                             0b00000000_00000000_00000000_00000000_00000000_10000000_00000000_00000000UL;
                }
                else
                {
                    Span <byte> pubkeyBytes = comparer.Calc.GetPubkey(sclrParent, true);
                    fixed(byte *pubXPt = &pubkeyBytes[0])
                    {
                        wPt[0] = (ulong)pubXPt[0] << 56 |
                                 (ulong)pubXPt[1] << 48 |
                                 (ulong)pubXPt[2] << 40 |
                                 (ulong)pubXPt[3] << 32 |
                                 (ulong)pubXPt[4] << 24 |
                                 (ulong)pubXPt[5] << 16 |
                                 (ulong)pubXPt[6] << 8 |
                                 pubXPt[7];
                        wPt[1] = (ulong)pubXPt[8] << 56 |
                                 (ulong)pubXPt[9] << 48 |
                                 (ulong)pubXPt[10] << 40 |
                                 (ulong)pubXPt[11] << 32 |
                                 (ulong)pubXPt[12] << 24 |
                                 (ulong)pubXPt[13] << 16 |
                                 (ulong)pubXPt[14] << 8 |
                                 pubXPt[15];
                        wPt[2] = (ulong)pubXPt[16] << 56 |
                                 (ulong)pubXPt[17] << 48 |
                                 (ulong)pubXPt[18] << 40 |
                                 (ulong)pubXPt[19] << 32 |
                                 (ulong)pubXPt[20] << 24 |
                                 (ulong)pubXPt[21] << 16 |
                                 (ulong)pubXPt[22] << 8 |
                                 pubXPt[23];
                        wPt[3] = (ulong)pubXPt[24] << 56 |
                                 (ulong)pubXPt[25] << 48 |
                                 (ulong)pubXPt[26] << 40 |
                                 (ulong)pubXPt[27] << 32 |
                                 (ulong)pubXPt[28] << 24 |
                                 (ulong)pubXPt[29] << 16 |
                                 (ulong)pubXPt[30] << 8 |
                                 pubXPt[31];
                        wPt[4] = (ulong)pubXPt[32] << 56 |
                                 (ulong)index << 24 |
                                 0b00000000_00000000_00000000_00000000_00000000_10000000_00000000_00000000UL;
                    }
                }

                wPt[5]  = 0;
                wPt[6]  = 0;
                wPt[7]  = 0;
                wPt[8]  = 0;
                wPt[9]  = 0;
                wPt[10] = 0;
                wPt[11] = 0;
                wPt[12] = 0;
                wPt[13] = 0;
                wPt[14] = 0;
                wPt[15] = 1320; // (1+32+4 + 128)*8

                // Final result is SHA512(outer_pad | SHA512(inner_pad | 37_byte_data))
                // 1. Compute SHA512(inner_pad | 37_byte_data)
                // Set pads to be used as working vectors (key is ChainCode that is the second 32 bytes of SHA512
                iPt[0] = 0x3636363636363636U ^ hPt[4];
                iPt[1] = 0x3636363636363636U ^ hPt[5];
                iPt[2] = 0x3636363636363636U ^ hPt[6];
                iPt[3] = 0x3636363636363636U ^ hPt[7];

                oPt[0] = 0x5c5c5c5c5c5c5c5cU ^ hPt[4];
                oPt[1] = 0x5c5c5c5c5c5c5c5cU ^ hPt[5];
                oPt[2] = 0x5c5c5c5c5c5c5c5cU ^ hPt[6];
                oPt[3] = 0x5c5c5c5c5c5c5c5cU ^ hPt[7];

                Sha512Fo.Init(hPt);
                Sha512Fo.SetW(iPt);
                Sha512Fo.CompressBlockWithWSet(hPt, iPt);
                Sha512Fo.Compress165SecondBlock(hPt, wPt);

                // 2. Compute SHA512(outer_pad | hash)
                *(Block64 *)wPt = *(Block64 *)hPt;
                wPt[8]          = 0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000UL;
                wPt[9]          = 0;
                wPt[10]         = 0;
                wPt[11]         = 0;
                wPt[12]         = 0;
                wPt[13]         = 0;
                wPt[14]         = 0;
                wPt[15]         = 1536; // (128+64)*8

                Sha512Fo.Init(hPt);
                Sha512Fo.SetW(oPt);
                Sha512Fo.CompressBlockWithWSet(hPt, oPt);
                Sha512Fo.Compress192SecondBlock(hPt, wPt);

                // New private key is (parentPrvKey + int(hPt)) % order
                sclrParent = sclrParent.Add(new Scalar(hPt, out _), out _);
            }

            // Child extended key (private key + chianCode) should be set by adding the index to the end of the Path
            // and have been computed already
            hPt[0] = (ulong)sclrParent.b7 << 32 | sclrParent.b6;
            hPt[1] = (ulong)sclrParent.b5 << 32 | sclrParent.b4;
            hPt[2] = (ulong)sclrParent.b3 << 32 | sclrParent.b2;
            hPt[3] = (ulong)sclrParent.b1 << 32 | sclrParent.b0;

            return(comparer.Compare(hPt));
        }
Beispiel #24
0
 public StandsController(IStandsRepository exhibitRepository, IStandsService standsService, ICompareService compareService)
 {
     _standsRepository = exhibitRepository;
     _standsService    = standsService;
     _compareService   = compareService;
 }
Beispiel #25
0
 public CompareController(ICompareService compareService)
 {
     this.compareService = compareService;
 }
Beispiel #26
0
 public ExhibitsController(IExhibitsRepository exhibitRepository, IExhibitsService exhibitsService, ICompareService compareService)
 {
     _exhibitsRepository = exhibitRepository;
     _exhibitsService    = exhibitsService;
     _compareService     = compareService;
 }
 public CompareServiceTests()
 {
     compareService = new CompareService();
 }
Beispiel #28
0
        public async Task <bool> Find(string key, string extra, char missingChar)
        {
            report.Init();

            if (!inputService.IsMissingCharValid(missingChar))
            {
                return(report.Fail("Invalid missing character."));
            }
            if (string.IsNullOrWhiteSpace(key) || !key.All(c => ConstantsFO.Base58Chars.Contains(c) || c == missingChar))
            {
                return(report.Fail("Input contains invalid base-58 character(s)."));
            }
            if (!key.StartsWith(ConstantsFO.MiniKeyStart))
            {
                return(report.Fail($"Minikey must start with {ConstantsFO.MiniKeyStart}."));
            }

            comparer = new PrvToAddrBothComparer();
            if (!comparer.Init(extra))
            {
                return(report.Fail("Invalid address."));
            }

            missCount = key.Count(c => c == missingChar);
            if (missCount == 0)
            {
                report.AddMessageSafe("The given input has no missing characters, verifying it as a complete minikey.");
                report.AddMessageSafe(inputService.CheckMiniKey(key));
                return(report.Finalize(true));
            }

            keyToCheck     = key;
            missingIndexes = new int[missCount];

            bool success;

            report.AddMessageSafe($"Total number of minikeys to test: {GetTotalCount(missCount):n0}");
            report.AddMessageSafe("Going throgh each case. Please wait...");
            Stopwatch watch = Stopwatch.StartNew();

            if (key.Length == ConstantsFO.MiniKeyLen1)
            {
                precomputed = new byte[ConstantsFO.MiniKeyLen1];
                PreCompute(missingChar);
                success = await Task.Run(Loop23);
            }
            else if (key.Length == ConstantsFO.MiniKeyLen2)
            {
                precomputed = new byte[ConstantsFO.MiniKeyLen2];
                PreCompute(missingChar);
                success = await Task.Run(Loop27);
            }
            else if (key.Length == ConstantsFO.MiniKeyLen3)
            {
                precomputed = new byte[ConstantsFO.MiniKeyLen3];
                PreCompute(missingChar);
                success = await Task.Run(Loop31);
            }
            else
            {
                return(report.Fail($"Minikey length must be {ConstantsFO.MiniKeyLen1} or {ConstantsFO.MiniKeyLen3}."));
            }

            watch.Stop();
            report.AddMessageSafe($"Elapsed time: {watch.Elapsed}");
            report.SetKeyPerSecSafe(GetTotalCount(missCount), watch.Elapsed.TotalSeconds);

            return(report.Finalize(success));
        }
        /// <summary>
        /// Performs authentication using CompareService
        /// We store the credentials in Session for later use. We also update the UI here.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                ICompareService compareService = CreateAppropriateService();
                compareService.SetClientCredentials(UsernameTextBox.Text, PasswordTextBox.Text, DomainTextBox.Text);

                string serviceVersion;
                string compositorVersion;
                if (compareService.VerifyConnection(out serviceVersion, out compositorVersion))
                {
                    // Store the gems for later use
                    Session["BeenAuthenticated"] = true;
                    Session["Passw"]             = CodePassword(PasswordTextBox.Text);
                    Session["UserName"]          = UsernameTextBox.Text;
                    Session["Domain"]            = DomainTextBox.Text;

                    string versionString = "Service: {0} - Compositor: {1}";
                    versionString = string.Format(versionString, serviceVersion, compositorVersion);
                    CompositorVersionLabel.Text = versionString;

                    ToggleUploadButtonAndStatusPane(true);
                    ShowMessage(GenerateScriptID("auth"), "success", " Authentication succeeded.");

                    UpdatePageUI();
                }
                else
                {
                    Session["BeenAuthenticated"] = false;

                    string message = "Authentication failed for user: {0}";
                    message = string.Format(message, UsernameTextBox.Text);
                    ShowMessage(GenerateScriptID("auth"), "error", message);
                }
            }
            catch (System.Security.SecurityException ex)
            {
                string message = " Credentials provided are either empty or invalid. " + ex.Message;
                ShowMessage(GenerateScriptID("auth"), "error", message);
            }
            catch (System.ServiceModel.EndpointNotFoundException ex)
            {
                string message = " Either Compare Service is not running or host/port address is invalid. " + ex.Message;
                ShowMessage(GenerateScriptID("auth"), "error", message);
            }
            catch (TimeoutException ex)
            {
                string message = " The connection between server and client was lost because of a timeout. " + ex.Message;
                ShowMessage(GenerateScriptID("auth"), "error", message);
            }
            catch (System.ServiceModel.ServerTooBusyException ex)
            {
                string message = " Too many simultaneous requests. Try again after a while. " + ex.Message;
                ShowMessage(GenerateScriptID("auth"), "error", message);
            }
            catch (System.ServiceModel.FaultException <string> ex)
            {
                string message = " An error occurred while authenticating. " + ex.Detail;
                ShowMessage(GenerateScriptID("auth"), "error", message);
            }
            catch (Exception ex)
            {
                string message = " An error occurred while authenticating. " + ex.Message;
                ShowMessage(GenerateScriptID("auth"), "error", message);
            }
        }
Beispiel #30
0
 public CompareController(ICompareService compareService, IUserService userService) : base(userService)
 {
     _compareService = compareService;
 }