예제 #1
0
        /* Updates the /ByteRange with the provided value */
        private void UpdateByteRange(PdfPKCS7 pkcs7, PdfSignature signature)
        {
            PdfArray b = signature.GetByteRange();
            RandomAccessFileOrArray rf = document.GetReader().GetSafeFile();
            Stream rg = null;

            try {
                rg = new RASInputStream(new RandomAccessSourceFactory().CreateRanged(rf.CreateSourceView(), b.ToLongArray(
                                                                                         )));
                byte[] buf = new byte[8192];
                int    rd;
                while ((rd = rg.JRead(buf, 0, buf.Length)) > 0)
                {
                    pkcs7.Update(buf, 0, rd);
                }
            }
            catch (Exception e) {
                throw new PdfException(e);
            }
            finally {
                try {
                    if (rg != null)
                    {
                        rg.Dispose();
                    }
                }
                catch (System.IO.IOException e) {
                    // this really shouldn't ever happen - the source view we use is based on a Safe view, which is a no-op anyway
                    throw new PdfException(e);
                }
            }
        }
예제 #2
0
        /// <summary>Extracts a revision from the document.</summary>
        /// <param name="field">the signature field name</param>
        /// <returns>an InputStream covering the revision. Returns null if it's not a signature field</returns>
        /// <exception cref="System.IO.IOException"/>
        public virtual Stream ExtractRevision(String field)
        {
            GetSignatureNames();
            if (!sigNames.ContainsKey(field))
            {
                return(null);
            }
            int length = sigNames.Get(field)[0];
            RandomAccessFileOrArray raf = document.GetReader().GetSafeFile();

            return(new RASInputStream(new WindowRandomAccessSource(raf.CreateSourceView(), 0, length)));
        }