forked from I2P_Developers/i2p.i2p
Data: Fix NPE on unknown sig type in destination
Fix hashcode and equals for typed data
This commit is contained in:
@@ -9,6 +9,8 @@ package net.i2p.data;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import net.i2p.crypto.SigType;
|
import net.i2p.crypto.SigType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,4 +104,23 @@ public class Signature extends SimpleDataStructure {
|
|||||||
buf.append(']');
|
buf.append(']');
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return DataHelper.hashCode(_type) ^ super.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == this) return true;
|
||||||
|
if (obj == null || !(obj instanceof Signature)) return false;
|
||||||
|
Signature s = (Signature) obj;
|
||||||
|
return _type == s._type && Arrays.equals(_data, s._data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,8 @@ package net.i2p.data;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import net.i2p.crypto.KeyGenerator;
|
import net.i2p.crypto.KeyGenerator;
|
||||||
import net.i2p.crypto.SigType;
|
import net.i2p.crypto.SigType;
|
||||||
|
|
||||||
@@ -104,4 +106,23 @@ public class SigningPrivateKey extends SimpleDataStructure {
|
|||||||
buf.append(']');
|
buf.append(']');
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return DataHelper.hashCode(_type) ^ super.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == this) return true;
|
||||||
|
if (obj == null || !(obj instanceof SigningPrivateKey)) return false;
|
||||||
|
SigningPrivateKey s = (SigningPrivateKey) obj;
|
||||||
|
return _type == s._type && Arrays.equals(_data, s._data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@ package net.i2p.data;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import net.i2p.crypto.SigType;
|
import net.i2p.crypto.SigType;
|
||||||
|
|
||||||
@@ -113,7 +114,8 @@ public class SigningPublicKey extends SimpleDataStructure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Up-convert this from an untyped (type 0) SPK to a typed SPK based on the Key Cert given
|
* Up-convert this from an untyped (type 0) SPK to a typed SPK based on the Key Cert given.
|
||||||
|
* The type of the returned key will be null if the kcert sigtype is null.
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if this is already typed to a different type
|
* @throws IllegalArgumentException if this is already typed to a different type
|
||||||
* @since 0.9.12
|
* @since 0.9.12
|
||||||
@@ -126,6 +128,9 @@ public class SigningPublicKey extends SimpleDataStructure {
|
|||||||
return this;
|
return this;
|
||||||
if (_type != SigType.DSA_SHA1)
|
if (_type != SigType.DSA_SHA1)
|
||||||
throw new IllegalArgumentException("Cannot convert " + _type + " to " + newType);
|
throw new IllegalArgumentException("Cannot convert " + _type + " to " + newType);
|
||||||
|
// unknown type, keep the 128 bytes of data
|
||||||
|
if (newType == null)
|
||||||
|
return new SigningPublicKey(null, _data);
|
||||||
int newLen = newType.getPubkeyLen();
|
int newLen = newType.getPubkeyLen();
|
||||||
if (newLen == SigType.DSA_SHA1.getPubkeyLen())
|
if (newLen == SigType.DSA_SHA1.getPubkeyLen())
|
||||||
return new SigningPublicKey(newType, _data);
|
return new SigningPublicKey(newType, _data);
|
||||||
@@ -145,7 +150,7 @@ public class SigningPublicKey extends SimpleDataStructure {
|
|||||||
* Get the portion of this (type 0) SPK that is really padding based on the Key Cert type given,
|
* Get the portion of this (type 0) SPK that is really padding based on the Key Cert type given,
|
||||||
* if any
|
* if any
|
||||||
*
|
*
|
||||||
* @return leading padding length > 0 or null
|
* @return leading padding length > 0 or null if no padding or type is unknown
|
||||||
* @throws IllegalArgumentException if this is already typed to a different type
|
* @throws IllegalArgumentException if this is already typed to a different type
|
||||||
* @since 0.9.12
|
* @since 0.9.12
|
||||||
*/
|
*/
|
||||||
@@ -153,7 +158,7 @@ public class SigningPublicKey extends SimpleDataStructure {
|
|||||||
if (_data == null)
|
if (_data == null)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
SigType newType = kcert.getSigType();
|
SigType newType = kcert.getSigType();
|
||||||
if (_type == newType)
|
if (_type == newType || newType == null)
|
||||||
return null;
|
return null;
|
||||||
if (_type != SigType.DSA_SHA1)
|
if (_type != SigType.DSA_SHA1)
|
||||||
throw new IllegalStateException("Cannot convert " + _type + " to " + newType);
|
throw new IllegalStateException("Cannot convert " + _type + " to " + newType);
|
||||||
@@ -200,4 +205,23 @@ public class SigningPublicKey extends SimpleDataStructure {
|
|||||||
public static void clearCache() {
|
public static void clearCache() {
|
||||||
_cache.clear();
|
_cache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return DataHelper.hashCode(_type) ^ super.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == this) return true;
|
||||||
|
if (obj == null || !(obj instanceof SigningPublicKey)) return false;
|
||||||
|
SigningPublicKey s = (SigningPublicKey) obj;
|
||||||
|
return _type == s._type && Arrays.equals(_data, s._data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user