summary refs log tree commit diff
path: root/crypto/src/cms
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-09-03 00:36:40 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-09-03 00:36:40 +0700
commitaa5f3f0929c50fc942325f18ed7ae48129d4c992 (patch)
tree0382f7336cb55c4a01bd38782d7694d1cb094921 /crypto/src/cms
parentClean up tests (diff)
downloadBouncyCastle.NET-ed25519-aa5f3f0929c50fc942325f18ed7ae48129d4c992.tar.xz
Stream modernization
Diffstat (limited to 'crypto/src/cms')
-rw-r--r--crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs20
-rw-r--r--crypto/src/cms/CMSCompressedDataStreamGenerator.cs14
-rw-r--r--crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs43
-rw-r--r--crypto/src/cms/CMSSignedDataStreamGenerator.cs8
-rw-r--r--crypto/src/cms/CMSTypedStream.cs26
5 files changed, 33 insertions, 78 deletions
diff --git a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
index 4ac2b34c9..d66b0aea9 100644
--- a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
@@ -248,7 +248,6 @@ namespace Org.BouncyCastle.Cms
 				macStream.WriteByte(value);
 			}
 
-#if PORTABLE
             protected override void Dispose(bool disposing)
             {
                 if (disposing)
@@ -269,25 +268,6 @@ namespace Org.BouncyCastle.Cms
                 }
                 base.Dispose(disposing);
             }
-#else
-			public override void Close()
-			{
-                Platform.Dispose(macStream);
-
-                // TODO Parent context(s) should really be be closed explicitly
-
-				eiGen.Close();
-
-				// [TODO] auth attributes go here 
-				byte[] macOctets = MacUtilities.DoFinal(mac);
-				authGen.AddObject(new DerOctetString(macOctets));
-				// [TODO] unauth attributes go here
-
-				authGen.Close();
-				cGen.Close();
-                base.Close();
-			}
-#endif
 		}
 	}
 }
diff --git a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
index 1a9513ce6..9a9c29b01 100644
--- a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
@@ -121,7 +121,6 @@ namespace Org.BouncyCastle.Cms
 				_out.WriteByte(value);
 			}
 
-#if PORTABLE
             protected override void Dispose(bool disposing)
             {
                 if (disposing)
@@ -136,19 +135,6 @@ namespace Org.BouncyCastle.Cms
                 }
                 base.Dispose(disposing);
             }
-#else
-			public override void Close()
-			{
-                Platform.Dispose(_out);
-
-                // TODO Parent context(s) should really be be closed explicitly
-
-                _eiGen.Close();
-				_cGen.Close();
-				_sGen.Close();
-				base.Close();
-			}
-#endif
 		}
 	}
 }
diff --git a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
index 90ecf0748..4a8b57aad 100644
--- a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
@@ -246,44 +246,31 @@ namespace Org.BouncyCastle.Cms
 				_out.WriteByte(value);
 			}
 
-#if PORTABLE
             protected override void Dispose(bool disposing)
             {
                 if (disposing)
  				{
-					ImplClose();
-                }
-                base.Dispose(disposing);
-            }
-#else
-			public override void Close()
-			{
-				ImplClose();
-				base.Close();
-			}
-#endif
+                    Platform.Dispose(_out);
 
-			private void ImplClose()
-            {
-				Platform.Dispose(_out);
+                    // TODO Parent context(s) should really be closed explicitly
 
-				// TODO Parent context(s) should really be closed explicitly
+                    _eiGen.Close();
 
-				_eiGen.Close();
+                    if (_outer.unprotectedAttributeGenerator != null)
+                    {
+                        Asn1.Cms.AttributeTable attrTable = _outer.unprotectedAttributeGenerator.GetAttributes(
+                            new Dictionary<CmsAttributeTableParameter, object>());
 
-				if (_outer.unprotectedAttributeGenerator != null)
-				{
-					Asn1.Cms.AttributeTable attrTable = _outer.unprotectedAttributeGenerator.GetAttributes(
-						new Dictionary<CmsAttributeTableParameter, object>());
+                        Asn1Set unprotectedAttrs = new BerSet(attrTable.ToAsn1EncodableVector());
 
-					Asn1Set unprotectedAttrs = new BerSet(attrTable.ToAsn1EncodableVector());
+                        _envGen.AddObject(new DerTaggedObject(false, 1, unprotectedAttrs));
+                    }
 
-					_envGen.AddObject(new DerTaggedObject(false, 1, unprotectedAttrs));
-				}
-
-				_envGen.Close();
-				_cGen.Close();
-			}
+                    _envGen.Close();
+                    _cGen.Close();
+                }
+                base.Dispose(disposing);
+            }
 		}
 	}
 }
diff --git a/crypto/src/cms/CMSSignedDataStreamGenerator.cs b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
index 5587a9d07..69427c246 100644
--- a/crypto/src/cms/CMSSignedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
@@ -791,7 +791,6 @@ namespace Org.BouncyCastle.Cms
 				_out.WriteByte(value);
 			}
 
-#if PORTABLE
             protected override void Dispose(bool disposing)
             {
                 if (disposing)
@@ -800,13 +799,6 @@ namespace Org.BouncyCastle.Cms
                 }
                 base.Dispose(disposing);
             }
-#else
-			public override void Close()
-            {
-                DoClose();
-				base.Close();
-			}
-#endif
 
             private void DoClose()
             {
diff --git a/crypto/src/cms/CMSTypedStream.cs b/crypto/src/cms/CMSTypedStream.cs
index e99d904b5..d4ca62256 100644
--- a/crypto/src/cms/CMSTypedStream.cs
+++ b/crypto/src/cms/CMSTypedStream.cs
@@ -33,11 +33,7 @@ namespace Org.BouncyCastle.Cms
 			int		bufSize)
 		{
 			_oid = oid;
-#if PORTABLE
-			_in = new FullReaderStream(inStream);
-#else
 			_in = new FullReaderStream(new BufferedStream(inStream, bufSize));
-#endif
 		}
 
 		public string ContentType
@@ -63,10 +59,24 @@ namespace Org.BouncyCastle.Cms
 			{
 			}
 
-			public override int Read(byte[]	buf, int off, int len)
+#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            public override void CopyTo(Stream destination, int bufferSize)
+            {
+				s.CopyTo(destination, bufferSize);
+            }
+#endif
+
+            public override int Read(byte[]	buf, int off, int len)
 			{
-				return Streams.ReadFully(base.s, buf, off, len);
+				return Streams.ReadFully(s, buf, off, len);
 			}
-		}
-	}
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            public override int Read(Span<byte> buffer)
+            {
+                return Streams.ReadFully(s, buffer);
+            }
+#endif
+        }
+    }
 }