Skip to content

Commit 118b9ef

Browse files
author
gefeili
committed
Refactor in PublicKeyKeyEncryptionMethodGenerator.getSessionInfo
1 parent 6912a51 commit 118b9ef

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

pg/src/main/java/org/bouncycastle/openpgp/operator/PublicKeyKeyEncryptionMethodGenerator.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,7 @@ protected static byte[] concatECDHEphKeyWithWrappedSessionKey(byte[] ephPubEncod
242242

243243
protected static byte[] getSessionInfo(byte[] ephPubEncoding, byte optSymKeyAlgorithm, byte[] wrappedSessionKey)
244244
{
245-
int len = ephPubEncoding.length + 1 + wrappedSessionKey.length;
246-
if (optSymKeyAlgorithm != 0)
247-
{
248-
len++;
249-
}
245+
int len = ephPubEncoding.length + wrappedSessionKey.length + (optSymKeyAlgorithm != 0 ? 2 : 1);
250246
byte[] out = new byte[len];
251247
// ephemeral pub key
252248
System.arraycopy(ephPubEncoding, 0, out, 0, ephPubEncoding.length);
@@ -256,14 +252,9 @@ protected static byte[] getSessionInfo(byte[] ephPubEncoding, byte optSymKeyAlgo
256252
if (optSymKeyAlgorithm != 0)
257253
{
258254
out[ephPubEncoding.length + 1] = optSymKeyAlgorithm;
259-
// wrapped session key
260-
System.arraycopy(wrappedSessionKey, 0, out, ephPubEncoding.length + 1 + 1, wrappedSessionKey.length);
261-
}
262-
else
263-
{
264-
// wrapped session key
265-
System.arraycopy(wrappedSessionKey, 0, out, ephPubEncoding.length + 1, wrappedSessionKey.length);
266255
}
256+
// wrapped session key
257+
System.arraycopy(wrappedSessionKey, 0, out, len - wrappedSessionKey.length, wrappedSessionKey.length);
267258

268259
return out;
269260
}

0 commit comments

Comments
 (0)