Пример #1
0
        /// <summary>Add the given file to the container to be signed.</summary>
        /// <param name="filename">Path to the file to add.</param>
        /// <param name="mimetype">The MIME type of the file.</param>
        /// <param name="charset">The character set the file is encoded in.</param>
        public void addDataFile(string filename, string mimetype, string charset)
        {
            ComDataFile df = new ComDataFile();

            sd.createDataFile(filename, ComConstants.COM_CONTENT_EMBEDDED_BASE64, mimetype, 0, null, 0, ComConstants.COM_DIGEST_SHA1_NAME, charset, df);
            sd.calculateDataFileSizeAndDigest(df.szId, filename, ComConstants.COM_DIGEST_SHA1);
        }
Пример #2
0
        /// <summary>
        /// Read the contents of the first data file in the container. The server response should contain
        /// no more data files.
        /// </summary>
        /// <returns>The contents of the response.</returns>
        public string getContent()
        {
            if (sdoc.nDataFiles < 1)
            {
                throw new Exception("No data files in the container");
            }

            /* For our purposes, we can get away with reading only the first one. */
            ComDataFile df = new ComDataFile();

            sdoc.getDataFile(0, df);

            /* Since we have the container already read to memory, we do not need to read it from disk again.
             * But extractDataFile checks for the unused parameters anyway, so give some dummy values. */
            string filename = Path.GetTempFileName();
            int    err      = ddl.extractDataFile(sdoc, "not used", filename, df.szId, "not used");

            if (err != 0)
            {
                throw new Exception("Error extracting data file: " + ei.getErrorStringByCode(err));
            }

            /* Since the COM-library only supports extracting to file, then read it back in. */
            StringBuilder buf = new StringBuilder();

            using (StreamReader sr = new StreamReader(filename))
            {
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    buf.AppendLine(line);
                }
            }

            return(buf.ToString());
        }