public unsafe void DecodePtrToPtrTest(BaseNEncoding encoding, byte[] plainTextData, string encodedData) { var encoder = (BaseNEncoder)encoding.GetEncoder(); var inputBuffer = new byte[encodedData.Length]; for (var i = 0; i < encodedData.Length; i++) { inputBuffer[i] = (byte)encodedData[i]; } var input = new ArraySegment <byte>(inputBuffer, 0, inputBuffer.Length); var outputBuffer = new byte[plainTextData.Length]; var output = new ArraySegment <byte>(outputBuffer, 0, outputBuffer.Length); var inputUsed = 0; var outputUsed = 0; fixed(byte *inputPtr = inputBuffer) fixed(byte *outputPtr = outputBuffer) { encoder.Convert(inputPtr, inputBuffer.Length, outputPtr, outputBuffer.Length, true, out inputUsed, out outputUsed, out var completed); Assert.True(completed); } Assert.Equal(input.Count, inputUsed); Assert.Equal(output.Count, outputUsed); Assert.Equal(plainTextData, outputBuffer); }
public void DecodeCharsToBytesTest(BaseNEncoding encoding, byte[] plainTextData, string encodedData) { var input = new ArraySegment <char>(encodedData.ToCharArray(), 0, encodedData.Length); var outputBuffer = new byte[plainTextData.Length]; var output = new ArraySegment <byte>(outputBuffer, 0, outputBuffer.Length); var encoder = (BaseNEncoder)encoding.GetEncoder(); encoder.Convert(input.Array, input.Offset, input.Count, output.Array, output.Offset, output.Count, true, out var inputUsed, out var outputUsed, out var completed); Assert.Equal(input.Count, inputUsed); Assert.Equal(output.Count, outputUsed); Assert.Equal(plainTextData, outputBuffer); Assert.True(completed); }
public void GetBytesSpanCharsTest(BaseNEncoding encoding, byte[] plainTextData, string encodedData) { var encoder = (BaseNEncoder)encoding.GetEncoder(); var inputBuffer = new char[encodedData.Length]; for (var i = 0; i < encodedData.Length; i++) { inputBuffer[i] = encodedData[i]; } var input = (Span <char>)inputBuffer; var outputBuffer = new byte[plainTextData.Length]; var output = (Span <byte>)outputBuffer; encoder.GetBytes(input, output, true); var byteCount = encoder.GetByteCount(input, true); Assert.Equal(plainTextData, outputBuffer); Assert.Equal(outputBuffer.Length, byteCount); }
public void DecodeSpanToSpanCharTest(BaseNEncoding encoding, byte[] plainTextData, string encodedData) { var encoder = (BaseNEncoder)encoding.GetEncoder(); var inputBuffer = new char[encodedData.Length]; for (var i = 0; i < encodedData.Length; i++) { inputBuffer[i] = encodedData[i]; } var input = (Span <char>)inputBuffer; var outputBuffer = new byte[plainTextData.Length]; var output = (Span <byte>)outputBuffer; encoder.Convert(input, output, true, out var inputUsed, out var outputUsed, out var completed); Assert.Equal(inputBuffer.Length, inputUsed); Assert.Equal(outputBuffer.Length, outputUsed); Assert.Equal(plainTextData, outputBuffer); Assert.True(completed); }
public void DecodeBytesToBytesTest(BaseNEncoding encoding, byte[] plainTextData, string encodedData) { var inputBuffer = new byte[encodedData.Length]; for (var i = 0; i < encodedData.Length; i++) { inputBuffer[i] = (byte)encodedData[i]; } var input = new ArraySegment <byte>(inputBuffer, 0, inputBuffer.Length); var outputBuffer = new byte[plainTextData.Length]; var output = new ArraySegment <byte>(outputBuffer, 0, outputBuffer.Length); var encoder = (BaseNEncoder)encoding.GetEncoder(); encoder.Convert(input.Array, input.Offset, input.Count, output.Array, output.Offset, output.Count, true, out var inputUsed, out var outputUsed, out var completed); Assert.Equal(inputUsed, input.Count); Assert.Equal(outputUsed, output.Count); Assert.Equal(plainTextData, outputBuffer); Assert.True(completed); }
public void GetEncoderTest() { var baseNEncoding = new BaseNEncoding(BaseNAlphabet.Base64UrlAlphabet, "name"); Assert.NotNull(baseNEncoding.GetEncoder()); }