Subject: Remove usages of DerOutputStream that is no longer public

Bouncycastle 1.77 compatibility patch

Author: Vladimir Petko <vladimir.petko@canonical.com>
Bug-Ubuntu: https://bugs.launchpad.net/debian/+source/android-platform-tools-base/+bug/2056088
Bug-Debian: https://bugs.debian.org/1058331
Forwarded: not-needed
Last-Update: 2024-03-06

--- a/build-system/builder/src/main/java/com/android/builder/internal/packaging/sign/SignatureExtension.java
+++ b/build-system/builder/src/main/java/com/android/builder/internal/packaging/sign/SignatureExtension.java
@@ -29,7 +29,8 @@
 
 import org.apache.commons.codec.binary.Base64;
 import org.bouncycastle.asn1.ASN1InputStream;
-import org.bouncycastle.asn1.DEROutputStream;
+import org.bouncycastle.asn1.ASN1OutputStream;
+import org.bouncycastle.asn1.ASN1Encoding;
 import org.bouncycastle.cert.jcajce.JcaCertStore;
 import org.bouncycastle.cms.CMSException;
 import org.bouncycastle.cms.CMSProcessableByteArray;
@@ -610,12 +611,12 @@
         /*
          * DEROutputStream is not closeable! OMG!
          */
-        DEROutputStream dos = null;
+        ASN1OutputStream dos = null;
         try (ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded())) {
-            dos = new DEROutputStream(outputBytes);
+            dos = ASN1OutputStream.create(outputBytes, ASN1Encoding.DER);
             dos.writeObject(asn1.readObject());
 
-            DEROutputStream toClose = dos;
+            ASN1OutputStream toClose = dos;
             dos = null;
             toClose.close();
         } catch (IOException e) {
--- a/build-system/builder/src/main/java/com/android/builder/signing/SignedJarApkCreator.java
+++ b/build-system/builder/src/main/java/com/android/builder/signing/SignedJarApkCreator.java
@@ -33,7 +33,8 @@
 import com.google.common.io.Files;
 
 import org.bouncycastle.asn1.ASN1InputStream;
-import org.bouncycastle.asn1.DEROutputStream;
+import org.bouncycastle.asn1.ASN1OutputStream;
+import org.bouncycastle.asn1.ASN1Encoding;
 import org.bouncycastle.cert.jcajce.JcaCertStore;
 import org.bouncycastle.cms.CMSException;
 import org.bouncycastle.cms.CMSProcessableByteArray;
@@ -400,7 +401,7 @@
         CMSSignedData sigData = gen.generate(data, false);
 
         try (ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded())) {
-            DEROutputStream dos = new DEROutputStream(mOutputJar);
+            ASN1OutputStream dos = ASN1OutputStream.create(mOutputJar, ASN1Encoding.DER);
             try {
                 dos.writeObject(asn1.readObject());
             } finally {
