Ejemplo n.º 1
0
        private void CompareSignedDocumentsInfo(SignedDocumentInfo outInfo, SignedDocumentInfo cmpInfo)
        {
            if (outInfo.GetNumberOfTotalRevisions() != cmpInfo.GetNumberOfTotalRevisions())
            {
                AddComparisonError("Number of total revisions", outInfo.GetNumberOfTotalRevisions().ToString(),
                                   cmpInfo.GetNumberOfTotalRevisions().ToString());
            }

            if (outInfo.GetSignatureInfos().Count != cmpInfo.GetSignatureInfos().Count)
            {
                AddComparisonError("Number of signatures in document", outInfo.GetSignatureInfos().Count.ToString(),
                                   cmpInfo.GetSignatureInfos().Count.ToString());
            }

            for (int i = 0; i < outInfo.GetSignatureInfos().Count; ++i)
            {
                SignatureInfo outSig     = outInfo.GetSignatureInfos()[i];
                SignatureInfo cmpSig     = cmpInfo.GetSignatureInfos()[i];
                String        outAltName = outSig.GetAlternativeSignerName();
                String        cmpAltName = cmpSig.GetAlternativeSignerName();
                if (CheckIfEqual(outAltName, cmpAltName))
                {
                    AddComparisonError("Alternative signer name", outAltName, cmpAltName);
                }

                String outContactInfo = outSig.GetContactInfo();
                String cmpContactInfo = cmpSig.GetContactInfo();
                if (CheckIfEqual(outContactInfo, cmpContactInfo))
                {
                    AddComparisonError("Contact info", outContactInfo, cmpContactInfo);
                }

                String outDigestAlg = outSig.GetDigestAlgorithm();
                String cmpDigestAlg = cmpSig.GetDigestAlgorithm();
                if (CheckIfEqual(outDigestAlg, cmpDigestAlg))
                {
                    AddComparisonError("Digest algorithm", outDigestAlg, cmpDigestAlg);
                }

                String outEncryptAlg = outSig.GetEncryptionAlgorithm();
                String cmpEncryptAlg = cmpSig.GetEncryptionAlgorithm();
                if (CheckIfEqual(outEncryptAlg, cmpEncryptAlg))
                {
                    AddComparisonError("Encryption algorithm", outEncryptAlg, cmpEncryptAlg);
                }

                String outLocation = outSig.GetLocation();
                String cmpLocation = cmpSig.GetLocation();
                if (CheckIfEqual(outLocation, cmpLocation))
                {
                    AddComparisonError("Location", outLocation, cmpLocation);
                }

                String outReason = outSig.GetReason();
                String cmpReason = cmpSig.GetReason();
                if (CheckIfEqual(outReason, cmpReason))
                {
                    AddComparisonError("Reason", outReason, cmpReason);
                }

                String outSigName = outSig.GetSignatureName();
                String cmpSigName = cmpSig.GetSignatureName();
                if (CheckIfEqual(outSigName, cmpSigName))
                {
                    AddComparisonError("Signature name", outSigName, cmpSigName);
                }

                String outSignerName = outSig.GetSignerName();
                String cmpSignerName = cmpSig.GetSignerName();
                if (CheckIfEqual(outSignerName, cmpSignerName))
                {
                    AddComparisonError("Signer name", outSignerName, cmpSignerName);
                }

                String outFilterSubtype = outSig.GetFilterSubtype();
                String cmpFilterSubtype = cmpSig.GetFilterSubtype();
                if (CheckIfEqual(outFilterSubtype, cmpFilterSubtype))
                {
                    AddComparisonError("Filter subtype", outFilterSubtype, cmpFilterSubtype);
                }

                int outSigRevisionNumber = outSig.GetRevisionNumber();
                int cmpSigRevisionNumber = cmpSig.GetRevisionNumber();
                if (outSigRevisionNumber != cmpSigRevisionNumber)
                {
                    AddComparisonError("Signature revision number", outSigRevisionNumber.ToString(),
                                       cmpSigRevisionNumber.ToString());
                }

                String outTimeStampService = outSig.GetTimeStampService();
                String cmpTimeStampService = cmpSig.GetTimeStampService();
                if (CheckIfEqual(outTimeStampService, cmpTimeStampService))
                {
                    AddComparisonError("TimeStamp service", outTimeStampService, cmpTimeStampService);
                }

                bool outAnnotsAllowed = outSig.IsAddingAnnotationsAllowed();
                bool cmpAnnotsAllowed = cmpSig.IsAddingAnnotationsAllowed();
                if (outAnnotsAllowed != cmpAnnotsAllowed)
                {
                    AddComparisonError("Annotations allowance", outAnnotsAllowed.ToString(), cmpAnnotsAllowed
                                       .ToString());
                }

                bool outFieldsFillAllowed = outSig.IsFieldsFillAllowed();
                bool cmpFieldsFillAllowed = cmpSig.IsFieldsFillAllowed();
                if (outFieldsFillAllowed != cmpFieldsFillAllowed)
                {
                    AddComparisonError("Fields filling allowance", outFieldsFillAllowed.ToString(), cmpFieldsFillAllowed
                                       .ToString());
                }

                bool outIsCertification = outSig.IsCertifiaction();
                bool cmpIsCertification = cmpSig.IsCertifiaction();
                if (outIsCertification != cmpIsCertification)
                {
                    AddComparisonError("Comparing signature to certification result", outIsCertification
                                       .ToString(), cmpIsCertification.ToString());
                }

                bool outIsWholeDocument = outSig.IsSignatureCoversWholeDocument();
                bool cmpIsWholeDocument = cmpSig.IsSignatureCoversWholeDocument();
                if (outIsWholeDocument != cmpIsWholeDocument)
                {
                    AddComparisonError("Whole document covering", outIsWholeDocument.ToString(), cmpIsWholeDocument
                                       .ToString());
                }

                Rectangle outFp           = outSig.GetSignaturePosition();
                Rectangle cmpFp           = cmpSig.GetSignaturePosition();
                String    outPositionRect = outFp == null ? null : outFp.ToString();
                String    cmpPositionRect = cmpFp == null ? null : cmpFp.ToString();
                if (CheckIfEqual(outPositionRect, cmpPositionRect))
                {
                    AddComparisonError("Signature position", outPositionRect, cmpPositionRect);
                }

                IList <String> outFieldLocks  = outSig.GetFieldsLocks();
                IList <String> cmpFieldLocks  = cmpSig.GetFieldsLocks();
                int            outLocksNumber = outFieldLocks.Count;
                int            cmpLocksNumber = cmpFieldLocks.Count;
                if (outLocksNumber != cmpLocksNumber)
                {
                    AddComparisonError("Field locks number", outLocksNumber.ToString(), cmpLocksNumber
                                       .ToString());
                }

                for (int j = 0; j < outLocksNumber; ++j)
                {
                    if (!outFieldLocks[j].Equals(cmpFieldLocks[j]))
                    {
                        AddComparisonError("Field lock", outFieldLocks[j], cmpFieldLocks[j]);
                    }
                }

                if (outSig.GetCertificateInfos().Count != cmpSig.GetCertificateInfos().Count)
                {
                    AddComparisonError("Certificates number", outSig.GetCertificateInfos().Count.ToString(),
                                       cmpSig.GetCertificateInfos().Count.ToString());
                }

                for (int j_1 = 0; j_1 < outSig.GetCertificateInfos().Count; ++j_1)
                {
                    CertificateInfo outCert = outSig.GetCertificateInfos()[j_1];
                    CertificateInfo cmpCert = cmpSig.GetCertificateInfos()[j_1];
                    if (!outCert.GetIssuer().Equals(cmpCert.GetIssuer()))
                    {
                        AddComparisonError("Certificate issuer", outCert.GetIssuer().ToString(),
                                           cmpCert.GetIssuer().ToString());
                    }

                    if (!outCert.GetSubject().Equals(cmpCert.GetSubject()))
                    {
                        AddComparisonError("Certificate subject", outCert.GetSubject().ToString(), cmpCert
                                           .GetSubject().ToString());
                    }

                    if (!outCert.GetValidFrom().Equals(cmpCert.GetValidFrom()))
                    {
                        AddComparisonError("Date \"valid from\"", outCert.GetValidFrom().ToString(), cmpCert
                                           .GetValidFrom().ToString());
                    }

                    if (!outCert.GetValidTo().Equals(cmpCert.GetValidTo()))
                    {
                        AddComparisonError("Date \"valid to\"", outCert.GetValidTo().ToString(),
                                           cmpCert.GetValidTo().ToString());
                    }
                }
            }
        }