1 package org.bouncycastle.jce.provider; 2 3 import org.bouncycastle.jce.ProviderConfigurationPermission; 4 // BEGIN android-removed 5 // import org.bouncycastle.jce.provider.asymmetric.ec.EC5Util; 6 // END android-removed 7 import org.bouncycastle.jce.interfaces.ConfigurableProvider; 8 // BEGIN android-removed 9 // import org.bouncycastle.jce.spec.ECParameterSpec; 10 // END android-removed 11 12 import java.io.ByteArrayInputStream; 13 import java.io.IOException; 14 import java.io.InputStream; 15 import java.security.Permission; 16 17 public class ProviderUtil 18 { 19 private static final long MAX_MEMORY = Runtime.getRuntime().maxMemory(); 20 21 private static Permission BC_EC_LOCAL_PERMISSION = new ProviderConfigurationPermission( 22 "BC", ConfigurableProvider.THREAD_LOCAL_EC_IMPLICITLY_CA); 23 private static Permission BC_EC_PERMISSION = new ProviderConfigurationPermission( 24 "BC", ConfigurableProvider.EC_IMPLICITLY_CA); 25 26 private static ThreadLocal threadSpec = new ThreadLocal(); 27 // BEGIN android-removed 28 // private static volatile ECParameterSpec ecImplicitCaParams; 29 // END android-removed 30 setParameter(String parameterName, Object parameter)31 static void setParameter(String parameterName, Object parameter) 32 { 33 SecurityManager securityManager = System.getSecurityManager(); 34 35 // BEGIN android-removed 36 // if (parameterName.equals(ConfigurableProvider.THREAD_LOCAL_EC_IMPLICITLY_CA)) 37 // { 38 // ECParameterSpec curveSpec; 39 // 40 // if (securityManager != null) 41 // { 42 // securityManager.checkPermission(BC_EC_LOCAL_PERMISSION); 43 // } 44 // 45 // if (parameter instanceof ECParameterSpec || parameter == null) 46 // { 47 // curveSpec = (ECParameterSpec)parameter; 48 // } 49 // else // assume java.security.spec 50 // { 51 // curveSpec = EC5Util.convertSpec((java.security.spec.ECParameterSpec)parameter, false); 52 // } 53 // 54 // if (curveSpec == null) 55 // { 56 // threadSpec.remove(); 57 // } 58 // else 59 // { 60 // threadSpec.set(curveSpec); 61 // } 62 // } 63 // else if (parameterName.equals(ConfigurableProvider.EC_IMPLICITLY_CA)) 64 // { 65 // if (securityManager != null) 66 // { 67 // securityManager.checkPermission(BC_EC_PERMISSION); 68 // } 69 // 70 // if (parameter instanceof ECParameterSpec || parameter == null) 71 // { 72 // ecImplicitCaParams = (ECParameterSpec)parameter; 73 // } 74 // else // assume java.security.spec 75 // { 76 // ecImplicitCaParams = EC5Util.convertSpec((java.security.spec.ECParameterSpec)parameter, false); 77 // } 78 // } 79 // END android-removed 80 } 81 82 // BEGIN android-removed 83 // public static ECParameterSpec getEcImplicitlyCa() 84 // { 85 // ECParameterSpec spec = (ECParameterSpec)threadSpec.get(); 86 // 87 // if (spec != null) 88 // { 89 // return spec; 90 // } 91 // 92 // return ecImplicitCaParams; 93 // } 94 // END android-removed 95 getReadLimit(InputStream in)96 static int getReadLimit(InputStream in) 97 throws IOException 98 { 99 if (in instanceof ByteArrayInputStream) 100 { 101 return in.available(); 102 } 103 104 if (MAX_MEMORY > Integer.MAX_VALUE) 105 { 106 return Integer.MAX_VALUE; 107 } 108 109 return (int)MAX_MEMORY; 110 } 111 } 112