forked from I2P_Developers/i2p.i2p
PrivateKeyFile: New constructor with padding
Router: - Use eepPriv.dat format for router keys file (thx orignal) - Consolidate router keys readin code - Update killKeys file list RouterPrivateKeyFile: New extension to add getRouterIdentity()
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package net.i2p.data.router;
|
||||
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.i2p.crypto.SigType;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.PrivateKey;
|
||||
import net.i2p.data.PrivateKeyFile;
|
||||
import net.i2p.data.SigningPrivateKey;
|
||||
|
||||
/**
|
||||
* Same format as super, simply adds a method to
|
||||
* treat it as a RouterIdentity instead of a Destination.
|
||||
*
|
||||
* @since 0.9.16
|
||||
*/
|
||||
public class RouterPrivateKeyFile extends PrivateKeyFile {
|
||||
|
||||
public RouterPrivateKeyFile(File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read it in from the file.
|
||||
* Also sets the local privKey and signingPrivKey.
|
||||
*/
|
||||
public RouterIdentity getRouterIdentity() throws IOException, DataFormatException {
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = new BufferedInputStream(new FileInputStream(this.file));
|
||||
RouterIdentity ri = new RouterIdentity();
|
||||
ri.readBytes(in);
|
||||
privKey = new PrivateKey();
|
||||
privKey.readBytes(in);
|
||||
SigType type = ri.getSigningPublicKey().getType();
|
||||
if (type == null)
|
||||
throw new DataFormatException("Unknown sig type");
|
||||
signingPrivKey = new SigningPrivateKey(type);
|
||||
signingPrivKey.readBytes(in);
|
||||
return ri;
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try { in.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user