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() {
|
private boolean x_isAvailable() {
|
||||||
if (ELGAMAL_2048 == this)
|
if (ELGAMAL_2048 == this)
|
||||||
return true;
|
return true;
|
||||||
|
// EC types are placeholders for now
|
||||||
|
if (base == EncAlgo.EC)
|
||||||
|
return false;
|
||||||
try {
|
try {
|
||||||
getParams();
|
getParams();
|
||||||
} catch (InvalidParameterSpecException e) {
|
} catch (InvalidParameterSpecException e) {
|
||||||
|
@ -13,9 +13,15 @@ public class KeyPair {
|
|||||||
private final PublicKey pub;
|
private final PublicKey pub;
|
||||||
private final PrivateKey priv;
|
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) {
|
public KeyPair(PublicKey publicKey, PrivateKey privateKey) {
|
||||||
pub = publicKey;
|
pub = publicKey;
|
||||||
priv = privateKey;
|
priv = privateKey;
|
||||||
|
if (pub.getType() != priv.getType())
|
||||||
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublicKey getPublic() {
|
public PublicKey getPublic() {
|
||||||
|
@ -53,11 +53,10 @@ public class PrivateKey extends SimpleDataStructure {
|
|||||||
* @since 0.9.38
|
* @since 0.9.38
|
||||||
*/
|
*/
|
||||||
public PrivateKey(EncType type, byte data[]) {
|
public PrivateKey(EncType type, byte data[]) {
|
||||||
super();
|
this(type);
|
||||||
_type = type;
|
|
||||||
if (data == null)
|
if (data == null)
|
||||||
throw new IllegalArgumentException("Data must be specified");
|
throw new IllegalArgumentException("Data must be specified");
|
||||||
_data = data;
|
setData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** constructs from base64
|
/** constructs from base64
|
||||||
|
@ -76,11 +76,10 @@ public class PublicKey extends SimpleDataStructure {
|
|||||||
* @since 0.9.38
|
* @since 0.9.38
|
||||||
*/
|
*/
|
||||||
public PublicKey(EncType type, byte data[]) {
|
public PublicKey(EncType type, byte data[]) {
|
||||||
super();
|
this(type);
|
||||||
_type = type;
|
|
||||||
if (data == null)
|
if (data == null)
|
||||||
throw new IllegalArgumentException("Data must be specified");
|
throw new IllegalArgumentException("Data must be specified");
|
||||||
_data = data;
|
setData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** constructs from base64
|
/** constructs from base64
|
||||||
|
Reference in New Issue
Block a user