Exemplo n.º 1
0
        /// <summary>
        /// Export the public keyring bundle.
        /// </summary>
        /// <remarks>
        /// Exports the public keyring bundle.
        /// </remarks>
        /// <param name="keys">The public keyring bundle to export.</param>
        /// <param name="stream">The output stream.</param>
        /// <param name="armor"><c>true</c> if the output should be armored; otherwise, <c>false</c>.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="keys"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="stream"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// An I/O error occurred.
        /// </exception>
        public void Export(PgpPublicKeyRingBundle keys, Stream stream, bool armor)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (armor)
            {
                using (var armored = new ArmoredOutputStream(stream)) {
                    armored.SetHeader("Version", null);

                    keys.Encode(armored);
                    armored.Flush();
                }
            }
            else
            {
                keys.Encode(stream);
            }
        }