public RFC3161TimestampSignature(CmsSignature rfc3161Signature) : base(rfc3161Signature)
            {
                var content = rfc3161Signature.Content;

                if (content is object)
                {
                    TimestampDateTime = TimestampDecoding.DecodeRfc3161(content);
                }
            }
Пример #2
0
        private static unsafe IReadOnlyList <ICmsSignature> GetSignatures(CryptMsgSafeHandle messageHandle)
        {
            var countSize = 0u;

            if (!Crypt32.CryptMsgGetParam(messageHandle, CryptMsgParamType.CMSG_SIGNER_COUNT_PARAM, 0, LocalBufferSafeHandle.Zero, ref countSize))
            {
                return(Array.Empty <ICmsSignature>());
            }
            uint signerCount;

            using (var countHandle = LocalBufferSafeHandle.Alloc(countSize))
            {
                if (!Crypt32.CryptMsgGetParam(messageHandle, CryptMsgParamType.CMSG_SIGNER_COUNT_PARAM, 0, countHandle, ref countSize))
                {
                    return(Array.Empty <ICmsSignature>());
                }
                signerCount = (uint)Marshal.ReadInt32(countHandle.DangerousGetHandle());
            }
            var signatures  = new List <ICmsSignature>();
            var contentSize = 0u;

            byte[] content = null;
            if (Crypt32.CryptMsgGetParam(messageHandle, CryptMsgParamType.CMSG_CONTENT_PARAM, 0, LocalBufferSafeHandle.Zero, ref contentSize))
            {
                using (var contentHandle = LocalBufferSafeHandle.Alloc(contentSize))
                {
                    if (Crypt32.CryptMsgGetParam(messageHandle, CryptMsgParamType.CMSG_CONTENT_PARAM, 0, contentHandle, ref contentSize))
                    {
                        content = new byte[contentSize];
                        Marshal.Copy(contentHandle.DangerousGetHandle(), content, 0, (int)contentSize);
                    }
                }
            }
            for (var i = 0u; i < signerCount; i++)
            {
                var signerSize = 0u;
                if (!Crypt32.CryptMsgGetParam(messageHandle, CryptMsgParamType.CMSG_SIGNER_INFO_PARAM, i, LocalBufferSafeHandle.Zero, ref signerSize))
                {
                    continue;
                }
                using (var signerHandle = LocalBufferSafeHandle.Alloc(signerSize))
                {
                    if (!Crypt32.CryptMsgGetParam(messageHandle, CryptMsgParamType.CMSG_SIGNER_INFO_PARAM, i, signerHandle, ref signerSize))
                    {
                        continue;
                    }
                    var signature = new CmsSignature(SignatureKind.Signature, messageHandle, signerHandle, content);
                    signatures.Add(signature);
                }
            }
            return(signatures.AsReadOnly());
        }