//public Rfc3171Accuracy_ Accuracy { get; private set; }
        //public ReadOnlyMemory<byte> Ordering { get; private set; }
        //public ReadOnlyMemory<byte> Nonce { get; private set; }
        //public ReadOnlyMemory<byte> Tsa { get; private set; }
        //public ReadOnlyMemory<byte> Extensions { get; private set; }


        public static Rfc3161TstInfo From(EncapsulatedContentInfo content)
        {
            /*  EncapsulatedContentInfo ::= SEQUENCE {
             *      eContentType ContentType,
             *      eContent [0] EXPLICIT OCTET STRING OPTIONAL } */
            // note: the content field is read with ReadEncodedValue
            // because it would fail with ReadOctetString when reading the *.p7s.

            // just unwrap OCTET STRING node, [0] OPTIONAL is already stripped inside EncapsulatedContentInfo
            var reader = new AsnReader(content.Content, AsnEncodingRules.DER);
            var data   = reader.ReadOctetString();

            return(Decode(data));
        }
Beispiel #2
0
        public static SignedData Decode(AsnReader reader)
        {
            /* SignedData ::= SEQUENCE {
             *  version CMSVersion,
             *  digestAlgorithms DigestAlgorithmIdentifiers,
             *  encapContentInfo EncapsulatedContentInfo,
             *  certificates [0] IMPLICIT CertificateSet OPTIONAL,
             *  crls [1] IMPLICIT RevocationInfoChoices OPTIONAL,
             *  signerInfos SignerInfos }*/
            var sequence = reader.ReadSequence();

            // version CMSVersion,
            if (!sequence.TryReadInt32(out var version))
            {
                sequence.ThrowIfNotEmpty();
            }

            // digestAlgorithms DigestAlgorithmIdentifiers
            // DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
            var digestAlgorithms = sequence.ReadSetOf(set => AlgorithmIdentifier.Decode(set));

            // encapContentInfo EncapsulatedContentInfo
            var encapContentInfo = EncapsulatedContentInfo.Decode(sequence);

            // certificates [0] IMPLICIT CertificateSet OPTIONAL,
            var certificates = sequence.ReadOptionalSetOf(0, set => CertificateChoices.Decode(set));

            // crls [1] IMPLICIT RevocationInfoChoices OPTIONAL,
            var crls = sequence.ReadOptionalSetOf(1, set => set.ReadEncodedValue());

            // signerInfos SignerInfos
            // SignerInfos ::= SET OF SignerInfo
            var signerInfos = sequence.ReadSetOf(set => SignerInfo.Decode(set));

            sequence.ThrowIfNotEmpty();
            return(new()
            {
                Version = version,
                DigestAlgorithms = digestAlgorithms,
                EncapContentInfo = encapContentInfo,
                Certificates = certificates,
                Crls = crls,
                SignerInfos = signerInfos,
            });
        }