public virtual void ActionIsPresentedTest()
        {
            PdfDictionary dict           = new PdfDictionary();
            PdfArray      references     = new PdfArray();
            PdfDictionary dictWithAction = new PdfDictionary();
            PdfDictionary @params        = new PdfDictionary();
            PdfName       action         = new PdfName("Name");
            PdfArray      fields         = new PdfArray();

            fields.Add(new PdfString("Value1"));
            fields.Add(new PdfString("Value2"));
            @params.Put(PdfName.Action, action);
            @params.Put(PdfName.Fields, fields);
            dictWithAction.Put(PdfName.TransformParams, @params);
            references.Add(dictWithAction);
            dict.Put(PdfName.Reference, references);
            SignaturePermissions permissions = new SignaturePermissions(dict, null);

            NUnit.Framework.Assert.AreEqual(1, permissions.GetFieldLocks().Count);
            SignaturePermissions.FieldLock fieldLock = permissions.GetFieldLocks()[0];
            NUnit.Framework.Assert.AreEqual(action, fieldLock.GetAction());
            NUnit.Framework.Assert.AreEqual(fields, fieldLock.GetFields());
            NUnit.Framework.Assert.IsTrue(permissions.IsAnnotationsAllowed());
            NUnit.Framework.Assert.IsFalse(permissions.IsCertification());
            NUnit.Framework.Assert.IsTrue(permissions.IsFillInAllowed());
        }
        public virtual void DefaultValuesTest()
        {
            SignaturePermissions permissions = new SignaturePermissions(new PdfDictionary(), null);

            NUnit.Framework.Assert.AreEqual(new List <Object>(), permissions.GetFieldLocks());
            NUnit.Framework.Assert.IsTrue(permissions.IsAnnotationsAllowed());
            NUnit.Framework.Assert.IsFalse(permissions.IsCertification());
            NUnit.Framework.Assert.IsTrue(permissions.IsFillInAllowed());
        }
Beispiel #3
0
        /// <summary>
        /// Creates an object that can inform you about the type of signature
        /// in a signature dictionary as well as some of the permissions
        /// defined by the signature.
        /// </summary>
        public SignaturePermissions(PdfDictionary sigDict, SignaturePermissions previous)
        {
            if (previous != null)
            {
                annotationsAllowed &= previous.IsAnnotationsAllowed();
                fillInAllowed      &= previous.IsFillInAllowed();
                fieldLocks.AddAll(previous.GetFieldLocks());
            }
            PdfArray @ref = sigDict.GetAsArray(PdfName.Reference);

            if (@ref != null)
            {
                for (int i = 0; i < @ref.Size(); i++)
                {
                    PdfDictionary dict    = @ref.GetAsDictionary(i);
                    PdfDictionary @params = dict.GetAsDictionary(PdfName.TransformParams);
                    if (PdfName.DocMDP.Equals(dict.GetAsName(PdfName.TransformMethod)))
                    {
                        certification = true;
                    }
                    PdfName action = @params.GetAsName(PdfName.Action);
                    if (action != null)
                    {
                        fieldLocks.Add(new SignaturePermissions.FieldLock(this, action, @params.GetAsArray(PdfName.Fields)));
                    }
                    PdfNumber p = @params.GetAsNumber(PdfName.P);
                    if (p == null)
                    {
                        continue;
                    }
                    switch (p.IntValue())
                    {
                    default: {
                        break;
                    }

                    case 1: {
                        fillInAllowed &= false;
                        goto case 2;
                    }

                    case 2: {
                        annotationsAllowed &= false;
                        break;
                    }
                    }
                }
            }
        }
        public virtual void TransformedMethodDocMDPIsPresentedTest()
        {
            PdfDictionary dict           = new PdfDictionary();
            PdfArray      references     = new PdfArray();
            PdfDictionary dictWithDocMDP = new PdfDictionary();

            dictWithDocMDP.Put(PdfName.TransformMethod, PdfName.DocMDP);
            dictWithDocMDP.Put(PdfName.TransformParams, new PdfDictionary());
            references.Add(dictWithDocMDP);
            dict.Put(PdfName.Reference, references);
            SignaturePermissions permissions = new SignaturePermissions(dict, null);

            NUnit.Framework.Assert.IsTrue(permissions.IsCertification());
            NUnit.Framework.Assert.AreEqual(new List <Object>(), permissions.GetFieldLocks());
            NUnit.Framework.Assert.IsTrue(permissions.IsAnnotationsAllowed());
            NUnit.Framework.Assert.IsTrue(permissions.IsFillInAllowed());
        }
        public virtual void PParamEqualsTo2Test()
        {
            PdfDictionary dict           = new PdfDictionary();
            PdfArray      references     = new PdfArray();
            PdfDictionary dictWithAction = new PdfDictionary();
            PdfDictionary @params        = new PdfDictionary();

            @params.Put(PdfName.P, new PdfNumber(2));
            dictWithAction.Put(PdfName.TransformParams, @params);
            references.Add(dictWithAction);
            dict.Put(PdfName.Reference, references);
            SignaturePermissions permissions = new SignaturePermissions(dict, null);

            NUnit.Framework.Assert.IsFalse(permissions.IsAnnotationsAllowed());
            NUnit.Framework.Assert.AreEqual(new List <Object>(), permissions.GetFieldLocks());
            NUnit.Framework.Assert.IsTrue(permissions.IsFillInAllowed());
            NUnit.Framework.Assert.IsFalse(permissions.IsCertification());
        }
Beispiel #6
0
 /// <summary>Creates a FieldLock instance</summary>
 public FieldLock(SignaturePermissions _enclosing, PdfName action, PdfArray fields)
 {
     this._enclosing = _enclosing;
     this.action     = action;
     this.fields     = fields;
 }