public void DescribeByteArray_can_handle_null_string_successfully() { // Arrange byte[] bytes = null; // Act var text = ByteArrayHelper.DescribeByteArray(bytes); // Assert text.ShouldBe(""); }
public void DescribeByteArray_can_handle_empty_byte_array_successfully() { // Arrange var bytes = new byte[] { }; // Act var text = ByteArrayHelper.DescribeByteArray(bytes); // Assert text.ShouldBe(""); }
public void DescribeByteArray_can_return_text_successfully() { // Arrange var bytes = new [] { (byte)10, (byte)20, (byte)30 }; // Act var text = ByteArrayHelper.DescribeByteArray(bytes); // Assert text.ShouldBe("10,20,30"); }
private static int RunEncode(IEncodeArguments arguments, RunResult runResult) { Console.Out.WriteLine(); Console.Out.WriteLine($"{nameof(RunEncode)}"); arguments.Validate(); var inputData = runResult.SignedData.HasAny() ? runResult.SignedData : ByteArrayHelper.TranslateByteArray(arguments.InputData); Console.Out.WriteLine($"Using: {ByteArrayHelper.DescribeByteArray(inputData)}"); runResult.EncodedData = Convert.ToBase64String(inputData); Console.Out.WriteLine($"{nameof(RunResult.EncodedData)}: {runResult.EncodedData}"); return(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); }
private static int RunHash(IHashArguments arguments, RunResult runResult) { Console.Out.WriteLine(); Console.Out.WriteLine($"{nameof(RunHash)}"); arguments.Validate(); var inputData = arguments.InputData; Console.Out.WriteLine($"Using: {inputData}"); runResult.UTF8EncodedData = Encoding.UTF8.GetBytes(inputData); Console.Out.WriteLine($"{nameof(RunResult.UTF8EncodedData)}: {ByteArrayHelper.DescribeByteArray(runResult.UTF8EncodedData)}"); using (var hashProvider = new SHA256Managed()) { runResult.HashedData = hashProvider.ComputeHash(runResult.UTF8EncodedData); Console.Out.WriteLine($"{nameof(RunResult.HashedData)} (SHA256): {ByteArrayHelper.DescribeByteArray(runResult.HashedData)}"); } return(0); }