Ejemplo n.º 1
0
        public static void CreateFromKeyIdentifierPreservesLeadingZeros()
        {
            ReadOnlySpan <byte> encoded = new byte[]
            {
                // SEQUENCE( [0](
                0x30, 0x16, 0x80, 0x14,
                // keyId
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x01, 0x00,
            };

            ReadOnlySpan <byte> keyId = encoded.Slice(4);

            X509AuthorityKeyIdentifierExtension akid;

            // From ROSpan
            akid = X509AuthorityKeyIdentifierExtension.CreateFromSubjectKeyIdentifier(keyId);
            AssertExtensions.SequenceEqual(encoded, akid.RawData);
            AssertExtensions.SequenceEqual(keyId, akid.KeyIdentifier.GetValueOrDefault().Span);

            // From array
            akid = X509AuthorityKeyIdentifierExtension.CreateFromSubjectKeyIdentifier(keyId.ToArray());
            AssertExtensions.SequenceEqual(encoded, akid.RawData);
            AssertExtensions.SequenceEqual(keyId, akid.KeyIdentifier.GetValueOrDefault().Span);

            // From SKI
            var skid = new X509SubjectKeyIdentifierExtension(keyId, critical: false);

            akid = X509AuthorityKeyIdentifierExtension.CreateFromSubjectKeyIdentifier(skid);
            AssertExtensions.SequenceEqual(encoded, akid.RawData);
            AssertExtensions.SequenceEqual(keyId, akid.KeyIdentifier.GetValueOrDefault().Span);
        }
Ejemplo n.º 2
0
        public static void CreateFromSubjectKeyIdentifier_Validation()
        {
            Assert.Throws <ArgumentNullException>(
                "subjectKeyIdentifier",
                () => X509AuthorityKeyIdentifierExtension.CreateFromSubjectKeyIdentifier(
                    (X509SubjectKeyIdentifierExtension)null));

            Assert.Throws <ArgumentNullException>(
                "subjectKeyIdentifier",
                () => X509AuthorityKeyIdentifierExtension.CreateFromSubjectKeyIdentifier(
                    (byte[])null));
        }
Ejemplo n.º 3
0
        public static void CreateFromLargeKeyIdentifier()
        {
            byte[] keyId = new byte[128];

            X509AuthorityKeyIdentifierExtension akid =
                X509AuthorityKeyIdentifierExtension.CreateFromSubjectKeyIdentifier(keyId);

            AssertExtensions.SequenceEqual(keyId, akid.KeyIdentifier.GetValueOrDefault().Span);

            byte[] rawData = akid.RawData;

            AssertExtensions.SequenceEqual(keyId, rawData.AsSpan(6));
            Assert.Equal("308183808180", rawData.AsSpan(0, 6).ByteArrayToHex());
        }