01: package org.bouncycastle.openpgp.test;
02:
03: import org.bouncycastle.openpgp.PGPEncryptedDataList;
04: import org.bouncycastle.openpgp.PGPMarker;
05: import org.bouncycastle.openpgp.PGPObjectFactory;
06: import org.bouncycastle.util.encoders.Base64;
07: import org.bouncycastle.util.test.SimpleTestResult;
08: import org.bouncycastle.util.test.Test;
09: import org.bouncycastle.util.test.TestResult;
10:
11: public class PGPMarkerTest implements Test {
12: private byte[] message1 = Base64
13: .decode("qANQR1DBwU4DdrlXatQSHgoQCADWlhY3bWWaOTm4t2espRWPFQmETeinnieHce64"
14: + "lmEIFzaryEWeSdQc8XGfDzcb7sxq7b5b9Hm6OrACcCbSp2KGEJNG5kJmo2A16UPq"
15: + "JdK4xNelpJRh3KcJPv+N/9VJrMdj4C+DRnGNFg1hTQf3RKsX+ms2V0OBC5vGlOZY"
16: + "zX+XZz/7hl1PXVLN23u4npZI/1xETI2VtRoM76S6oykGXxMtT3+sGU1fAVEKVS45"
17: + "pyQHWbBqApkWrURq0xBqpVfDwOgGw09dJxt2igW9hjvNAd9tJiMGrMF5o2OLlub7"
18: + "c7FiK+dWLLcw+nx7Hl6FQmo9E8qyW8x1Cb78HjR/JXMgH/ngB/4gba6xX+s5TJkW"
19: + "H2Wpp5ePTw39EqHosUMrm05R+C0ha3EyyaJIvKj2WWmImKu5PWo1t37Pi6KHFNC3"
20: + "wsYJMRKnnNtd34luMTOgLpDcdgClzfp2p6EqHMoB7Uj3etlLmbN+vpGgz9qkLBRV"
21: + "7MpR1yE9qrZNeGgbkry6N31w5E7HoAHu5JNcwxgzbJoj2lI8uvs6Gf7fEoQOuAPE"
22: + "W/SGlfR2BdBPiJ1yErMElc2O8LVS0wTwwifHpEsMV+1ntl1EC5d052lo+6q7zNqD"
23: + "uYt1/2if6h9W9fe+S9mzr0ZAtxIN2ZGOFJJRnqzjDQ4siB9nnwr6YgvUVRSr/lQB"
24: + "hDTd0bmjyWacCt0PPMJWchO6A5tzqKUpTWSYibpdks80kLQogQHsJTZd/kpS0I6f"
25: + "gD0HYYlMssZwhg2J2TWwXDpDTgQ6mzFKbGSdOSk/deTJj2+EubzxaZcxZEocCJA8"
26: + "bppCj4kLBnCj1LjYx7A=");
27:
28: private byte[] message2 = Base64
29: .decode("qANQR1DBwU4DZlTzKj+E4aMQCADruFAojUIlHGcnswLIekvhbVnaHnbCt6Kp"
30: + "IL2zppmEIYJ9n1xCO1k+3Y5j9vNATbqCVWs1HD0aAL3PRI1eZ1l8GkIBCd2z"
31: + "tcZpSI/uyI/JCzVW2stCH0gpP2V7zcjk8HaIuBz4ZsyU9m7v6LwCDPB4CTrb"
32: + "Z5nn5Jm3eowonQsRL/3TpJtG+IjTaw29NbCBNNX8quM5LwfIsfWovqNv28r1"
33: + "aX8FsqoTRsWEfQ7dMV/swVGqv0PgKxqErdnZVJ2yOJqjLk+lBJT6zhqPijGV"
34: + "10pc68hdZxxLU1KZq25DAjS12xcAgagjRkOmYE/H1oEjGZlXfS4y/xQ7skHa"
35: + "HI+b04vECACTpQPwCXhxYiNWnf4XhJPONIGyrsXVtsTNwzOShFPmeUvpipP4"
36: + "HknakBkBuUY49xcffQogW/NlGCZnQOulDLE6fCH/krkSmI8WVP5Vhf6bM1Qm"
37: + "92dHZFoTrrcQ9NVGaCNHHWf7KXkNfKdTkE23LdggoVrVAzO4WcdqVc6s/or7"
38: + "jQYP9zXLeu8+GGFMxe/9FCtoIWbujGQHsdDEkCK4h+D44EVDPzbvWj39ZB4w"
39: + "hHoab8RLHd7njcrPeoCPdYkFVCKOSuLdxxYZDbbmgpISaafrafwefkkESeGu"
40: + "JzbNhmyS8zfOiejWzndaLYWUSE/sqISK9Pg+xKundnFPk04+AhIRyYEoUjG3"
41: + "LgGVyM49mrM8E7QwAGU0m/VCJLoOu+N74Z1rp1wFdA5yCllFlONNM4Czhd1D"
42: + "ZMyLFqGXiKlyVCPlUTN2uVisYQGr6iNGYSPxpKjwiAzdeeQBPOETG0vd3nTO"
43: + "MN4BMKcG+kRJd5FU72SRfmbGwPPjd1gts9xFvtj4Tvpkam8=");
44:
45: public TestResult perform() {
46: try {
47: //
48: // test encrypted message
49: //
50: PGPObjectFactory pgpFact = new PGPObjectFactory(message1);
51:
52: Object o;
53:
54: if (pgpFact.nextObject() instanceof PGPMarker) {
55: if (pgpFact.nextObject() instanceof PGPEncryptedDataList) {
56: return new SimpleTestResult(true, getName()
57: + ": Okay");
58: } else {
59: return new SimpleTestResult(false, getName()
60: + ": error processing after marker.");
61: }
62: }
63:
64: pgpFact = new PGPObjectFactory(message2);
65:
66: if (pgpFact.nextObject() instanceof PGPMarker) {
67: if (pgpFact.nextObject() instanceof PGPEncryptedDataList) {
68: return new SimpleTestResult(true, getName()
69: + ": Okay");
70: } else {
71: return new SimpleTestResult(false, getName()
72: + ": error processing after marker.");
73: }
74: }
75:
76: return new SimpleTestResult(false, getName()
77: + ": marker not found");
78: } catch (Exception e) {
79: return new SimpleTestResult(false, getName()
80: + ": exception - " + e.toString());
81: }
82: }
83:
84: public String getName() {
85: return "PGPMarkerTest";
86: }
87:
88: public static void main(String[] args) {
89: Test test = new PGPMarkerTest();
90: TestResult result = test.perform();
91:
92: System.out.println(result.toString());
93: }
94: }
|