Beispiel #1
0
        public void GetSigningProvider_can_create_a_PrivateKeyFileSigningProvider_successfully()
        {
            // Arrange
            var argumentsMock = new Mock <ISignArguments>();

            argumentsMock
            .Setup(x => x.PrivateKeyFileName)
            .Returns(KnownData.KnownPrivateKeyFileName);

            // Act
            var result = SigningProviderFactory.GetSigningProvider(argumentsMock.Object);

            // Assert
            result.ShouldNotBeNull();
        }
Beispiel #2
0
        public void GetSigningProvider_fails_to_create_a_PrivateKeyFileSigningProvider_with_unknown_key_file()
        {
            // Arrange
            var argumentsMock = new Mock <ISignArguments>();

            argumentsMock
            .Setup(x => x.PrivateKeyFileName)
            .Returns(Guid.NewGuid().ToString);

            // Act
            var ex = Assert.Throws <FileNotFoundException>(
                () => SigningProviderFactory.GetSigningProvider(argumentsMock.Object)
                );

            // Assert
            ex.ShouldNotBeNull();
        }
Beispiel #3
0
        public void GetSigningProvider_for_unknown_value_fails()
        {
            // Arrange
            var argumentsMock = new Mock <ISignArguments>();

            argumentsMock
            .Setup(x => x.SigningProvider)
            .Returns((SigningProviderType)int.MaxValue);

            // Act
            var ex = Assert.Throws <ArgumentOutOfRangeException>(
                () => SigningProviderFactory.GetSigningProvider(argumentsMock.Object)
                );

            // Assert
            ex.ShouldNotBeNull();
            ex.ParamName.ShouldBe("arguments");
        }
Beispiel #4
0
        private static int RunSign(ISignArguments arguments, RunResult runResult)
        {
            Console.Out.WriteLine();
            Console.Out.WriteLine($"{nameof(RunSign)}");

            arguments.Validate();

            var inputData = runResult.HashedData.HasAny()
                ? runResult.HashedData
                : ByteArrayHelper.TranslateByteArray(arguments.InputData);

            Console.Out.WriteLine($"Using: {ByteArrayHelper.DescribeByteArray(inputData)}");

            var signingProvider = SigningProviderFactory.GetSigningProvider(arguments);

            runResult.SignedData = signingProvider.SignHash(inputData);

            Console.Out.WriteLine($"{nameof(RunResult.SignedData)}: {ByteArrayHelper.DescribeByteArray(runResult.SignedData)}");

            return(0);
        }
Beispiel #5
0
        public void GetSigningProvider_fails_to_create_a_PrivateKeyFileSigningProvider_with_invalid_key_file()
        {
            // Arrange
            var tempFileName  = Path.GetTempFileName();
            var argumentsMock = new Mock <ISignArguments>();

            argumentsMock
            .Setup(x => x.PrivateKeyFileName)
            .Returns(tempFileName);

            // Act
            var ex = Assert.Throws <ArgumentException>(
                () => SigningProviderFactory.GetSigningProvider(argumentsMock.Object)
                );

            // Assert
            ex.ShouldNotBeNull();
            ex.ParamName.ShouldBe("privateKeyPEM");

            File.Delete(tempFileName);
        }