Exemplo n.º 1
0
            public void Setup()
            {
                key     = Mock.Of <IAsymmetricKey>();
                content = new byte[] { 0x07 };

                command = commandProvider.GetCreateSignatureCommand(key, content);
            }
        public void CreateSignature(ApplicationArguments arguments)
        {
            ReadKeyFromFileCommand readPrivateKeyFromFile = fileCommandProvider.GetReadPrivateKeyFromFileCommand(arguments.PrivateKeyPath, arguments.Password);

            commandExecutor.Execute(readPrivateKeyFromFile);

            byte[] contentToSign;
            if (arguments.HasFileInput)
            {
                ReadFileCommand <byte[]> readFileToSign = fileCommandProvider.GetReadFileCommand <byte[]>(arguments.FileInput);
                commandExecutor.Execute(readFileToSign);
                contentToSign = readFileToSign.Result;
            }
            else
            {
                contentToSign = encoding.GetBytes(arguments.Input);
            }

            CreateSignatureCommand createSignature = signatureCommandProvider.GetCreateSignatureCommand(readPrivateKeyFromFile.Result, contentToSign);

            commandExecutor.Execute(createSignature);

            if (arguments.HasFileOutput)
            {
                WriteFileCommand <Signature> writeSignatureTofile = fileCommandProvider.GetWriteToFileCommand(createSignature.Result, arguments.FileOutput);
                commandExecutor.Execute(writeSignatureTofile);
                return;
            }

            WriteToStdOutCommand <Signature> writeSignatureToStdOut = fileCommandProvider.GetWriteToStdOutCommand <Signature>(createSignature.Result);

            commandExecutor.Execute(writeSignatureToStdOut);
        }
Exemplo n.º 3
0
        public void ShouldSetCreatedSignatureAsCommandResult()
        {
            var command = new CreateSignatureCommand
            {
                ContentToSign = new byte[] { 0x07 },
                PrivateKey    = privateKey
            };

            commandHandler.Execute(command);
            Assert.AreEqual(signature, command.Result);
        }