1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.vafer.jdeb.signing;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.ByteArrayOutputStream;
20 import java.io.InputStream;
21 import java.util.Arrays;
22
23 import junit.framework.TestCase;
24
25 public final class SigningTestCase extends TestCase {
26
27 public void testClearSign() throws Exception {
28
29 final InputStream ring = getClass().getClassLoader().getResourceAsStream("org/vafer/gpg/secring.gpg");
30
31 assertNotNull(ring);
32
33 final String inputStr = "TEST1\nTEST2\nTEST3\n";
34 final byte[] input = inputStr.getBytes("UTF-8");
35
36 final String expectedOutputStr =
37 "-----BEGIN PGP SIGNED MESSAGE-----\n" +
38 "Hash: SHA1\n" +
39 "\n" +
40 "TEST1\r\n" +
41 "TEST2\r\n" +
42 "TEST3\r\n" +
43 "-----BEGIN PGP SIGNATURE-----\n" +
44 "Version: BCPG v1.29\n" +
45 "\n" +
46 "iEYEARECABAFAkax1rgJEHM9pIAuB02PAABIJgCghFmoCJCZ0CGiqgVLGGPd/Yh5\n" +
47 "FQQAnRVqvI2ij45JQSHYJBblZ0Vv2meN\n" +
48 "=aAAT\n" +
49 "-----END PGP SIGNATURE-----\n";
50
51 final byte[] expectedOutput = expectedOutputStr.getBytes("UTF-8");
52
53 final ByteArrayOutputStream os = new ByteArrayOutputStream();
54
55 SigningUtils.clearSign(
56 new ByteArrayInputStream(input),
57 ring,
58 "2E074D8F", "test",
59 os);
60
61 final byte[] output = os.toByteArray();
62
63 final int from = expectedOutputStr.indexOf("iEYEAREC");
64 final int until = expectedOutputStr.indexOf("=aAAT") + 5;
65 Arrays.fill(output, from, until, (byte)'?');
66 Arrays.fill(expectedOutput, from, until, (byte)'?');
67
68 assertEquals(new String(expectedOutput), new String(output));
69 }
70 }