Esempio n. 1
0
        public static SignerIdentifier Decode(AsnReader reader, bool validateEmpty = true)
        {
            /* SignerIdentifier ::= CHOICE {
             *  issuerAndSerialNumber IssuerAndSerialNumber,
             *  subjectKeyIdentifier [0] SubjectKeyIdentifier } */
            var tag = reader.PeekTag();

            if (tag.HasSameClassAndValue(Asn1Tag.Sequence))
            {
                var result = new SignerIdentifier()
                {
                    IssuerAndSerialNumber = IssuerAndSerialNumber.Decode(reader),
                };

                if (validateEmpty)
                {
                    reader.ThrowIfNotEmpty();
                }
                return(result);
            }

            if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0)))
            {
                var result = new SignerIdentifier()
                {
                    SubjectKeyIdentifier = reader.ReadPrimitiveOrNotOctetString(tag),
                };

                if (validateEmpty)
                {
                    reader.ThrowIfNotEmpty();
                }
                return(result);
            }

            throw new CryptographicException();
        }