propagate from branch 'i2p.i2p.zzz.test2' (head ec8e362ce8b93280b518c599a3cc075b89085d2b)

to branch 'i2p.i2p' (head c9b1eef91f61f4482ad11c4f2b2d01be67a17ad2)
This commit is contained in:
zzz
2013-12-10 02:26:32 +00:00
54 changed files with 362 additions and 281 deletions

View File

@ -10,6 +10,9 @@ import net.i2p.data.SigningPublicKey;
*
*/
public class DummyDSAEngine extends DSAEngine {
private static final Signature FAKE_SIGNATURE = new Signature(new byte[Signature.SIGNATURE_BYTES]);
public DummyDSAEngine(I2PAppContext context) {
super(context);
}
@ -21,8 +24,6 @@ public class DummyDSAEngine extends DSAEngine {
@Override
public Signature sign(byte data[], SigningPrivateKey signingKey) {
Signature sig = new Signature();
sig.setData(Signature.FAKE_SIGNATURE);
return sig;
return FAKE_SIGNATURE;
}
}
}

View File

@ -399,6 +399,7 @@ public class DataHelper {
* - Leading whitespace is not trimmed
* - '=' is the only key-termination character (not ':' or whitespace)
*
* As of 0.9.10, an empty value is allowed.
*/
public static void loadProps(Properties props, File file) throws IOException {
loadProps(props, file, false);
@ -442,11 +443,12 @@ public class DataHelper {
// it was a horrible idea anyway
//val = val.replaceAll("\\\\r","\r");
//val = val.replaceAll("\\\\n","\n");
if ( (key.length() > 0) && (val.length() > 0) )
if (forceLowerCase)
props.setProperty(key.toLowerCase(Locale.US), val);
else
props.setProperty(key, val);
// as of 0.9.10, an empty value is allowed
if (forceLowerCase)
props.setProperty(key.toLowerCase(Locale.US), val);
else
props.setProperty(key, val);
}
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}

View File

@ -191,13 +191,21 @@ public class PrivateKeyFile {
this.dest = d;
}
/** change cert type - caller must also call write() */
/**
* Change cert type - caller must also call write().
* Side effect - creates new Destination object.
*/
public Certificate setCertType(int t) {
if (this.dest == null)
throw new IllegalArgumentException("Dest is null");
Certificate c = new Certificate();
c.setCertificateType(t);
this.dest.setCertificate(c);
// dests now immutable, must create new
Destination newdest = new Destination();
newdest.setPublicKey(dest.getPublicKey());
newdest.setSigningPublicKey(dest.getSigningPublicKey());
newdest.setCertificate(c);
dest = newdest;
return c;
}

View File

@ -25,7 +25,11 @@ public class Signature extends SimpleDataStructure {
private static final SigType DEF_TYPE = SigType.DSA_SHA1;
/** 40 */
public final static int SIGNATURE_BYTES = DEF_TYPE.getSigLen();
/** all zeros */
/**
* all zeros
* @deprecated to be removed
*/
public final static byte[] FAKE_SIGNATURE = new byte[SIGNATURE_BYTES];
private final SigType _type;

View File

@ -25,7 +25,12 @@ import net.i2p.util.ConcurrentHashSet;
*/
public abstract class Translate {
public static final String PROP_LANG = "routerconsole.lang";
/** @since 0.9.10 */
public static final String PROP_COUNTRY = "routerconsole.country";
/** non-null, two-letter lower case, may be "" */
private static final String _localeLang = Locale.getDefault().getLanguage();
/** non-null, two-letter upper case, may be "" */
private static final String _localeCountry = Locale.getDefault().getCountry();
private static final Map<String, ResourceBundle> _bundles = new ConcurrentHashMap<String, ResourceBundle>(16);
private static final Set<String> _missing = new ConcurrentHashSet<String>(16);
/** use to look for untagged strings */
@ -42,7 +47,7 @@ public abstract class Translate {
// shouldnt happen but dont dump the po headers if it does
if (key.equals(""))
return key;
ResourceBundle bundle = findBundle(bun, lang);
ResourceBundle bundle = findBundle(bun, lang, getCountry(ctx));
if (bundle == null)
return key;
try {
@ -110,7 +115,7 @@ public abstract class Translate {
return TEST_STRING + '(' + n + ')' + TEST_STRING;
ResourceBundle bundle = null;
if (!lang.equals("en"))
bundle = findBundle(bun, lang);
bundle = findBundle(bun, lang, getCountry(ctx));
String x;
if (bundle == null)
x = n == 1 ? s : p;
@ -129,7 +134,10 @@ public abstract class Translate {
}
}
/** @return lang in routerconsole.lang property, else current locale */
/**
* Two-letter lower case
* @return lang in routerconsole.lang property, else current locale
*/
public static String getLanguage(I2PAppContext ctx) {
String lang = ctx.getProperty(PROP_LANG);
if (lang == null || lang.length() <= 0)
@ -137,14 +145,39 @@ public abstract class Translate {
return lang;
}
/** cache both found and not found for speed */
private static ResourceBundle findBundle(String bun, String lang) {
String key = bun + '-' + lang;
/**
* Two-letter upper case or ""
* @return country in routerconsole.country property, else current locale
* @since 0.9.10
*/
public static String getCountry(I2PAppContext ctx) {
// property may be empty so we don't have a non-default
// language and a default country
return ctx.getProperty(PROP_COUNTRY, _localeCountry);
}
/**
* cache both found and not found for speed
* @param lang non-null, if "" returns null
* @param country non-null, may be ""
* @return null if not found
*/
private static ResourceBundle findBundle(String bun, String lang, String country) {
String key = bun + '-' + lang + '-' + country;
ResourceBundle rv = _bundles.get(key);
if (rv == null && !_missing.contains(key)) {
if ("".equals(lang)) {
_missing.add(key);
return null;
}
try {
Locale loc;
if ("".equals(country))
loc = new Locale(lang);
else
loc = new Locale(lang, country);
// We must specify the class loader so that a webapp can find the bundle in the .war
rv = ResourceBundle.getBundle(bun, new Locale(lang), Thread.currentThread().getContextClassLoader());
rv = ResourceBundle.getBundle(bun, loc, Thread.currentThread().getContextClassLoader());
if (rv != null)
_bundles.put(key, rv);
} catch (MissingResourceException e) {