Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Tyley <roberto.tyley@gmail.com>2014-07-15 01:38:01 +0400
committerRoberto Tyley <roberto.tyley@gmail.com>2014-07-26 11:23:17 +0400
commit7cb752aaf746dc0b473afeb9e892b7fbc12666c5 (patch)
treecc4f91ddc18332b5adbe82e3fcb040d976c90105 /core/src/test/java/org/spongycastle/util/io/pem/test/AllTests.java
parent551830f8ea5177042af2c7dd1fc90888bc67387d (diff)
Execute become-spongy.sh
https://github.com/rtyley/spongycastle/blob/3040af/become-spongy.sh
Diffstat (limited to 'core/src/test/java/org/spongycastle/util/io/pem/test/AllTests.java')
-rw-r--r--core/src/test/java/org/spongycastle/util/io/pem/test/AllTests.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/core/src/test/java/org/spongycastle/util/io/pem/test/AllTests.java b/core/src/test/java/org/spongycastle/util/io/pem/test/AllTests.java
new file mode 100644
index 00000000..6c04ace6
--- /dev/null
+++ b/core/src/test/java/org/spongycastle/util/io/pem/test/AllTests.java
@@ -0,0 +1,71 @@
+package org.spongycastle.util.io.pem.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.spongycastle.util.io.pem.PemHeader;
+import org.spongycastle.util.io.pem.PemObject;
+import org.spongycastle.util.io.pem.PemWriter;
+
+public class AllTests
+ extends TestCase
+{
+ public void testPemLength()
+ throws IOException
+ {
+ for (int i = 1; i != 60; i++)
+ {
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[i]);
+ }
+
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[100]);
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[101]);
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[102]);
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[103]);
+
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[1000]);
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[1001]);
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[1002]);
+ lengthTest("CERTIFICATE", Collections.EMPTY_LIST, new byte[1003]);
+
+ List headers = new ArrayList();
+
+ headers.add(new PemHeader("Proc-Type", "4,ENCRYPTED"));
+ headers.add(new PemHeader("DEK-Info", "DES3,0001020304050607"));
+
+ lengthTest("RSA PRIVATE KEY", headers, new byte[103]);
+ }
+
+ private void lengthTest(String type, List headers, byte[] data)
+ throws IOException
+ {
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ PemWriter pWrt = new PemWriter(new OutputStreamWriter(bOut));
+
+ PemObject pemObj = new PemObject(type, headers, data);
+ pWrt.writeObject(pemObj);
+
+ pWrt.close();
+
+ assertEquals(bOut.toByteArray().length, pWrt.getOutputSize(pemObj));
+ }
+
+ public static void main (String[] args)
+ {
+ junit.textui.TestRunner.run (suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("util tests");
+ suite.addTestSuite(AllTests.class);
+ return suite;
+ }
+} \ No newline at end of file