File tree Expand file tree Collapse file tree 5 files changed +211
-249
lines changed
pg/src/main/java/org/bouncycastle/bcpg Expand file tree Collapse file tree 5 files changed +211
-249
lines changed Original file line number Diff line number Diff line change @@ -206,8 +206,7 @@ private void writeHeader(
206206 else if (bodyLen <= 0xffff )
207207 {
208208 this .write (hdr | 0x01 );
209- this .write ((byte )(bodyLen >> 8 ));
210- this .write ((byte )(bodyLen ));
209+ StreamUtil .write2OctetLength (this , (int )bodyLen );
211210 }
212211 else
213212 {
@@ -339,22 +338,6 @@ public void writePacket(
339338 p .encode (this );
340339 }
341340
342- void writeShort (short n )
343- throws IOException
344- {
345- out .write ((byte )(n >> 8 ));
346- out .write ((byte )n );
347- }
348-
349- void writeInt (int n )
350- throws IOException
351- {
352- out .write (n >> 24 );
353- out .write (n >> 16 );
354- out .write (n >> 8 );
355- out .write (n );
356- }
357-
358341 /**
359342 * Write a packet to the stream.
360343 * The packet will use the old encoding format if {@link #packetFormat} is {@link PacketFormat#LEGACY}, otherwise
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public MPInteger(
1515 BCPGInputStream in )
1616 throws IOException
1717 {
18- int length = ( in . read () << 8 ) | in . read ( );
18+ int length = StreamUtil . read2OctetLength ( in );
1919 byte [] bytes = new byte [(length + 7 ) / 8 ];
2020
2121 in .readFully (bytes );
@@ -43,8 +43,8 @@ public void encode(
4343 BCPGOutputStream out )
4444 throws IOException
4545 {
46- out . writeShort (( short ) value .bitLength ());
47-
46+ StreamUtil . write2OctetLength ( out , value .bitLength ());
47+
4848 byte [] bytes = value .toByteArray ();
4949
5050 if (bytes [0 ] == 0 )
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ public class PublicKeyPacket
5656
5757 if (version <= VERSION_3 )
5858 {
59- validDays = ( in . read () << 8 ) | in . read ( );
59+ validDays = StreamUtil . read2OctetLength ( in );
6060 }
6161
6262 algorithm = (byte )in .read ();
@@ -178,14 +178,14 @@ public byte[] getEncodedContents()
178178
179179 if (version <= VERSION_3 )
180180 {
181- pOut . writeShort (( short ) validDays );
181+ StreamUtil . write2OctetLength ( pOut , validDays );
182182 }
183183
184184 pOut .write (algorithm );
185185
186186 if (version == VERSION_6 )
187187 {
188- pOut . writeInt ( key .getEncoded ().length );
188+ StreamUtil . write4OctetLength ( pOut , key .getEncoded ().length );
189189 }
190190
191191 pOut .writeObject ((BCPGObject )key );
You can’t perform that action at this time.
0 commit comments