Changeset a38bd0b


Ignore:
Timestamp:
Nov 26, 2014 4:06:09 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
9700f30
Parents:
5f2b620
Message:

Data: Fix NPE on unknown sig type in destination
Fix hashcode and equals for typed data

Location:
core/java/src/net/i2p/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/Signature.java

    r5f2b620 ra38bd0b  
    99 *
    1010 */
     11
     12import java.util.Arrays;
    1113
    1214import net.i2p.crypto.SigType;
     
    103105        return buf.toString();
    104106    }
     107
     108    /**
     109     *  @since 0.9.17
     110     */
     111    @Override
     112    public int hashCode() {
     113        return DataHelper.hashCode(_type) ^ super.hashCode();
     114    }
     115
     116    /**
     117     *  @since 0.9.17
     118     */
     119    @Override
     120    public boolean equals(Object obj) {
     121        if (obj == this) return true;
     122        if (obj == null || !(obj instanceof Signature)) return false;
     123        Signature s = (Signature) obj;
     124        return _type == s._type && Arrays.equals(_data, s._data);
     125    }
    105126}
  • core/java/src/net/i2p/data/SigningPrivateKey.java

    r5f2b620 ra38bd0b  
    99 *
    1010 */
     11
     12import java.util.Arrays;
    1113
    1214import net.i2p.crypto.KeyGenerator;
     
    105107        return buf.toString();
    106108    }
     109
     110    /**
     111     *  @since 0.9.17
     112     */
     113    @Override
     114    public int hashCode() {
     115        return DataHelper.hashCode(_type) ^ super.hashCode();
     116    }
     117
     118    /**
     119     *  @since 0.9.17
     120     */
     121    @Override
     122    public boolean equals(Object obj) {
     123        if (obj == this) return true;
     124        if (obj == null || !(obj instanceof SigningPrivateKey)) return false;
     125        SigningPrivateKey s = (SigningPrivateKey) obj;
     126        return _type == s._type && Arrays.equals(_data, s._data);
     127    }
    107128}
  • core/java/src/net/i2p/data/SigningPublicKey.java

    r5f2b620 ra38bd0b  
    1313import java.io.IOException;
    1414import java.io.OutputStream;
     15import java.util.Arrays;
    1516
    1617import net.i2p.crypto.SigType;
     
    114115
    115116    /**
    116      *  Up-convert this from an untyped (type 0) SPK to a typed SPK based on the Key Cert given
     117     *  Up-convert this from an untyped (type 0) SPK to a typed SPK based on the Key Cert given.
     118     *  The type of the returned key will be null if the kcert sigtype is null.
    117119     *
    118120     *  @throws IllegalArgumentException if this is already typed to a different type
     
    127129        if (_type != SigType.DSA_SHA1)
    128130            throw new IllegalArgumentException("Cannot convert " + _type + " to " + newType);
     131        // unknown type, keep the 128 bytes of data
     132        if (newType == null)
     133            return new SigningPublicKey(null, _data);
    129134        int newLen = newType.getPubkeyLen();
    130135        if (newLen == SigType.DSA_SHA1.getPubkeyLen())
     
    146151     *  if any
    147152     *
    148      *  @return leading padding length > 0 or null
     153     *  @return leading padding length > 0 or null if no padding or type is unknown
    149154     *  @throws IllegalArgumentException if this is already typed to a different type
    150155     *  @since 0.9.12
     
    154159            throw new IllegalStateException();
    155160        SigType newType = kcert.getSigType();
    156         if (_type == newType)
     161        if (_type == newType || newType == null)
    157162            return null;
    158163        if (_type != SigType.DSA_SHA1)
     
    201206        _cache.clear();
    202207    }
     208
     209    /**
     210     *  @since 0.9.17
     211     */
     212    @Override
     213    public int hashCode() {
     214        return DataHelper.hashCode(_type) ^ super.hashCode();
     215    }
     216
     217    /**
     218     *  @since 0.9.17
     219     */
     220    @Override
     221    public boolean equals(Object obj) {
     222        if (obj == this) return true;
     223        if (obj == null || !(obj instanceof SigningPublicKey)) return false;
     224        SigningPublicKey s = (SigningPublicKey) obj;
     225        return _type == s._type && Arrays.equals(_data, s._data);
     226    }
    203227}
Note: See TracChangeset for help on using the changeset viewer.