Skip to content

Commit e89655e

Browse files
author
gefeili
committed
Changes around StreamUtil
1 parent 40979ea commit e89655e

File tree

7 files changed

+179
-168
lines changed

7 files changed

+179
-168
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ else if (l <= 223)
216216
}
217217
else if (l == 255)
218218
{
219-
bodyLen = (this.read() << 24) | (this.read() << 16) | (this.read() << 8) | this.read();
219+
bodyLen = StreamUtil.read4OctetLength(this);
220220
}
221221
else
222222
{
@@ -236,10 +236,10 @@ else if (l == 255)
236236
bodyLen = this.read();
237237
break;
238238
case 1:
239-
bodyLen = (this.read() << 8) | this.read();
239+
bodyLen = StreamUtil.read2OctetLength(this);
240240
break;
241241
case 2:
242-
bodyLen = (this.read() << 24) | (this.read() << 16) | (this.read() << 8) | this.read();
242+
bodyLen = StreamUtil.read4OctetLength(this);
243243
break;
244244
case 3:
245245
partial = true;
@@ -410,7 +410,7 @@ else if (l <= 223)
410410
}
411411
else if (l == 255)
412412
{
413-
dataLength = (in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read();
413+
dataLength = StreamUtil.read4OctetLength(in);
414414
}
415415
else
416416
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class LiteralDataPacket
3535
fileName[i] = (byte)ch;
3636
}
3737

38-
modDate = ((long)in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read();
38+
modDate = StreamUtil.readTime(in);
3939
if (modDate < 0)
4040
{
4141
throw new IOException("literal data truncated in header");
@@ -55,7 +55,7 @@ public int getFormat()
5555
*/
5656
public long getModificationTime()
5757
{
58-
return modDate * 1000L;
58+
return modDate;
5959
}
6060

6161
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class PublicKeyPacket
3636
super(keyTag);
3737

3838
version = in.read();
39-
time = ((long)in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read();
39+
time = StreamUtil.read4OctetLength(in);
4040

4141
if (version <= VERSION_3)
4242
{
@@ -47,7 +47,7 @@ public class PublicKeyPacket
4747
if (version == VERSION_6)
4848
{
4949
// TODO: Use keyOctets to be able to parse unknown keys
50-
long keyOctets = ((long)in.read() << 24) | ((long)in.read() << 16) | ((long)in.read() << 8) | in.read();
50+
long keyOctets = StreamUtil.read4OctetLength(in);
5151
}
5252

5353
switch (algorithm)

0 commit comments

Comments
 (0)