Changeset 4340f70


Ignore:
Timestamp:
Jul 29, 2013 1:49:05 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7737bf5
Parents:
6dbd8a6
Message:
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/TrustedUpdate.java

    r6dbd8a6 r4340f70  
    99import java.io.SequenceInputStream;
    1010import java.io.UnsupportedEncodingException;
     11import java.util.Collections;
    1112import java.util.HashMap;
    1213import java.util.Map;
     
    211212
    212213    /**
     214     *  @since 0.9.8
     215     */
     216    Map<SigningPublicKey, String> getKeys() {
     217        return Collections.unmodifiableMap(_trustedKeys);
     218    }
     219
     220    /**
    213221     *  Duplicate keys or names rejected,
    214222     *  except that duplicate empty names are allowed
  • core/java/src/net/i2p/data/Signature.java

    r6dbd8a6 r4340f70  
    99 *
    1010 */
     11
     12import net.i2p.crypto.SigType;
    1113
    1214/**
     
    2123 */
    2224public class Signature extends SimpleDataStructure {
    23     public final static int SIGNATURE_BYTES = 40;
     25    private static final SigType DEF_TYPE = SigType.DSA_SHA1;
     26    /** 40 */
     27    public final static int SIGNATURE_BYTES = DEF_TYPE.getSigLen();
    2428    /** all zeros */
    2529    public final static byte[] FAKE_SIGNATURE = new byte[SIGNATURE_BYTES];
    2630
     31    private final SigType _type;
     32
    2733    public Signature() {
     34        this(DEF_TYPE);
     35    }
     36
     37    /**
     38     *  @since 0.9.8
     39     */
     40    public Signature(SigType type) {
    2841        super();
     42        _type = type;
    2943    }
    3044
    3145    public Signature(byte data[]) {
    32         super(data);
     46        this(DEF_TYPE, data);
     47    }
     48
     49    /**
     50     *  @since 0.9.8
     51     */
     52    public Signature(SigType type, byte data[]) {
     53        super();
     54        _type = type;
     55        setData(data);
    3356    }
    3457
    3558    public int length() {
    36         return SIGNATURE_BYTES;
     59        return _type.getSigLen();
     60    }
     61
     62    /**
     63     *  @since 0.9.8
     64     */
     65    public SigType getType() {
     66        return _type;
    3767    }
    3868}
  • core/java/src/net/i2p/data/SigningPrivateKey.java

    r6dbd8a6 r4340f70  
    1111
    1212import net.i2p.crypto.KeyGenerator;
     13import net.i2p.crypto.SigType;
    1314
    1415/**
     
    2122 */
    2223public class SigningPrivateKey extends SimpleDataStructure {
    23     public final static int KEYSIZE_BYTES = 20;
     24    private static final SigType DEF_TYPE = SigType.DSA_SHA1;
     25    public final static int KEYSIZE_BYTES = DEF_TYPE.getPrivkeyLen();
     26
     27    private final SigType _type;
    2428
    2529    public SigningPrivateKey() {
     30        this(DEF_TYPE);
     31    }
     32
     33    /**
     34     *  @since 0.9.8
     35     */
     36    public SigningPrivateKey(SigType type) {
    2637        super();
     38        _type = type;
    2739    }
    2840
    2941    public SigningPrivateKey(byte data[]) {
    30         super(data);
     42        this(DEF_TYPE, data);
     43    }
     44
     45    /**
     46     *  @since 0.9.8
     47     */
     48    public SigningPrivateKey(SigType type, byte data[]) {
     49        super();
     50        _type = type;
     51        setData(data);
    3152    }
    3253
     
    3657     */
    3758    public SigningPrivateKey(String base64Data)  throws DataFormatException {
    38         super();
     59        this();
    3960        fromBase64(base64Data);
    4061    }
    4162
     63
    4264    public int length() {
    43         return KEYSIZE_BYTES;
     65        return _type.getPrivkeyLen();
     66    }
     67
     68    /**
     69     *  @since 0.9.8
     70     */
     71    public SigType getType() {
     72        return _type;
    4473    }
    4574
  • core/java/src/net/i2p/data/SigningPublicKey.java

    r6dbd8a6 r4340f70  
    1313import java.io.IOException;
    1414
     15import net.i2p.crypto.SigType;
     16
    1517/**
    1618 * Defines the SigningPublicKey as defined by the I2P data structure spec.
     
    2224 */
    2325public class SigningPublicKey extends SimpleDataStructure {
    24     public final static int KEYSIZE_BYTES = 128;
     26    private static final SigType DEF_TYPE = SigType.DSA_SHA1;
     27    public final static int KEYSIZE_BYTES = DEF_TYPE.getPubkeyLen();
    2528    private static final int CACHE_SIZE = 1024;
    2629
    2730    private static final SDSCache<SigningPublicKey> _cache = new SDSCache(SigningPublicKey.class, KEYSIZE_BYTES, CACHE_SIZE);
     31
     32    private final SigType _type;
    2833
    2934    /**
     
    4550
    4651    public SigningPublicKey() {
     52        this(DEF_TYPE);
     53    }
     54
     55    /**
     56     *  @since 0.9.8
     57     */
     58    public SigningPublicKey(SigType type) {
    4759        super();
     60        _type = type;
    4861    }
    4962
    5063    public SigningPublicKey(byte data[]) {
    51         super(data);
     64        this(DEF_TYPE, data);
     65    }
     66
     67    /**
     68     *  @since 0.9.8
     69     */
     70    public SigningPublicKey(SigType type, byte data[]) {
     71        super();
     72        _type = type;
     73        setData(data);
    5274    }
    5375
     
    5779     */
    5880    public SigningPublicKey(String base64Data)  throws DataFormatException {
    59         super();
     81        this();
    6082        fromBase64(base64Data);
    6183    }
    6284
    6385    public int length() {
    64         return KEYSIZE_BYTES;
     86        return _type.getPubkeyLen();
     87    }
     88
     89    /**
     90     *  @since 0.9.8
     91     */
     92    public SigType getType() {
     93        return _type;
    6594    }
    6695}
  • core/java/src/net/i2p/data/SimpleDataStructure.java

    r6dbd8a6 r4340f70  
    3232public abstract class SimpleDataStructure extends DataStructureImpl {
    3333    protected byte[] _data;
    34     /** this is just to avoid lots of calls to length() */
    35     protected final int _length;
    3634   
    3735    /** A new instance with the data set to null. Call readBytes(), setData(), or fromByteArray() after this to set the data */
    3836    public SimpleDataStructure() {
    39         _length = length();
    4037    }
    4138   
    4239    /** @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok) */
    4340    public SimpleDataStructure(byte data[]) {
    44         _length = length();
    4541        setData(data);
    4642    }
     
    6965        if (_data != null)
    7066            throw new RuntimeException("Data already set");
    71         if (data != null && data.length != _length)
    72             throw new IllegalArgumentException("Bad data length: " + data.length + "; required: " + _length);
     67        if (data != null && data.length != length())
     68            throw new IllegalArgumentException("Bad data length: " + data.length + "; required: " + length());
    7369        _data = data;
    7470    }
     
    8278        if (_data != null)
    8379            throw new RuntimeException("Data already set");
    84         _data = new byte[_length];
     80        int length = length();
     81        _data = new byte[length];
    8582        int read = read(in, _data);
    86         if (read != _length) throw new DataFormatException("Not enough bytes to read the data");
     83        if (read != length) throw new DataFormatException("Not enough bytes to read the data");
    8784    }
    8885   
     
    110107        if (d == null)
    111108            throw new DataFormatException("Bad Base64 encoded data");
    112         if (d.length != _length)
    113             throw new DataFormatException("Bad decoded data length, expected " + _length + " got " + d.length);
     109        if (d.length != length())
     110            throw new DataFormatException("Bad decoded data length, expected " + length() + " got " + d.length);
    114111        // call setData() instead of _data = data in case overridden
    115112        setData(d);
     
    142139    public void fromByteArray(byte data[]) throws DataFormatException {
    143140        if (data == null) throw new DataFormatException("Null data passed in");
    144         if (data.length != _length)
    145             throw new DataFormatException("Bad data length: " + data.length + "; required: " + _length);
     141        if (data.length != length())
     142            throw new DataFormatException("Bad data length: " + data.length + "; required: " + length());
    146143        // call setData() instead of _data = data in case overridden
    147144        setData(data);
     
    152149        StringBuilder buf = new StringBuilder(64);
    153150        buf.append('[').append(getClass().getSimpleName()).append(": ");
     151        int length = length();
    154152        if (_data == null) {
    155153            buf.append("null");
    156         } else if (_length <= 32) {
     154        } else if (length <= 32) {
    157155            buf.append(toBase64());
    158156        } else {
    159             buf.append("size: ").append(Integer.toString(_length));
     157            buf.append("size: ").append(Integer.toString(length));
    160158        }
    161159        buf.append(']');
  • history.txt

    r6dbd8a6 r4340f70  
     12012-07-29 zzz
     2 * Signatures:
     3   - Prep for new signature algorithms; new SigType enum;
     4     Signature, SigningPublicKey, SigningPrivateKey store type
     5   - New Hash384 and Hash512 classes
     6   - Remove length field in SimpleDataStructure
     7   - New SU3File generator/verifier/extractor
     8
    192012-07-28 zzz
    210 * Addresses: Treat RFC 4193 addresses fc00::/7 as local
  • router/java/src/net/i2p/router/RouterVersion.java

    r6dbd8a6 r4340f70  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 13;
     21    public final static long BUILD = 14;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.