@@ -14,7 +14,9 @@ public class OnePassSignaturePacketTest
14
14
{
15
15
16
16
// Parse v6 OPS packet and compare its values to a known-good test vector
17
- private void testParseV6OnePassSignaturePacket () throws IOException {
17
+ private void testParseV6OnePassSignaturePacket ()
18
+ throws IOException
19
+ {
18
20
// Version 6 OnePassSignature packet
19
21
// extracted from https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-13.html#name-sample-inline-signed-messag
20
22
byte [] encOPS = Hex .decode ("c44606010a1b2076495f50218890f7f5e2ee3c1822514f70500f551d86e5c921e404e34a53fbaccb186c4f0609a697e4d52dfa6c722b0c1f1e27c18a56708f6525ec27bad9acc901" );
@@ -48,7 +50,9 @@ private void testParseV6OnePassSignaturePacket() throws IOException {
48
50
isEncodingEqual ("OPS Packet encoding mismatch" , encOPS , bOut .toByteArray ());
49
51
}
50
52
51
- private void roundtripV3Packet () throws IOException {
53
+ private void roundtripV3Packet ()
54
+ throws IOException
55
+ {
52
56
OnePassSignaturePacket before = new OnePassSignaturePacket (
53
57
PGPSignature .BINARY_DOCUMENT ,
54
58
HashAlgorithmTags .SHA256 ,
@@ -73,7 +77,8 @@ private void roundtripV3Packet() throws IOException {
73
77
isNull ("OPS v3 MUST NOT have salt" ,
74
78
before .getSalt ());
75
79
76
- for (boolean newTypeIdFormat : new boolean [] {true , false }) {
80
+ for (boolean newTypeIdFormat : new boolean [] {true , false })
81
+ {
77
82
// round-trip the packet by encoding and decoding it
78
83
ByteArrayOutputStream bOut = new ByteArrayOutputStream ();
79
84
BCPGOutputStream pOut = new BCPGOutputStream (bOut , newTypeIdFormat );
@@ -105,7 +110,9 @@ private void roundtripV3Packet() throws IOException {
105
110
}
106
111
}
107
112
108
- private void roundtripV6Packet () throws IOException {
113
+ private void roundtripV6Packet ()
114
+ throws IOException
115
+ {
109
116
byte [] salt = new byte [32 ];
110
117
byte [] fingerprint = Hex .decode ("CB186C4F0609A697E4D52DFA6C722B0C1F1E27C18A56708F6525EC27BAD9ACC9" );
111
118
long keyID = ((fingerprint [0 ] & 0xffL ) << 56 ) |
@@ -143,7 +150,8 @@ private void roundtripV6Packet() throws IOException {
143
150
isTrue ("non-nested OPS is expected to be containing" ,
144
151
before .isContaining ());
145
152
146
- for (boolean newTypeIdFormat : new boolean [] {true , false }) {
153
+ for (boolean newTypeIdFormat : new boolean [] {true , false })
154
+ {
147
155
// round-trip the packet by encoding and decoding it
148
156
ByteArrayOutputStream bOut = new ByteArrayOutputStream ();
149
157
BCPGOutputStream pOut = new BCPGOutputStream (bOut , newTypeIdFormat );
@@ -174,7 +182,9 @@ private void roundtripV6Packet() throws IOException {
174
182
}
175
183
}
176
184
177
- private void roundtripV6PacketWithZeroLengthSalt () throws IOException {
185
+ private void roundtripV6PacketWithZeroLengthSalt ()
186
+ throws IOException
187
+ {
178
188
byte [] salt = new byte [0 ];
179
189
byte [] fingerprint = Hex .decode ("CB186C4F0609A697E4D52DFA6C722B0C1F1E27C18A56708F6525EC27BAD9ACC9" );
180
190
@@ -189,7 +199,8 @@ private void roundtripV6PacketWithZeroLengthSalt() throws IOException {
189
199
isEncodingEqual ("Salt mismatch" ,
190
200
salt , before .getSalt ());
191
201
192
- for (boolean newTypeIdFormat : new boolean [] {true , false }) {
202
+ for (boolean newTypeIdFormat : new boolean [] {true , false })
203
+ {
193
204
// round-trip the packet by encoding and decoding it
194
205
ByteArrayOutputStream bOut = new ByteArrayOutputStream ();
195
206
BCPGOutputStream pOut = new BCPGOutputStream (bOut , newTypeIdFormat );
@@ -218,24 +229,31 @@ private void roundtripV6PacketWithZeroLengthSalt() throws IOException {
218
229
}
219
230
}
220
231
221
- private void parsingOfPacketWithUnknownVersionFails () {
232
+ private void parsingOfPacketWithUnknownVersionFails ()
233
+ {
222
234
// Version 0x99 OnePassSignature packet
223
235
byte [] encOPS = Hex .decode ("c44699010a1b2076495f50218890f7f5e2ee3c1822514f70500f551d86e5c921e404e34a53fbaccb186c4f0609a697e4d52dfa6c722b0c1f1e27c18a56708f6525ec27bad9acc901" );
224
236
225
237
ByteArrayInputStream bIn = new ByteArrayInputStream (encOPS );
226
238
BCPGInputStream pIn = new BCPGInputStream (bIn );
227
239
228
- try {
240
+ try
241
+ {
229
242
pIn .readPacket ();
230
243
fail ("Expected UnsupportedPacketVersionException" );
231
- } catch (IOException e ) {
244
+ }
245
+ catch (IOException e )
246
+ {
232
247
fail ("Expected UnsupportedPacketVersionException" , e );
233
- } catch (UnsupportedPacketVersionException e ) {
248
+ }
249
+ catch (UnsupportedPacketVersionException e )
250
+ {
234
251
// expected
235
252
}
236
253
}
237
254
238
- private void parsingOfPacketWithTruncatedFingerprintFails () {
255
+ private void parsingOfPacketWithTruncatedFingerprintFails ()
256
+ {
239
257
// Version 6 OnePassSignature packet with truncated fingerprint field (20 bytes instead of 32)
240
258
// This error would happen, if a v6 OPS packet was generated with a v4 fingerprint.
241
259
// extracted from https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-13.html#name-sample-inline-signed-messag
@@ -244,21 +262,27 @@ private void parsingOfPacketWithTruncatedFingerprintFails() {
244
262
ByteArrayInputStream bIn = new ByteArrayInputStream (encOPS );
245
263
BCPGInputStream pIn = new BCPGInputStream (bIn );
246
264
247
- try {
265
+ try
266
+ {
248
267
pIn .readPacket ();
249
268
fail ("Expected IOException" );
250
- } catch (IOException e ) {
269
+ }
270
+ catch (IOException e )
271
+ {
251
272
// expected
252
273
}
253
274
}
254
275
255
276
@ Override
256
- public String getName () {
277
+ public String getName ()
278
+ {
257
279
return "OnePassSignaturePacketTest" ;
258
280
}
259
281
260
282
@ Override
261
- public void performTest () throws Exception {
283
+ public void performTest ()
284
+ throws Exception
285
+ {
262
286
testParseV6OnePassSignaturePacket ();
263
287
roundtripV3Packet ();
264
288
roundtripV6Packet ();
@@ -267,7 +291,8 @@ public void performTest() throws Exception {
267
291
roundtripV6PacketWithZeroLengthSalt ();
268
292
}
269
293
270
- public static void main (String [] args ) {
294
+ public static void main (String [] args )
295
+ {
271
296
runTest (new OnePassSignaturePacketTest ());
272
297
}
273
298
}
0 commit comments