1 files changed, 46 insertions, 32 deletions
diff --git a/crypto/src/bcpg/ArmoredOutputStream.cs b/crypto/src/bcpg/ArmoredOutputStream.cs
index fb1f6eb29..1f0e412d8 100644
--- a/crypto/src/bcpg/ArmoredOutputStream.cs
+++ b/crypto/src/bcpg/ArmoredOutputStream.cs
@@ -101,16 +101,7 @@ namespace Org.BouncyCastle.Bcpg
private static readonly string footerStart = "-----END PGP ";
private static readonly string footerTail = "-----";
- private static readonly string version = "BCPG C# v"
-#if PORTABLE
- + Assembly.GetExecutingAssembly()
- .GetCustomAttributes(typeof(AssemblyVersionAttribute), true)
- .Cast<AssemblyVersionAttribute>()
- .First()
- .Version;
-#else
- + Assembly.GetExecutingAssembly().GetName().Version;
-#endif
+ private static readonly string version = "BCPG C# v" + AssemblyInfo.Version;
private readonly IDictionary headers;
@@ -292,37 +283,60 @@ namespace Org.BouncyCastle.Bcpg
* <b>Note</b>: Close() does not close the underlying stream. So it is possible to write
* multiple objects using armoring to a single stream.
*/
- public override void Close()
+#if PORTABLE
+ protected override void Dispose(bool disposing)
{
- if (type != null)
+ if (disposing)
{
- if (bufPtr > 0)
- {
- Encode(outStream, buf, bufPtr);
- }
+ if (type == null)
+ return;
- DoWrite(nl + '=');
+ DoClose();
- int crcV = crc.Value;
+ type = null;
+ start = true;
+ }
+ base.Dispose(disposing);
+ }
+#else
+ public override void Close()
+ {
+ if (type == null)
+ return;
- buf[0] = ((crcV >> 16) & 0xff);
- buf[1] = ((crcV >> 8) & 0xff);
- buf[2] = (crcV & 0xff);
+ DoClose();
- Encode(outStream, buf, 3);
+ type = null;
+ start = true;
- DoWrite(nl);
- DoWrite(footerStart);
- DoWrite(type);
- DoWrite(footerTail);
- DoWrite(nl);
-
- outStream.Flush();
+ base.Close();
+ }
+#endif
- type = null;
- start = true;
- base.Close();
+ private void DoClose()
+ {
+ if (bufPtr > 0)
+ {
+ Encode(outStream, buf, bufPtr);
}
+
+ DoWrite(nl + '=');
+
+ int crcV = crc.Value;
+
+ buf[0] = ((crcV >> 16) & 0xff);
+ buf[1] = ((crcV >> 8) & 0xff);
+ buf[2] = (crcV & 0xff);
+
+ Encode(outStream, buf, 3);
+
+ DoWrite(nl);
+ DoWrite(footerStart);
+ DoWrite(type);
+ DoWrite(footerTail);
+ DoWrite(nl);
+
+ outStream.Flush();
}
private void WriteHeaderEntry(
|