public void ToBytesFromCharArrayTest(BaseNEncoding encoding, byte[] plainTextData, string encodedData)
        {
            var actual     = encoding.GetBytes(encodedData.ToCharArray());
            var bytesCount = encoding.GetByteCount(encodedData.ToCharArray(), 0, encodedData.Length);

            Assert.Equal(plainTextData, actual);
            Assert.Equal(bytesCount, actual.Length);
        }
Exemple #2
0
        public void GetBytesStringTest()
        {
            var base64String  = "80_poA1Ahss=";
            var base64Bytes   = new byte[] { 243, 79, 233, 160, 13, 64, 134, 203 };
            var baseNEncoding = new BaseNEncoding(BaseNAlphabet.Base64UrlAlphabet, "name");

            var actual = baseNEncoding.GetBytes(base64String, 0, base64String.Length);

            Assert.Equal(base64Bytes, actual);
        }
        public void ToBytesFromCharArrayPartTest(BaseNEncoding encoding, byte[] plainTextData, string encodedData)
        {
            var random     = new Random(9375220);
            var input      = PadData(encodedData, out var offset, out var extra, random);
            var actual     = encoding.GetBytes(input.ToCharArray(), offset, encodedData.Length);
            var bytesCount = encoding.GetByteCount(input.ToCharArray(), offset, encodedData.Length);

            Assert.Equal(plainTextData, actual);
            Assert.Equal(bytesCount, actual.Length);
        }
        public void ToBytesFromStringTest(BaseNEncoding encoding, byte[] plainTextData, string encodedData)
        {
            var actual = encoding.GetBytes(encodedData);

#if NETCOREAPP
            var bytesCount = encoding.GetByteCount(encodedData, 0, encodedData.Length);
#else
            var bytesCount = encoding.GetByteCount(encodedData.ToCharArray(), 0, encodedData.Length);
#endif
            Assert.Equal(plainTextData, actual);
            Assert.Equal(bytesCount, actual.Length);
        }
Exemple #5
0
        public unsafe void GetBytesPtrTest()
        {
            var base64String  = "80_poA1Ahss=";
            var base64Bytes   = new byte[] { 243, 79, 233, 160, 13, 64, 134, 203 };
            var baseNEncoding = new BaseNEncoding(BaseNAlphabet.Base64UrlAlphabet, "name");
            var actualBytes   = new byte[base64Bytes.Length];

            fixed(byte *bytesPtr = actualBytes)
            fixed(char *charsPtr = base64String)
            {
                baseNEncoding.GetBytes(charsPtr, base64String.Length, bytesPtr, actualBytes.Length);

                Assert.Equal(base64Bytes, actualBytes);
            }
        }