From 28d70017845dfe00af366ae56ad388f52bc944d2 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Fri, 5 Oct 2018 13:39:56 +0700 Subject: Fix some TODOs for PORTABLE and Streams --- crypto/src/util/io/Streams.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'crypto/src/util') diff --git a/crypto/src/util/io/Streams.cs b/crypto/src/util/io/Streams.cs index cc7fa924c..503a1b4f1 100644 --- a/crypto/src/util/io/Streams.cs +++ b/crypto/src/util/io/Streams.cs @@ -96,5 +96,30 @@ namespace Org.BouncyCastle.Utilities.IO { buf.WriteTo(output); } + + /// + public static int WriteBufTo(MemoryStream buf, byte[] output, int offset) + { +#if PORTABLE + byte[] bytes = buf.ToArray(); + bytes.CopyTo(output, offset); + return bytes.Length; +#else + int size = (int)buf.Length; + buf.WriteTo(new MemoryStream(output, offset, size, true)); + return size; +#endif + } + + public static void WriteZeroes(Stream outStr, long count) + { + byte[] zeroes = new byte[BufferSize]; + while (count > BufferSize) + { + outStr.Write(zeroes, 0, BufferSize); + count -= BufferSize; + } + outStr.Write(zeroes, 0, (int)count); + } } } -- cgit 1.4.1