Skip to content

Commit 40979ea

Browse files
author
gefeili
committed
Changes around StreamUtil.
1 parent 94b91e1 commit 40979ea

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

pg/src/main/java/org/bouncycastle/bcpg/ArmoredInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class ArmoredInputStream
2525
extends InputStream
2626
{
27-
/*
27+
/**
2828
* set up the decoding table.
2929
*/
3030
private static final byte[] decodingTable;

pg/src/main/java/org/bouncycastle/bcpg/BCPGOutputStream.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,22 @@ public void writePacket(
323323
p.encode(this);
324324
}
325325

326+
void writeShort(short n)
327+
throws IOException
328+
{
329+
out.write((byte)(n >> 8));
330+
out.write((byte)n);
331+
}
332+
333+
void writeInt(int n)
334+
throws IOException
335+
{
336+
out.write(n >> 24);
337+
out.write(n >> 16);
338+
out.write(n >> 8);
339+
out.write(n);
340+
}
341+
326342
void writePacket(
327343
int tag,
328344
byte[] body)

pg/src/main/java/org/bouncycastle/bcpg/MPInteger.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ public void encode(
4343
BCPGOutputStream out)
4444
throws IOException
4545
{
46-
int length = value.bitLength();
47-
48-
out.write(length >> 8);
49-
out.write(length);
46+
out.writeShort((short)value.bitLength());
5047

5148
byte[] bytes = value.toByteArray();
5249

pg/src/main/java/org/bouncycastle/bcpg/PublicKeyPacket.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,14 @@ public byte[] getEncodedContents()
162162

163163
if (version <= VERSION_3)
164164
{
165-
pOut.write((byte)(validDays >> 8));
166-
pOut.write((byte)validDays);
165+
pOut.writeShort((short)validDays);
167166
}
168167

169168
pOut.write(algorithm);
170169

171170
if (version == VERSION_6)
172171
{
173-
int keyOctets = key.getEncoded().length;
174-
pOut.write(keyOctets >> 24);
175-
pOut.write(keyOctets >> 16);
176-
pOut.write(keyOctets >> 8);
177-
pOut.write(keyOctets);
172+
pOut.writeInt(key.getEncoded().length);
178173
}
179174

180175
pOut.writeObject((BCPGObject)key);

pg/src/main/java/org/bouncycastle/bcpg/StreamUtil.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ static long readKeyID(BCPGInputStream in)
109109
static void writeTime(BCPGOutputStream pOut, long time)
110110
throws IOException
111111
{
112-
pOut.write((byte)(time >> 24));
113-
pOut.write((byte)(time >> 16));
114-
pOut.write((byte)(time >> 8));
115-
pOut.write((byte)time);
112+
pOut.writeInt((int) time);
116113
}
117114

118115
static long readTime(BCPGInputStream in)

pg/src/test/java/org/bouncycastle/openpgp/test/PGPKeyRingTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3211,7 +3211,6 @@ private void doTestNoExportPrivateKey(PGPKeyPair keyPair)
32113211
public void testNullEncryption()
32123212
throws Exception
32133213
{
3214-
char[] passPhrase = "fred".toCharArray();
32153214
KeyPairGenerator bareGenerator = KeyPairGenerator.getInstance("RSA", new BouncyCastleProvider());
32163215
bareGenerator.initialize(2048);
32173216
KeyPair rsaPair = bareGenerator.generateKeyPair();

0 commit comments

Comments
 (0)