예제 #1
0
        public static void ValidateDocument(ISymUnmanagedDocument document, string url, string algorithmId, byte[] checksum)
        {
            ValidateDocumentUrl(document, url);

            int actualCount, actualCount2;

            if (checksum != null)
            {
                Assert.Equal(HResult.S_OK, document.GetChecksum(0, out actualCount, null));
                byte[] actualChecksum = new byte[actualCount];
                Assert.Equal(HResult.S_OK, document.GetChecksum(actualCount, out actualCount2, actualChecksum));
                Assert.Equal(actualCount, actualCount2);
                AssertEx.Equal(checksum, actualChecksum);
            }
            else
            {
                Assert.Equal(HResult.S_FALSE, document.GetChecksum(0, out actualCount, null));
                Assert.Equal(0, actualCount);
            }

            var guid = Guid.NewGuid();

            Assert.Equal(HResult.S_OK, document.GetChecksumAlgorithmId(ref guid));
            Assert.Equal(algorithmId != null ? new Guid(algorithmId) : default(Guid), guid);

            guid = Guid.NewGuid();
            Assert.Equal(HResult.S_OK, document.GetLanguageVendor(ref guid));
            Assert.Equal(new Guid("994b45c4-e6e9-11d2-903f-00c04fa302a1"), guid);

            guid = Guid.NewGuid();
            Assert.Equal(HResult.S_OK, document.GetDocumentType(ref guid));
            Assert.Equal(new Guid("5a869d0b-6611-11d3-bd2a-0000f80849bd"), guid);
        }
예제 #2
0
        public static void ValidateDocument(ISymUnmanagedDocument document, string url, string algorithmId, byte[] checksum)
        {
            ValidateDocumentUrl(document, url);

            int actualCount, actualCount2;

            if (checksum != null)
            {
                Assert.Equal(HResult.S_OK, document.GetChecksum(0, out actualCount, null));
                byte[] actualChecksum = new byte[actualCount];
                Assert.Equal(HResult.S_OK, document.GetChecksum(actualCount, out actualCount2, actualChecksum));
                Assert.Equal(actualCount, actualCount2);
                AssertEx.Equal(checksum, actualChecksum);
            }
            else
            {
                Assert.Equal(HResult.S_FALSE, document.GetChecksum(0, out actualCount, null));
                Assert.Equal(0, actualCount);
            }

            var guid = Guid.NewGuid();

            Assert.Equal(HResult.S_OK, document.GetChecksumAlgorithmId(ref guid));
            Assert.Equal(algorithmId != null ? new Guid(algorithmId) : default(Guid), guid);

            guid = Guid.NewGuid();
            Assert.Equal(HResult.S_OK, document.GetLanguageVendor(ref guid));
            Assert.Equal(new Guid("994b45c4-e6e9-11d2-903f-00c04fa302a1"), guid);

            guid = Guid.NewGuid();
            Assert.Equal(HResult.S_OK, document.GetDocumentType(ref guid));
            Assert.Equal(new Guid("5a869d0b-6611-11d3-bd2a-0000f80849bd"), guid);
        }
예제 #3
0
    public SymDocument(ISymUnmanagedDocument doc)
    {
        if (doc == null)
        {
            throw new ArgumentNullException(nameof(doc));
        }

        int len;

        doc.GetUrl(0, out len, null);
        if (len > 0)
        {
            var urlChars = new char[len];
            doc.GetUrl(len, out len, urlChars);
            Url = new string(urlChars, 0, len - 1);
        }

        doc.GetChecksum(0, out len, null);
        if (len > 0)
        {
            Checksum = new byte[len];
            doc.GetChecksum(len, out len, Checksum);
        }

        Guid id = Guid.Empty;

        doc.GetChecksumAlgorithmId(ref id);
        ChecksumAlgorithmId = id;
    }
예제 #4
0
        public static Guid GetHashAlgorithm(this ISymUnmanagedDocument document)
        {
            Guid result = default(Guid);
            int  hr     = document.GetChecksumAlgorithmId(ref result);

            ThrowExceptionForHR(hr);
            return(result);
        }
        public static Guid GetHashAlgorithm(this ISymUnmanagedDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            Guid result = default(Guid);

            ThrowExceptionForHR(document.GetChecksumAlgorithmId(ref result));
            return(result);
        }
예제 #6
0
                public SymDocument(ISymUnmanagedDocument doc)
                {
                    if (doc == null)
                    {
                        throw new ArgumentNullException(nameof(doc));
                    }

                    int len;
                    var hr = doc.GetUrl(0, out len, null);

                    ThrowExceptionForHR(hr);
                    if (len > 0)
                    {
                        var urlChars = new char[len];
                        hr = doc.GetUrl(len, out len, urlChars);
                        ThrowExceptionForHR(hr);
                        Url = new string(urlChars, 0, len - 1);
                    }

                    hr = doc.GetChecksum(0, out len, null);
                    ThrowExceptionForHR(hr);

                    if (len > 0)
                    {
                        Checksum = new byte[len];
                        hr       = doc.GetChecksum(len, out len, Checksum);
                        ThrowExceptionForHR(hr);
                    }

                    var id = Guid.Empty;

                    hr = doc.GetChecksumAlgorithmId(ref id);
                    ThrowExceptionForHR(hr);

                    ChecksumAlgorithmId = id;
                    if (id == CorSym_SourceHash_MD5)
                    {
                        ChecksumAlgorithm = ChecksumAlgorithmKind.Md5;
                    }
                    else if (id == CorSym_SourceHash_SHA1)
                    {
                        ChecksumAlgorithm = ChecksumAlgorithmKind.Sha1;
                    }
                }