From c89aab88022aea20d0aa7163986936f264ce8134 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 13 Oct 2017 17:04:44 +0200 Subject: [PATCH] reduce visibility where unnecessary --- .../securitytoken/CardCapabilities.java | 3 +- .../keychain/securitytoken/KeyFormat.java | 8 ++--- .../securitytoken/OpenPgpCapabilities.java | 29 ++++++++++--------- .../keychain/securitytoken/ResponseApdu.java | 1 + .../securitytoken/SCP11bSecureMessaging.java | 4 +-- .../securitytoken/SecurityTokenUtils.java | 18 ++++++------ 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/CardCapabilities.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/CardCapabilities.java index d6600ab01..dc8a65e6d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/CardCapabilities.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/CardCapabilities.java @@ -21,7 +21,8 @@ import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException; import java.nio.ByteBuffer; -public class CardCapabilities { +@SuppressWarnings("WeakerAccess") +class CardCapabilities { private static final int MASK_CHAINING = 1 << 7; private static final int MASK_EXTENDED = 1 << 6; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/KeyFormat.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/KeyFormat.java index 9d612517b..aea814cc4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/KeyFormat.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/KeyFormat.java @@ -25,18 +25,18 @@ import org.sufficientlysecure.keychain.ui.CreateSecurityTokenAlgorithmFragment; public abstract class KeyFormat { - public enum KeyFormatType { + enum KeyFormatType { RSAKeyFormatType, ECKeyFormatType - }; + } private final KeyFormatType mKeyFormatType; - public KeyFormat(final KeyFormatType keyFormatType) { + KeyFormat(final KeyFormatType keyFormatType) { mKeyFormatType = keyFormatType; } - public final KeyFormatType keyFormatType() { + final KeyFormatType keyFormatType() { return mKeyFormatType; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/OpenPgpCapabilities.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/OpenPgpCapabilities.java index 082ae90ec..2edc03c0d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/OpenPgpCapabilities.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/OpenPgpCapabilities.java @@ -21,7 +21,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -public class OpenPgpCapabilities { +@SuppressWarnings("unused") // just expose all included data +class OpenPgpCapabilities { private final static int MASK_SM = 1 << 7; private final static int MASK_KEY_IMPORT = 1 << 5; private final static int MASK_ATTRIBUTES_CHANGABLE = 1 << 2; @@ -40,12 +41,12 @@ public class OpenPgpCapabilities { private Map mKeyFormats; - public OpenPgpCapabilities(byte[] data) throws IOException { + OpenPgpCapabilities(byte[] data) throws IOException { mKeyFormats = new HashMap<>(); updateWithData(data); } - public void updateWithData(byte[] data) throws IOException { + void updateWithData(byte[] data) throws IOException { Iso7816TLV[] tlvs = Iso7816TLV.readList(data, true); if (tlvs.length == 1 && tlvs[0].mT == 0x6E) { tlvs = ((Iso7816TLV.Iso7816CompositeTLV) tlvs[0]).mSubs; @@ -114,47 +115,47 @@ public class OpenPgpCapabilities { mMaxRspLen = (v[8] << 8) + v[9]; } - public boolean isPw1ValidForMultipleSignatures() { + boolean isPw1ValidForMultipleSignatures() { return mPw1ValidForMultipleSignatures; } - public byte[] getAid() { + byte[] getAid() { return mAid; } - public byte[] getHistoricalBytes() { + byte[] getHistoricalBytes() { return mHistoricalBytes; } - public boolean isHasSM() { + boolean isHasSM() { return mHasSM; } - public boolean isAttributesChangable() { + boolean isAttributesChangable() { return mAttriburesChangable; } - public boolean isHasKeyImport() { + boolean isHasKeyImport() { return mHasKeyImport; } - public boolean isHasAESSM() { + boolean isHasAESSM() { return isHasSM() && ((mSMType == 1) || (mSMType == 2)); } - public boolean isHasSCP11bSM() { + boolean isHasSCP11bSM() { return isHasSM() && (mSMType == 3); } - public int getMaxCmdLen() { + int getMaxCmdLen() { return mMaxCmdLen; } - public int getMaxRspLen() { + int getMaxRspLen() { return mMaxRspLen; } - public KeyFormat getFormatForKeyType(KeyType keyType) { + KeyFormat getFormatForKeyType(KeyType keyType) { return mKeyFormats.get(keyType); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/ResponseApdu.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/ResponseApdu.java index 0ace27b71..b3eb85743 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/ResponseApdu.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/ResponseApdu.java @@ -24,6 +24,7 @@ import com.google.auto.value.AutoValue; /** A response APDU as defined in ISO/IEC 7816-4. */ @AutoValue +@SuppressWarnings("WeakerAccess") public abstract class ResponseApdu { private static final int APDU_SW_SUCCESS = 0x9000; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SCP11bSecureMessaging.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SCP11bSecureMessaging.java index a135caae9..fb7b3e5ec 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SCP11bSecureMessaging.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SCP11bSecureMessaging.java @@ -150,7 +150,7 @@ class SCP11bSecureMessaging implements SecureMessaging { && (mMacChaining != null); } - private static final ECParameterSpec getAlgorithmParameterSpec(final ECKeyFormat kf) + private static ECParameterSpec getAlgorithmParameterSpec(final ECKeyFormat kf) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidParameterSpecException { final AlgorithmParameters algoParams = AlgorithmParameters.getInstance(SCP11B_KEY_AGREEMENT_KEY_ALGO, PROVIDER); @@ -273,7 +273,7 @@ class SCP11bSecureMessaging implements SecureMessaging { } - public static void establish(final SecurityTokenConnection t, final Context ctx, OpenPgpCommandApduFactory commandFactory) + static void establish(final SecurityTokenConnection t, final Context ctx, OpenPgpCommandApduFactory commandFactory) throws SecureMessagingException, IOException { CommandAPDU cmd; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenUtils.java index d8077c615..31df10576 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenUtils.java @@ -33,8 +33,8 @@ import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPrivateCrtKey; -public class SecurityTokenUtils { - public static byte[] attributesFromSecretKey(final KeyType slot, final CanonicalizedSecretKey secretKey) throws IOException, PgpGeneralException { +class SecurityTokenUtils { + static byte[] attributesFromSecretKey(final KeyType slot, final CanonicalizedSecretKey secretKey) throws IOException, PgpGeneralException { if (secretKey.isRSA()) { final int mModulusLength = secretKey.getBitStrength(); final int mExponentLength = secretKey.getSecurityTokenRSASecretKey().getPublicExponent().bitLength(); @@ -46,7 +46,7 @@ public class SecurityTokenUtils { attrs[i++] = (byte) (mModulusLength & 0xff); attrs[i++] = (byte) ((mExponentLength >> 8) & 0xff); attrs[i++] = (byte) (mExponentLength & 0xff); - attrs[i++] = RSAKeyFormat.RSAAlgorithmFormat.CRT_WITH_MODULUS.getValue(); + attrs[i] = RSAKeyFormat.RSAAlgorithmFormat.CRT_WITH_MODULUS.getValue(); return attrs; } else if (secretKey.isEC()) { @@ -70,8 +70,8 @@ public class SecurityTokenUtils { } - public static byte[] createRSAPrivKeyTemplate(RSAPrivateCrtKey secretKey, KeyType slot, - RSAKeyFormat format) throws IOException { + static byte[] createRSAPrivKeyTemplate(RSAPrivateCrtKey secretKey, KeyType slot, + RSAKeyFormat format) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(), template = new ByteArrayOutputStream(), data = new ByteArrayOutputStream(), @@ -138,8 +138,8 @@ public class SecurityTokenUtils { return res.toByteArray(); } - public static byte[] createECPrivKeyTemplate(ECPrivateKey secretKey, ECPublicKey publicKey, KeyType slot, - ECKeyFormat format) throws IOException { + static byte[] createECPrivKeyTemplate(ECPrivateKey secretKey, ECPublicKey publicKey, KeyType slot, + ECKeyFormat format) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(), template = new ByteArrayOutputStream(), data = new ByteArrayOutputStream(), @@ -184,7 +184,7 @@ public class SecurityTokenUtils { return res.toByteArray(); } - public static byte[] encodeLength(int len) { + static byte[] encodeLength(int len) { if (len < 0) { throw new IllegalArgumentException("length is negative"); } else if (len >= 16777216) { @@ -214,7 +214,7 @@ public class SecurityTokenUtils { return res; } - public static void writeBits(ByteArrayOutputStream stream, BigInteger value, int width) { + static void writeBits(ByteArrayOutputStream stream, BigInteger value, int width) { if (value.signum() == -1) { throw new IllegalArgumentException("value is negative"); } else if (width <= 0) {