From 70d9415ba24f1c1fb6336e71a23f69d49f59e2fd Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 6 Sep 2011 13:23:24 +0000 Subject: [PATCH] more constructors --- .../java/src/net/i2p/data/PrivateKeyFile.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/core/java/src/net/i2p/data/PrivateKeyFile.java b/core/java/src/net/i2p/data/PrivateKeyFile.java index 4f4af3cf9a..2808f9a699 100644 --- a/core/java/src/net/i2p/data/PrivateKeyFile.java +++ b/core/java/src/net/i2p/data/PrivateKeyFile.java @@ -127,6 +127,32 @@ public class PrivateKeyFile { this.signingPrivKey = null; } + /** @since 0.8.9 */ + public PrivateKeyFile(File file, I2PSession session) { + this(file, session.getMyDestination(), session.getDecryptionKey(), session.getPrivateKey()); + } + + /** @since 0.8.9 */ + public PrivateKeyFile(File file, Destination dest, PrivateKey pk, SigningPrivateKey spk) { + this.file = file; + this.client = null; + this.dest = dest; + this.privKey = pk; + this.signingPrivKey = spk; + } + + /** @since 0.8.9 */ + public PrivateKeyFile(File file, PublicKey pubkey, SigningPublicKey spubkey, Certificate cert, + PrivateKey pk, SigningPrivateKey spk) { + this.file = file; + this.client = null; + this.dest = new Destination(); + this.dest.setPublicKey(pubkey); + this.dest.setSigningPublicKey(spubkey); + this.dest.setCertificate(cert); + this.privKey = pk; + this.signingPrivKey = spk; + } /** Also reads in the file to get the privKey and signingPrivKey, * which aren't available from I2PClient. @@ -136,7 +162,10 @@ public class PrivateKeyFile { FileOutputStream out = null; try { out = new FileOutputStream(this.file); - this.client.createDestination(out); + if (this.client != null) + this.client.createDestination(out); + else + write(); } finally { if (out != null) { try { out.close(); } catch (IOException ioe) {} @@ -411,8 +440,8 @@ public class PrivateKeyFile { - private File file; - private I2PClient client; + private final File file; + private final I2PClient client; private Destination dest; private PrivateKey privKey; private SigningPrivateKey signingPrivKey;