Changeset 0ceb957
- Timestamp:
- Apr 17, 2016 3:55:41 PM (5 years ago)
- Branches:
- master
- Children:
- b69677b
- Parents:
- 193ad43
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
core/java/src/net/i2p/data/PrivateKeyFile.java
r193ad43 r0ceb957 75 75 int mode = 0; 76 76 boolean error = false; 77 Getopt g = new Getopt("pkf", args, "t:nuxhse: ");77 Getopt g = new Getopt("pkf", args, "t:nuxhse:c:"); 78 78 int c; 79 79 while ((c = g.getopt()) != -1) { 80 80 switch (c) { 81 case 'c': 82 stype = g.getOptarg(); 83 break; 84 81 85 case 't': 82 86 stype = g.getOptarg(); … … 118 122 try { 119 123 File f = new File(filearg); 124 boolean exists = f.exists(); 120 125 PrivateKeyFile pkf = new PrivateKeyFile(f, client); 121 Destination d = pkf.createIfAbsent(); 122 System.out.println("Original Destination:"); 126 Destination d; 127 if (stype != null) { 128 SigType type = SigType.parseSigType(stype); 129 if (type == null) 130 throw new IllegalArgumentException("Signature type " + stype + " is not supported"); 131 d = pkf.createIfAbsent(type); 132 } else { 133 d = pkf.createIfAbsent(); 134 } 135 if (exists) 136 System.out.println("Original Destination:"); 137 else 138 System.out.println("Created Destination:"); 123 139 System.out.println(pkf); 124 140 verifySignature(d); … … 186 202 187 203 private static void usage() { 188 System.err.println("Usage: PrivateKeyFile filename (generates if nonexistent, then prints)\n" +204 System.err.println("Usage: PrivateKeyFile [-c sigtype] filename (generates if nonexistent, then prints)\n" + 189 205 " PrivateKeyFile -h filename (generates if nonexistent, adds hashcash cert)\n" + 190 206 " PrivateKeyFile -h -e effort filename (specify HashCash effort instead of default " + HASH_EFFORT + ")\n" + 191 207 " PrivateKeyFile -n filename (changes to null cert)\n" + 192 208 " PrivateKeyFile -s filename signwithdestfile (generates if nonexistent, adds cert signed by 2nd dest)\n" + 193 " PrivateKeyFile -t sigtype filename (changes to KeyCertificate of the given sig type \n" +209 " PrivateKeyFile -t sigtype filename (changes to KeyCertificate of the given sig type)\n" + 194 210 " PrivateKeyFile -u filename (changes to unknown cert)\n" + 195 211 " PrivateKeyFile -x filename (changes to hidden cert)\n"); … … 258 274 } 259 275 260 /** Also reads in the file to get the privKey and signingPrivKey, 276 /** 277 * Create with the default signature type if nonexistent. 278 * 279 * Also reads in the file to get the privKey and signingPrivKey, 261 280 * which aren't available from I2PClient. 262 281 */ 263 282 public Destination createIfAbsent() throws I2PException, IOException, DataFormatException { 283 return createIfAbsent(I2PClient.DEFAULT_SIGTYPE); 284 } 285 286 /** 287 * Create with the specified signature type if nonexistent. 288 * 289 * Also reads in the file to get the privKey and signingPrivKey, 290 * which aren't available from I2PClient. 291 * 292 * @since 0.9.26 293 */ 294 public Destination createIfAbsent(SigType type) throws I2PException, IOException, DataFormatException { 264 295 if(!this.file.exists()) { 265 296 OutputStream out = null; … … 267 298 out = new SecureFileOutputStream(this.file); 268 299 if (this.client != null) 269 this.client.createDestination(out );300 this.client.createDestination(out, type); 270 301 else 271 302 write();
Note: See TracChangeset
for help on using the changeset viewer.