Ejemplo n.º 1
0
        public static void TryCopyIA5String(
            PublicEncodingRules ruleSet,
            string inputHex,
            string expectedValue)
        {
            byte[] inputData = inputHex.HexToByteArray();
            char[] output    = new char[expectedValue.Length];

            AsnReader reader = new AsnReader(inputData, (AsnEncodingRules)ruleSet);
            bool      copied;
            int       charsWritten;

            if (output.Length > 0)
            {
                output[0] = 'a';

                copied = reader.TryCopyIA5String(output.AsSpan(0, expectedValue.Length - 1),
                                                 out charsWritten);

                Assert.False(copied, "reader.TryCopyIA5String - too short");
                Assert.Equal(0, charsWritten);
                Assert.Equal('a', output[0]);
            }

            copied = reader.TryCopyIA5String(output,
                                             out charsWritten);

            Assert.True(copied, "reader.TryCopyIA5String");

            string actualValue = new string(output, 0, charsWritten);

            Assert.Equal(expectedValue, actualValue);
        }
Ejemplo n.º 2
0
        private static void TryCopyIA5String_Throws(PublicEncodingRules ruleSet, byte[] inputData)
        {
            char[] outputData = new char[inputData.Length + 1];
            outputData[0] = 'a';

            int       bytesWritten = -1;
            AsnReader reader       = new AsnReader(inputData, (AsnEncodingRules)ruleSet);

            Assert.Throws <CryptographicException>(
                () => reader.TryCopyIA5String(outputData, out bytesWritten));

            Assert.Equal(-1, bytesWritten);
            Assert.Equal('a', outputData[0]);
        }