From d43dc816b484f77b8c298943e4aeecb63e58cff6 Mon Sep 17 00:00:00 2001 From: Matthias Wiedemann Date: Tue, 26 Sep 2023 08:11:41 +0000 Subject: [PATCH] #392 replace call to BigInteger.intValueExact to remain comptaible with android api 30 --- src/main/java/com/jcraft/jsch/KeyPairPKCS8.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/jcraft/jsch/KeyPairPKCS8.java b/src/main/java/com/jcraft/jsch/KeyPairPKCS8.java index 048bd80d..e1845cf1 100644 --- a/src/main/java/com/jcraft/jsch/KeyPairPKCS8.java +++ b/src/main/java/com/jcraft/jsch/KeyPairPKCS8.java @@ -862,6 +862,13 @@ static Cipher getCipher(byte[] id, ASN1 encryptparams, byte[][] ivp) throws Exce } static int parseASN1IntegerAsInt(byte[] content) { - return new BigInteger(content).intValueExact(); + BigInteger b = new BigInteger(content); + // https://github.com/mwiede/jsch/issues/392 not using intValueExact() because of Android + // incompatibility. + if (b.bitLength() <= 31) { + return b.intValue(); + } else { + throw new ArithmeticException("BigInteger out of int range"); + } } }