forked from I2P_Developers/i2p.i2p
Data: Check data length in typed constructors
Check for type match in KeyPair Mark placeholder EncTypes 1-3 as unavailable
This commit is contained in:
@ -113,6 +113,9 @@ public enum EncType {
|
||||
private boolean x_isAvailable() {
|
||||
if (ELGAMAL_2048 == this)
|
||||
return true;
|
||||
// EC types are placeholders for now
|
||||
if (base == EncAlgo.EC)
|
||||
return false;
|
||||
try {
|
||||
getParams();
|
||||
} catch (InvalidParameterSpecException e) {
|
||||
|
@ -13,9 +13,15 @@ public class KeyPair {
|
||||
private final PublicKey pub;
|
||||
private final PrivateKey priv;
|
||||
|
||||
/**
|
||||
* @param publicKey non-null, same EncType as privateKey
|
||||
* @param privateKey non-null, same EncType as publicKey
|
||||
*/
|
||||
public KeyPair(PublicKey publicKey, PrivateKey privateKey) {
|
||||
pub = publicKey;
|
||||
priv = privateKey;
|
||||
if (pub.getType() != priv.getType())
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public PublicKey getPublic() {
|
||||
|
@ -53,11 +53,10 @@ public class PrivateKey extends SimpleDataStructure {
|
||||
* @since 0.9.38
|
||||
*/
|
||||
public PrivateKey(EncType type, byte data[]) {
|
||||
super();
|
||||
_type = type;
|
||||
this(type);
|
||||
if (data == null)
|
||||
throw new IllegalArgumentException("Data must be specified");
|
||||
_data = data;
|
||||
setData(data);
|
||||
}
|
||||
|
||||
/** constructs from base64
|
||||
|
@ -76,11 +76,10 @@ public class PublicKey extends SimpleDataStructure {
|
||||
* @since 0.9.38
|
||||
*/
|
||||
public PublicKey(EncType type, byte data[]) {
|
||||
super();
|
||||
_type = type;
|
||||
this(type);
|
||||
if (data == null)
|
||||
throw new IllegalArgumentException("Data must be specified");
|
||||
_data = data;
|
||||
setData(data);
|
||||
}
|
||||
|
||||
/** constructs from base64
|
||||
|
Reference in New Issue
Block a user