summaryrefslogtreecommitdiffstats
path: root/bcpkix/src/main/java/org/bouncycastle/openssl/jcajce/JcaPEMWriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'bcpkix/src/main/java/org/bouncycastle/openssl/jcajce/JcaPEMWriter.java')
-rw-r--r--bcpkix/src/main/java/org/bouncycastle/openssl/jcajce/JcaPEMWriter.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/bcpkix/src/main/java/org/bouncycastle/openssl/jcajce/JcaPEMWriter.java b/bcpkix/src/main/java/org/bouncycastle/openssl/jcajce/JcaPEMWriter.java
new file mode 100644
index 0000000..423f950
--- /dev/null
+++ b/bcpkix/src/main/java/org/bouncycastle/openssl/jcajce/JcaPEMWriter.java
@@ -0,0 +1,68 @@
+package org.bouncycastle.openssl.jcajce;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.bouncycastle.openssl.PEMEncryptor;
+import org.bouncycastle.util.io.pem.PemGenerationException;
+import org.bouncycastle.util.io.pem.PemObjectGenerator;
+import org.bouncycastle.util.io.pem.PemWriter;
+
+/**
+ * General purpose writer for OpenSSL PEM objects based on JCA/JCE classes.
+ */
+public class JcaPEMWriter
+ extends PemWriter
+{
+ /**
+ * Base constructor.
+ *
+ * @param out output stream to use.
+ */
+ public JcaPEMWriter(Writer out)
+ {
+ super(out);
+ }
+
+ /**
+ * @throws java.io.IOException
+ */
+ public void writeObject(
+ Object obj)
+ throws IOException
+ {
+ writeObject(obj, null);
+ }
+
+ /**
+ * @param obj
+ * @param encryptor
+ * @throws java.io.IOException
+ */
+ public void writeObject(
+ Object obj,
+ PEMEncryptor encryptor)
+ throws IOException
+ {
+ try
+ {
+ super.writeObject(new JcaMiscPEMGenerator(obj, encryptor));
+ }
+ catch (PemGenerationException e)
+ {
+ if (e.getCause() instanceof IOException)
+ {
+ throw (IOException)e.getCause();
+ }
+
+ throw e;
+ }
+ }
+
+ public void writeObject(
+ PemObjectGenerator obj)
+ throws IOException
+ {
+ super.writeObject(obj);
+ }
+}