Exemplo n.º 1
0
        public void WriteObject(PemObjectGenerator objGen)
        {
            PemObject obj = objGen.Generate();

            WritePreEncapsulationBoundary(obj.Type);

            if (obj.Headers.Count > 0)
            {
                foreach (PemHeader header in obj.Headers)
                {
                    writer.Write(header.Name);
                    writer.Write(": ");
                    writer.WriteLine(header.Value);
                }

                writer.WriteLine();
            }

            WriteEncoded(obj.GetContent());
            WritePostEncapsulationBoundary(obj.Type);
        }
Exemplo n.º 2
0
        /**
         * Return the number of bytes or characters required to contain the
         * passed in object if it is PEM encoded.
         *
         * @param obj pem object to be output
         * @return an estimate of the number of bytes
         */
        public int GetOutputSize(PemObject obj)
        {
            // BEGIN and END boundaries.
            int size = (2 * (obj.Type.Length + 10 + nlLength)) + 6 + 4;

            if (obj.Headers.Count > 0)
            {
                foreach (PemHeader header in obj.Headers)
                {
                    size += header.Name.Length + ": ".Length + header.Value.Length + nlLength;
                }

                size += nlLength;
            }

            // base64 encoding
            int dataLen = ((obj.GetContent().Length + 2) / 3) * 4;

            size += dataLen + (((dataLen + LineLength - 1) / LineLength) * nlLength);

            return(size);
        }