Add spongy castle sources to libraries folder
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
|
||||
package java.security.interfaces;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.spec.RSAOtherPrimeInfo;
|
||||
|
||||
/**
|
||||
* The interface to an RSA multi-prime private key, as defined in the
|
||||
* PKCS#1 v2.1, using the Chinese Remainder Theorem (CRT) information values.
|
||||
*
|
||||
* @since 1.4
|
||||
* @see RSAPrivateKeySpec, RSAMultiPrimePrivateCrtKeySpec, RSAPrivateKey,
|
||||
* RSAPrivateCrtKey
|
||||
*/
|
||||
public interface RSAMultiPrimePrivateCrtKey
|
||||
extends RSAPrivateKey
|
||||
{
|
||||
/**
|
||||
* Returns the public exponent.
|
||||
*
|
||||
* @returns the public exponent.
|
||||
*/
|
||||
public BigInteger getPublicExponent();
|
||||
|
||||
/**
|
||||
* Returns the primeP.
|
||||
*
|
||||
* @returns the primeP.
|
||||
*/
|
||||
public BigInteger getPrimeP();
|
||||
|
||||
/**
|
||||
* Returns the primeQ.
|
||||
*
|
||||
* @returns the primeQ.
|
||||
*/
|
||||
public BigInteger getPrimeQ();
|
||||
|
||||
/**
|
||||
* Returns the primeExponentP.
|
||||
*
|
||||
* @returns the primeExponentP.
|
||||
*/
|
||||
public BigInteger getPrimeExponentP();
|
||||
|
||||
/**
|
||||
* Returns the primeExponentQ.
|
||||
*
|
||||
* @returns the primeExponentQ.
|
||||
*/
|
||||
public BigInteger getPrimeExponentQ();
|
||||
|
||||
/**
|
||||
* Returns the crtCoefficient.
|
||||
*
|
||||
* @returns the crtCoefficient.
|
||||
*/
|
||||
public BigInteger getCrtCoefficient();
|
||||
|
||||
/**
|
||||
* Returns the otherPrimeInfo or null if there are only two prime
|
||||
* factors (p and q).
|
||||
*
|
||||
* @returns the otherPrimeInfo.
|
||||
*/
|
||||
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
package java.security.spec;
|
||||
|
||||
/**
|
||||
* This class specifies a parameter spec for RSA PSS encoding scheme,
|
||||
* as defined in the PKCS#1 v2.1.
|
||||
*
|
||||
* @since 1.4
|
||||
* @see AlgorithmParameterSpec, Signature
|
||||
*/
|
||||
public class PSSParameterSpec
|
||||
extends Object
|
||||
implements AlgorithmParameterSpec
|
||||
{
|
||||
private int saltLen;
|
||||
|
||||
/**
|
||||
* Creates a new PSSParameterSpec given the salt length as defined
|
||||
* in PKCS#1.
|
||||
*
|
||||
* @param saltLen - the length of salt in bits to be used in PKCS#1
|
||||
* PSS encoding.
|
||||
* @throws IllegalArgumentException - if saltLen is less than 0.
|
||||
*/
|
||||
public PSSParameterSpec(int saltLen)
|
||||
{
|
||||
if ( saltLen < 0 )
|
||||
{
|
||||
throw new IllegalArgumentException("Salt length must be >= 0");
|
||||
}
|
||||
|
||||
this.saltLen = saltLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the salt length in bits.
|
||||
*
|
||||
* @returns the salt length.
|
||||
*/
|
||||
public int getSaltLength()
|
||||
{
|
||||
return saltLen;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package java.security.spec;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* specifies parameters to be used for the generation of
|
||||
* a RSA key pair.
|
||||
*/
|
||||
public class RSAKeyGenParameterSpec
|
||||
implements AlgorithmParameterSpec
|
||||
{
|
||||
static BigInteger F0 = BigInteger.valueOf(3);
|
||||
static BigInteger F4 = BigInteger.valueOf(65537);
|
||||
|
||||
private int keysize;
|
||||
private BigInteger publicExponent;
|
||||
|
||||
public RSAKeyGenParameterSpec(
|
||||
int keysize,
|
||||
BigInteger publicExponent)
|
||||
{
|
||||
this.keysize = keysize;
|
||||
this.publicExponent = publicExponent;
|
||||
}
|
||||
|
||||
public int getKeysize()
|
||||
{
|
||||
return keysize;
|
||||
}
|
||||
|
||||
public BigInteger getPublicExponent()
|
||||
{
|
||||
return publicExponent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
|
||||
package java.security.spec;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* This class specifies an RSA multi-prime private key, as defined in
|
||||
* the PKCS#1 v2.1, using the Chinese Remainder Theorem (CRT) information
|
||||
* values for efficiency.
|
||||
*
|
||||
* @since 1.4
|
||||
* @see Key, KeyFactory, KeySpec, PKCS8EncodedKeySpec, RSAPrivateKeySpec,
|
||||
* RSAPublicKeySpec, RSAOtherPrimeInfo
|
||||
*/
|
||||
public class RSAMultiPrimePrivateCrtKeySpec
|
||||
extends RSAPrivateKeySpec
|
||||
{
|
||||
private BigInteger publicExponent;
|
||||
private BigInteger privateExponent;
|
||||
private BigInteger primeP;
|
||||
private BigInteger primeQ;
|
||||
private BigInteger primeExponentP;
|
||||
private BigInteger primeExponentQ;
|
||||
private BigInteger crtCoefficient;
|
||||
private RSAOtherPrimeInfo[] otherPrimeInfo;
|
||||
|
||||
/**
|
||||
* Creates a new RSAMultiPrimePrivateCrtKeySpec given the modulus,
|
||||
* publicExponent, privateExponent, primeP, primeQ, primeExponentP,
|
||||
* primeExponentQ, crtCoefficient, and otherPrimeInfo as defined in
|
||||
* PKCS#1 v2.1.
|
||||
*
|
||||
* Note that otherPrimeInfo is cloned when constructing this object.
|
||||
*
|
||||
* @param modulus - the modulus n.
|
||||
* @param publicExponent - the public exponent e.
|
||||
* @param privateExponent - the private exponent d.
|
||||
* @param primeP - the prime factor p of n.
|
||||
* @param primeQ - the prime factor q of n.
|
||||
* @param primeExponentP - this is d mod (p-1).
|
||||
* @param primeExponentQ - this is d mod (q-1).
|
||||
* @param crtCoefficient - the Chinese Remainder Theorem coefficient q-1
|
||||
* mod p.
|
||||
* @param otherPrimeInfo - triplets of the rest of primes, null can be
|
||||
* specified if there are only two prime factors (p and q).
|
||||
* @throws NullPointerException - if any of the parameters, i.e. modulus,
|
||||
* publicExponent, privateExponent, primeP, primeQ, primeExponentP,
|
||||
* primeExponentQ, crtCoefficient, is null.
|
||||
* @throws IllegalArgumentException - if an empty, i.e. 0-length,
|
||||
* otherPrimeInfo is specified.
|
||||
*/
|
||||
public RSAMultiPrimePrivateCrtKeySpec(
|
||||
BigInteger modulus,
|
||||
BigInteger publicExponent,
|
||||
BigInteger privateExponent,
|
||||
BigInteger primeP,
|
||||
BigInteger primeQ,
|
||||
BigInteger primeExponentP,
|
||||
BigInteger primeExponentQ,
|
||||
BigInteger crtCoefficient,
|
||||
RSAOtherPrimeInfo[] otherPrimeInfo)
|
||||
{
|
||||
super(modulus, privateExponent);
|
||||
|
||||
if ( publicExponent == null || primeP == null || primeQ == null
|
||||
|| primeExponentP == null || primeExponentQ == null
|
||||
|| crtCoefficient == null )
|
||||
{
|
||||
throw new NullPointerException("Invalid null argument");
|
||||
}
|
||||
|
||||
if ( otherPrimeInfo != null )
|
||||
{
|
||||
if ( otherPrimeInfo.length == 0 )
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid length for otherPrimeInfo");
|
||||
}
|
||||
|
||||
this.otherPrimeInfo = (RSAOtherPrimeInfo[])otherPrimeInfo.clone();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public exponent.
|
||||
*
|
||||
* @returns the public exponent.
|
||||
*/
|
||||
public BigInteger getPublicExponent()
|
||||
{
|
||||
return publicExponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primeP.
|
||||
*
|
||||
* @returns the primeP.
|
||||
*/
|
||||
public BigInteger getPrimeP()
|
||||
{
|
||||
return primeP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primeQ.
|
||||
*
|
||||
* @returns the primeQ.
|
||||
*/
|
||||
public BigInteger getPrimeQ()
|
||||
{
|
||||
return primeQ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primeExponentP.
|
||||
*
|
||||
* @returns the primeExponentP.
|
||||
*/
|
||||
public BigInteger getPrimeExponentP()
|
||||
{
|
||||
return primeExponentP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primeExponentQ.
|
||||
*
|
||||
* @returns the primeExponentQ.
|
||||
*/
|
||||
public BigInteger getPrimeExponentQ()
|
||||
{
|
||||
return primeExponentQ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the crtCofficient.
|
||||
*
|
||||
* @returns the crtCofficient.
|
||||
*/
|
||||
public BigInteger getCrtCoefficient()
|
||||
{
|
||||
return crtCoefficient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the otherPrimeInfo or null if there are only
|
||||
* two prime factors (p and q).
|
||||
*
|
||||
* @returns the otherPrimeInfo.
|
||||
*/
|
||||
public RSAOtherPrimeInfo[] getOtherPrimeInfo()
|
||||
{
|
||||
if ( otherPrimeInfo != null )
|
||||
{
|
||||
return (RSAOtherPrimeInfo[])otherPrimeInfo.clone();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
|
||||
package java.security.spec;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* This class represents the triplet (prime, exponent, and coefficient)
|
||||
* inside RSA's OtherPrimeInfo structure, as defined in the PKCS#1 v2.1.
|
||||
* The ASN.1 syntax of RSA's OtherPrimeInfo is as follows:
|
||||
*
|
||||
* <pre>
|
||||
* OtherPrimeInfo ::= SEQUENCE {
|
||||
* prime INTEGER,
|
||||
* exponent INTEGER,
|
||||
* coefficient INTEGER
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class RSAOtherPrimeInfo
|
||||
extends Object
|
||||
{
|
||||
private BigInteger prime;
|
||||
private BigInteger primeExponent;
|
||||
private BigInteger crtCoefficient;
|
||||
|
||||
/**
|
||||
* Creates a new RSAOtherPrimeInfo given the prime, primeExponent,
|
||||
* and crtCoefficient as defined in PKCS#1.
|
||||
*
|
||||
* @param prime - the prime factor of n.
|
||||
* @param primeExponent - the exponent.
|
||||
* @param crtCoefficient - the Chinese Remainder Theorem coefficient.
|
||||
* @throws NullPointerException - if any of the parameters, i.e. prime,
|
||||
* primeExponent, crtCoefficient, is null.
|
||||
*/
|
||||
public RSAOtherPrimeInfo(
|
||||
BigInteger prime,
|
||||
BigInteger primeExponent,
|
||||
BigInteger crtCoefficient)
|
||||
{
|
||||
if ( prime == null || primeExponent == null || crtCoefficient == null )
|
||||
{
|
||||
throw new NullPointerException("Null parameter");
|
||||
}
|
||||
|
||||
this.prime = prime;
|
||||
this.primeExponent = primeExponent;
|
||||
this.crtCoefficient = crtCoefficient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prime.
|
||||
*
|
||||
* @returns the prime.
|
||||
*/
|
||||
public final BigInteger getPrime()
|
||||
{
|
||||
return prime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prime's exponent.
|
||||
*
|
||||
* @returns the primeExponent.
|
||||
*/
|
||||
public final BigInteger getExponent()
|
||||
{
|
||||
return primeExponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prime's crtCoefficient.
|
||||
*
|
||||
* @returns the crtCoefficient.
|
||||
*/
|
||||
public final BigInteger getCrtCoefficient()
|
||||
{
|
||||
return crtCoefficient;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,464 @@
|
||||
package org.spongycastle.i18n;
|
||||
|
||||
import org.spongycastle.i18n.filter.Filter;
|
||||
import org.spongycastle.i18n.filter.TrustedInput;
|
||||
import org.spongycastle.i18n.filter.UntrustedInput;
|
||||
import org.spongycastle.i18n.filter.UntrustedUrlInput;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.Format;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class LocalizedMessage
|
||||
{
|
||||
protected static final int NO_FILTER = 0;
|
||||
protected static final int FILTER = 1;
|
||||
protected static final int FILTER_URL = 2;
|
||||
|
||||
protected String id;
|
||||
protected String resource;
|
||||
|
||||
// ISO-8859-1 is the default encoding
|
||||
public static final String DEFAULT_ENCODING = "ISO-8859-1";
|
||||
protected String encoding = DEFAULT_ENCODING;
|
||||
|
||||
protected FilteredArguments arguments;
|
||||
protected FilteredArguments extraArgs = null;
|
||||
|
||||
protected Filter filter = null;
|
||||
|
||||
protected ClassLoader loader = null;
|
||||
|
||||
/**
|
||||
* Constructs a new LocalizedMessage using <code>resource</code> as the base name for the
|
||||
* RessourceBundle and <code>id</code> as the message bundle id the resource file.
|
||||
* @param resource base name of the resource file
|
||||
* @param id the id of the corresponding bundle in the resource file
|
||||
* @throws NullPointerException if <code>resource</code> or <code>id</code> is <code>null</code>
|
||||
*/
|
||||
public LocalizedMessage(String resource,String id) throws NullPointerException
|
||||
{
|
||||
if (resource == null || id == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.id = id;
|
||||
this.resource = resource;
|
||||
arguments = new FilteredArguments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new LocalizedMessage using <code>resource</code> as the base name for the
|
||||
* RessourceBundle and <code>id</code> as the message bundle id the resource file.
|
||||
* @param resource base name of the resource file
|
||||
* @param id the id of the corresponding bundle in the resource file
|
||||
* @param encoding the encoding of the resource file
|
||||
* @throws NullPointerException if <code>resource</code> or <code>id</code> is <code>null</code>
|
||||
* @throws UnsupportedEncodingException if the encoding is not supported
|
||||
*/
|
||||
public LocalizedMessage(String resource,String id, String encoding) throws NullPointerException, UnsupportedEncodingException
|
||||
{
|
||||
if (resource == null || id == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.id = id;
|
||||
this.resource = resource;
|
||||
arguments = new FilteredArguments();
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new LocalizedMessage using <code>resource</code> as the base name for the
|
||||
* RessourceBundle and <code>id</code> as the message bundle id the resource file.
|
||||
* @param resource base name of the resource file
|
||||
* @param id the id of the corresponding bundle in the resource file
|
||||
* @param arguments an array containing the arguments for the message
|
||||
* @throws NullPointerException if <code>resource</code> or <code>id</code> is <code>null</code>
|
||||
*/
|
||||
public LocalizedMessage(String resource, String id, Object[] arguments) throws NullPointerException
|
||||
{
|
||||
if (resource == null || id == null || arguments == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.id = id;
|
||||
this.resource = resource;
|
||||
this.arguments = new FilteredArguments(arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new LocalizedMessage using <code>resource</code> as the base name for the
|
||||
* RessourceBundle and <code>id</code> as the message bundle id the resource file.
|
||||
* @param resource base name of the resource file
|
||||
* @param id the id of the corresponding bundle in the resource file
|
||||
* @param encoding the encoding of the resource file
|
||||
* @param arguments an array containing the arguments for the message
|
||||
* @throws NullPointerException if <code>resource</code> or <code>id</code> is <code>null</code>
|
||||
* @throws UnsupportedEncodingException if the encoding is not supported
|
||||
*/
|
||||
public LocalizedMessage(String resource, String id, String encoding, Object[] arguments) throws NullPointerException, UnsupportedEncodingException
|
||||
{
|
||||
if (resource == null || id == null || arguments == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.id = id;
|
||||
this.resource = resource;
|
||||
this.arguments = new FilteredArguments(arguments);
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the entry <code>id + "." + key</code> from the resource file and returns a
|
||||
* formated message for the given Locale and TimeZone.
|
||||
* @param key second part of the entry id
|
||||
* @param loc the used {@link Locale}
|
||||
* @param timezone the used {@link TimeZone}
|
||||
* @return a Strng containing the localized message
|
||||
* @throws MissingEntryException if the resource file is not available or the entry does not exist.
|
||||
*/
|
||||
public String getEntry(String key,Locale loc, TimeZone timezone) throws MissingEntryException
|
||||
{
|
||||
String entry = id;
|
||||
if (key != null)
|
||||
{
|
||||
entry += "." + key;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ResourceBundle bundle;
|
||||
if (loader == null)
|
||||
{
|
||||
bundle = ResourceBundle.getBundle(resource,loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
bundle = ResourceBundle.getBundle(resource, loc);
|
||||
}
|
||||
String result = bundle.getString(entry);
|
||||
if (!encoding.equals(DEFAULT_ENCODING))
|
||||
{
|
||||
result = new String(result.getBytes(DEFAULT_ENCODING), encoding);
|
||||
}
|
||||
if (!arguments.isEmpty())
|
||||
{
|
||||
result = formatWithTimeZone(result,arguments.getFilteredArgs(loc),loc,timezone);
|
||||
}
|
||||
result = addExtraArgs(result, loc);
|
||||
return result;
|
||||
}
|
||||
catch (MissingResourceException mre)
|
||||
{
|
||||
throw new MissingEntryException("Can't find entry " + entry + " in resource file " + resource + ".",
|
||||
resource,
|
||||
entry,
|
||||
loc,
|
||||
loader != null ? loader : this.getClassLoader());
|
||||
}
|
||||
catch (UnsupportedEncodingException use)
|
||||
{
|
||||
// should never occur - cause we already test this in the constructor
|
||||
throw new RuntimeException(use.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected String formatWithTimeZone(
|
||||
String template,
|
||||
Object[] arguments,
|
||||
Locale locale,
|
||||
TimeZone timezone)
|
||||
{
|
||||
MessageFormat mf = new MessageFormat(" ");
|
||||
mf.setLocale(locale);
|
||||
mf.applyPattern(template);
|
||||
if (!timezone.equals(TimeZone.getDefault()))
|
||||
{
|
||||
Format[] formats = mf.getFormats();
|
||||
for (int i = 0; i < formats.length; i++)
|
||||
{
|
||||
if (formats[i] instanceof DateFormat)
|
||||
{
|
||||
DateFormat temp = (DateFormat) formats[i];
|
||||
temp.setTimeZone(timezone);
|
||||
mf.setFormat(i,temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mf.format(arguments);
|
||||
}
|
||||
|
||||
protected String addExtraArgs(String msg, Locale locale)
|
||||
{
|
||||
if (extraArgs != null)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer(msg);
|
||||
Object[] filteredArgs = extraArgs.getFilteredArgs(locale);
|
||||
for (int i = 0; i < filteredArgs.length; i++)
|
||||
{
|
||||
sb.append(filteredArgs[i]);
|
||||
}
|
||||
msg = sb.toString();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Filter} that is used to filter the arguments of this message
|
||||
* @param filter the {@link Filter} to use. <code>null</code> to disable filtering.
|
||||
*/
|
||||
public void setFilter(Filter filter)
|
||||
{
|
||||
arguments.setFilter(filter);
|
||||
if (extraArgs != null)
|
||||
{
|
||||
extraArgs.setFilter(filter);
|
||||
}
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current filter.
|
||||
* @return the current filter
|
||||
*/
|
||||
public Filter getFilter()
|
||||
{
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link ClassLoader} which loads the resource files. If it is set to <code>null</code>
|
||||
* then the default {@link ClassLoader} is used.
|
||||
* @param loader the {@link ClassLoader} which loads the resource files
|
||||
*/
|
||||
public void setClassLoader(ClassLoader loader)
|
||||
{
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ClassLoader} which loads the resource files or <code>null</code>
|
||||
* if the default ClassLoader is used.
|
||||
* @return the {@link ClassLoader} which loads the resource files
|
||||
*/
|
||||
public ClassLoader getClassLoader()
|
||||
{
|
||||
return loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the message in the resource bundle.
|
||||
* @return the id of the message
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the resource bundle for this message
|
||||
* @return name of the resource file
|
||||
*/
|
||||
public String getResource()
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an <code>Object[]</code> containing the message arguments.
|
||||
* @return the message arguments
|
||||
*/
|
||||
public Object[] getArguments()
|
||||
{
|
||||
return arguments.getArguments();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param extraArg
|
||||
*/
|
||||
public void setExtraArgument(Object extraArg)
|
||||
{
|
||||
setExtraArguments(new Object[] {extraArg});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param extraArgs
|
||||
*/
|
||||
public void setExtraArguments(Object[] extraArgs)
|
||||
{
|
||||
if (extraArgs != null)
|
||||
{
|
||||
this.extraArgs = new FilteredArguments(extraArgs);
|
||||
this.extraArgs.setFilter(filter);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extraArgs = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object[] getExtraArgs()
|
||||
{
|
||||
return (extraArgs == null) ? null : extraArgs.getArguments();
|
||||
}
|
||||
|
||||
protected class FilteredArguments
|
||||
{
|
||||
|
||||
protected Filter filter = null;
|
||||
|
||||
protected boolean[] isLocaleSpecific;
|
||||
protected int[] argFilterType;
|
||||
protected Object[] arguments;
|
||||
protected Object[] unpackedArgs;
|
||||
protected Object[] filteredArgs;
|
||||
|
||||
FilteredArguments()
|
||||
{
|
||||
this(new Object[0]);
|
||||
}
|
||||
|
||||
FilteredArguments(Object[] args)
|
||||
{
|
||||
this.arguments = args;
|
||||
this.unpackedArgs = new Object[args.length];
|
||||
this.filteredArgs = new Object[args.length];
|
||||
this.isLocaleSpecific = new boolean[args.length];
|
||||
this.argFilterType = new int[args.length];
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
if (args[i] instanceof TrustedInput)
|
||||
{
|
||||
this.unpackedArgs[i] = ((TrustedInput) args[i]).getInput();
|
||||
argFilterType[i] = NO_FILTER;
|
||||
}
|
||||
else if (args[i] instanceof UntrustedInput)
|
||||
{
|
||||
this.unpackedArgs[i] = ((UntrustedInput) args[i]).getInput();
|
||||
if (args[i] instanceof UntrustedUrlInput)
|
||||
{
|
||||
argFilterType[i] = FILTER_URL;
|
||||
}
|
||||
else
|
||||
{
|
||||
argFilterType[i] = FILTER;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.unpackedArgs[i] = args[i];
|
||||
argFilterType[i] = FILTER;
|
||||
}
|
||||
|
||||
// locale specific
|
||||
this.isLocaleSpecific[i] = (this.unpackedArgs[i] instanceof LocaleString);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return unpackedArgs.length == 0;
|
||||
}
|
||||
|
||||
public Object[] getArguments()
|
||||
{
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public Object[] getFilteredArgs(Locale locale)
|
||||
{
|
||||
Object[] result = new Object[unpackedArgs.length];
|
||||
for (int i = 0; i < unpackedArgs.length; i++)
|
||||
{
|
||||
Object arg;
|
||||
if (filteredArgs[i] != null)
|
||||
{
|
||||
arg = filteredArgs[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
arg = unpackedArgs[i];
|
||||
if (isLocaleSpecific[i])
|
||||
{
|
||||
// get locale
|
||||
arg = ((LocaleString) arg).getLocaleString(locale);
|
||||
arg = filter(argFilterType[i], arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
arg = filter(argFilterType[i], arg);
|
||||
filteredArgs[i] = arg;
|
||||
}
|
||||
}
|
||||
result[i] = arg;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object filter(int type, Object obj)
|
||||
{
|
||||
if (filter != null)
|
||||
{
|
||||
Object o = (null == obj) ? "null" : obj;
|
||||
switch (type)
|
||||
{
|
||||
case NO_FILTER:
|
||||
return o;
|
||||
case FILTER:
|
||||
return filter.doFilter(o.toString());
|
||||
case FILTER_URL:
|
||||
return filter.doFilterUrl(o.toString());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
public Filter getFilter()
|
||||
{
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setFilter(Filter filter)
|
||||
{
|
||||
if (filter != this.filter)
|
||||
{
|
||||
for (int i = 0; i < unpackedArgs.length; i++)
|
||||
{
|
||||
filteredArgs[i] = null;
|
||||
}
|
||||
}
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("Resource: \"").append(resource);
|
||||
sb.append("\" Id: \"").append(id).append("\"");
|
||||
sb.append(" Arguments: ").append(arguments.getArguments().length).append(" normal, ")
|
||||
.append(extraArgs.getArguments().length).append(" extra");
|
||||
sb.append(" Encoding: ").append(encoding);
|
||||
sb.append(" ClassLoader: ").append(loader);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.spongycastle.i18n;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
public class MissingEntryException extends RuntimeException
|
||||
{
|
||||
|
||||
protected final String resource;
|
||||
protected final String key;
|
||||
protected final ClassLoader loader;
|
||||
protected final Locale locale;
|
||||
|
||||
private String debugMsg;
|
||||
|
||||
public MissingEntryException(String message, String resource, String key, Locale locale, ClassLoader loader)
|
||||
{
|
||||
super(message);
|
||||
this.resource = resource;
|
||||
this.key = key;
|
||||
this.locale = locale;
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public MissingEntryException(String message, Throwable cause, String resource, String key, Locale locale, ClassLoader loader)
|
||||
{
|
||||
super(message + ": " + cause);
|
||||
this.resource = resource;
|
||||
this.key = key;
|
||||
this.locale = locale;
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getResource()
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
|
||||
public ClassLoader getClassLoader()
|
||||
{
|
||||
return loader;
|
||||
}
|
||||
|
||||
public Locale getLocale()
|
||||
{
|
||||
return locale;
|
||||
}
|
||||
|
||||
public String getDebugMsg()
|
||||
{
|
||||
if (debugMsg == null)
|
||||
{
|
||||
debugMsg = "Can not find entry " + key + " in resource file " + resource + " for the locale " + locale + ".";
|
||||
}
|
||||
return debugMsg;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user