[pkg-java] r17924 - in trunk/ca-certificates-java/src: main/java/org/debian/security test/java/org/debian/security
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Mar 24 10:48:07 UTC 2014
Author: ebourg-guest
Date: 2014-03-24 10:48:07 +0000 (Mon, 24 Mar 2014)
New Revision: 17924
Added:
trunk/ca-certificates-java/src/main/java/org/debian/security/InvalidKeystorePasswordException.java
trunk/ca-certificates-java/src/main/java/org/debian/security/UnableToSaveKeystoreException.java
trunk/ca-certificates-java/src/main/java/org/debian/security/UnknownInputException.java
Removed:
trunk/ca-certificates-java/src/main/java/org/debian/security/Exceptions.java
Modified:
trunk/ca-certificates-java/src/main/java/org/debian/security/UpdateCertificates.java
trunk/ca-certificates-java/src/test/java/org/debian/security/UpdateCertificatesTest.java
Log:
Split Exceptions into distinct classes
Deleted: trunk/ca-certificates-java/src/main/java/org/debian/security/Exceptions.java
===================================================================
--- trunk/ca-certificates-java/src/main/java/org/debian/security/Exceptions.java 2014-03-24 10:35:49 UTC (rev 17923)
+++ trunk/ca-certificates-java/src/main/java/org/debian/security/Exceptions.java 2014-03-24 10:48:07 UTC (rev 17924)
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2012 Damien Raude-Morvan <drazzib at debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-package org.debian.security;
-
-/**
- * Custom exceptions used by {@link UpdateCertificates}
- *
- * @author Damien Raude-Morvan <drazzib at debian.org>
- */
-public class Exceptions {
-
- /**
- * Data send in stdin is invalid (neither "+" or "-" command).
- */
- public static class UnknownInput extends Exception {
- private static final long serialVersionUID = 5698253678856993527L;
-
- public UnknownInput(final String message) {
- super(message);
- }
- }
-
- /**
- * Unable to save keystore to provided location.
- */
- public static class UnableToSaveKeystore extends Exception {
- private static final long serialVersionUID = 3632154306237688490L;
-
- public UnableToSaveKeystore(final String message, final Exception e) {
- super(message, e);
- }
- }
-
- /**
- * Unable to open keystore from provided location (might be an invalid password
- * or IO error).
- */
- public static class InvalidKeystorePassword extends Exception {
- private static final long serialVersionUID = 7004201816889107694L;
-
- public InvalidKeystorePassword(final String message, final Exception e) {
- super(message, e);
- }
- }
-}
Added: trunk/ca-certificates-java/src/main/java/org/debian/security/InvalidKeystorePasswordException.java
===================================================================
--- trunk/ca-certificates-java/src/main/java/org/debian/security/InvalidKeystorePasswordException.java (rev 0)
+++ trunk/ca-certificates-java/src/main/java/org/debian/security/InvalidKeystorePasswordException.java 2014-03-24 10:48:07 UTC (rev 17924)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 Damien Raude-Morvan <drazzib at debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.debian.security;
+
+/**
+ * Unable to open keystore from provided location (might be an invalid password
+ * or IO error).
+ */
+public class InvalidKeystorePasswordException extends Exception {
+ private static final long serialVersionUID = 7004201816889107694L;
+
+ public InvalidKeystorePasswordException(String message, Exception e) {
+ super(message, e);
+ }
+}
Property changes on: trunk/ca-certificates-java/src/main/java/org/debian/security/InvalidKeystorePasswordException.java
___________________________________________________________________
Added: svn:keywords
+ Date Author Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/ca-certificates-java/src/main/java/org/debian/security/UnableToSaveKeystoreException.java
===================================================================
--- trunk/ca-certificates-java/src/main/java/org/debian/security/UnableToSaveKeystoreException.java (rev 0)
+++ trunk/ca-certificates-java/src/main/java/org/debian/security/UnableToSaveKeystoreException.java 2014-03-24 10:48:07 UTC (rev 17924)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 Damien Raude-Morvan <drazzib at debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.debian.security;
+
+/**
+ * Unable to save keystore to provided location.
+ */
+public class UnableToSaveKeystoreException extends Exception {
+ private static final long serialVersionUID = 3632154306237688490L;
+
+ public UnableToSaveKeystoreException(String message, Exception e) {
+ super(message, e);
+ }
+}
Property changes on: trunk/ca-certificates-java/src/main/java/org/debian/security/UnableToSaveKeystoreException.java
___________________________________________________________________
Added: svn:keywords
+ Date Author Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/ca-certificates-java/src/main/java/org/debian/security/UnknownInputException.java
===================================================================
--- trunk/ca-certificates-java/src/main/java/org/debian/security/UnknownInputException.java (rev 0)
+++ trunk/ca-certificates-java/src/main/java/org/debian/security/UnknownInputException.java 2014-03-24 10:48:07 UTC (rev 17924)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 Damien Raude-Morvan <drazzib at debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.debian.security;
+
+/**
+ * Data send in stdin is invalid (neither "+" or "-" command).
+ */
+public class UnknownInputException extends Exception {
+ private static final long serialVersionUID = 5698253678856993527L;
+
+ public UnknownInputException(String message) {
+ super(message);
+ }
+}
Property changes on: trunk/ca-certificates-java/src/main/java/org/debian/security/UnknownInputException.java
___________________________________________________________________
Added: svn:keywords
+ Date Author Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/ca-certificates-java/src/main/java/org/debian/security/UpdateCertificates.java
===================================================================
--- trunk/ca-certificates-java/src/main/java/org/debian/security/UpdateCertificates.java 2014-03-24 10:35:49 UTC (rev 17923)
+++ trunk/ca-certificates-java/src/main/java/org/debian/security/UpdateCertificates.java 2014-03-24 10:48:07 UTC (rev 17924)
@@ -56,7 +56,7 @@
if (args.length == 2 && args[0].equals("-storepass")) {
passwordString = args[1];
} else if (args.length > 0) {
- System.err.println("Usage: java UpdateCertificates [-storepass <password>]");
+ System.err.println("Usage: java org.debian.security.UpdateCertificates [-storepass <password>]");
System.exit(1);
}
@@ -65,16 +65,16 @@
// Force reading of inputstream in UTF-8
uc.processChanges(new InputStreamReader(System.in, "UTF8"));
uc.writeKeyStore();
- } catch (Exceptions.InvalidKeystorePassword e) {
+ } catch (InvalidKeystorePasswordException e) {
e.printStackTrace(System.err);
System.exit(1);
- } catch (Exceptions.UnableToSaveKeystore e) {
+ } catch (UnableToSaveKeystoreException e) {
e.printStackTrace(System.err);
System.exit(1);
}
}
- public UpdateCertificates(final String passwordString, final String keystoreFile) throws IOException, GeneralSecurityException, Exceptions.InvalidKeystorePassword {
+ public UpdateCertificates(final String passwordString, final String keystoreFile) throws IOException, GeneralSecurityException, InvalidKeystorePasswordException {
this.password = passwordString.toCharArray();
this.ksFilename = keystoreFile;
this.ks = openKeyStore();
@@ -84,7 +84,7 @@
/**
* Try to open a existing keystore or create an new one.
*/
- private KeyStore openKeyStore() throws GeneralSecurityException, IOException, Exceptions.InvalidKeystorePassword {
+ private KeyStore openKeyStore() throws GeneralSecurityException, IOException, InvalidKeystorePasswordException {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
File certInputFile = new File(this.ksFilename);
FileInputStream certInputStream = null;
@@ -94,7 +94,7 @@
try {
ks.load(certInputStream, this.password);
} catch (IOException e) {
- throw new Exceptions.InvalidKeystorePassword("Cannot open Java keystore. Is the password correct?", e);
+ throw new InvalidKeystorePasswordException("Cannot open Java keystore. Is the password correct?", e);
}
if (certInputStream != null) {
certInputStream.close();
@@ -111,7 +111,7 @@
while ((line = bufferedStdinReader.readLine()) != null) {
try {
parseLine(line);
- } catch (Exceptions.UnknownInput e) {
+ } catch (UnknownInputException e) {
System.err.println("Unknown input: " + line);
// Keep processing for others lines
}
@@ -122,7 +122,7 @@
* Parse given line to choose between {@link #addAlias(String, Certificate)}
* or {@link #deleteAlias(String)}.
*/
- protected void parseLine(final String line) throws GeneralSecurityException, IOException, Exceptions.UnknownInput {
+ protected void parseLine(final String line) throws GeneralSecurityException, IOException, UnknownInputException {
assert this.ks != null;
String path = line.substring(1);
@@ -140,7 +140,7 @@
// removed after the release of Wheezy.
deleteAlias(filename);
} else {
- throw new Exceptions.UnknownInput(line);
+ throw new UnknownInputException(line);
}
}
@@ -201,7 +201,7 @@
/**
* Write actual keystore content to disk.
*/
- protected void writeKeyStore() throws GeneralSecurityException, Exceptions.UnableToSaveKeystore {
+ protected void writeKeyStore() throws GeneralSecurityException, UnableToSaveKeystoreException {
assert this.ks != null;
try {
@@ -209,7 +209,7 @@
this.ks.store(certOutputFile, this.password);
certOutputFile.close();
} catch (IOException e) {
- throw new Exceptions.UnableToSaveKeystore("There was a problem saving the new Java keystore.", e);
+ throw new UnableToSaveKeystoreException("There was a problem saving the new Java keystore.", e);
}
}
}
Modified: trunk/ca-certificates-java/src/test/java/org/debian/security/UpdateCertificatesTest.java
===================================================================
--- trunk/ca-certificates-java/src/test/java/org/debian/security/UpdateCertificatesTest.java 2014-03-24 10:35:49 UTC (rev 17923)
+++ trunk/ca-certificates-java/src/test/java/org/debian/security/UpdateCertificatesTest.java 2014-03-24 10:48:07 UTC (rev 17924)
@@ -57,7 +57,7 @@
*/
@Test
public void testNoop() throws IOException, GeneralSecurityException,
- Exceptions.InvalidKeystorePassword, Exceptions.UnableToSaveKeystore {
+ InvalidKeystorePasswordException, UnableToSaveKeystoreException {
UpdateCertificates uc = new UpdateCertificates(this.ksPassword,
this.ksFilename);
uc.writeKeyStore();
@@ -70,12 +70,12 @@
*/
@Test
public void testWriteThenOpenWrongPwd() throws IOException,
- GeneralSecurityException, Exceptions.UnableToSaveKeystore {
+ GeneralSecurityException, UnableToSaveKeystoreException {
try {
UpdateCertificates uc = new UpdateCertificates(this.ksPassword,
this.ksFilename);
uc.writeKeyStore();
- } catch (Exceptions.InvalidKeystorePassword e) {
+ } catch (InvalidKeystorePasswordException e) {
Assert.fail();
}
@@ -84,7 +84,7 @@
this.ksFilename);
Assert.fail();
uc.writeKeyStore();
- } catch (Exceptions.InvalidKeystorePassword e) {
+ } catch (InvalidKeystorePasswordException e) {
Assert.assertEquals(
"Cannot open Java keystore. Is the password correct?",
e.getMessage());
@@ -97,8 +97,7 @@
* will throw an UnableToSaveKeystore
*/
@Test
- public void testDeleteThenWrite() throws IOException,
- GeneralSecurityException, Exceptions.InvalidKeystorePassword {
+ public void testDeleteThenWrite() throws IOException, GeneralSecurityException, InvalidKeystorePasswordException {
try {
UpdateCertificates uc = new UpdateCertificates(this.ksPassword,
this.ksFilename);
@@ -111,7 +110,7 @@
// Will fail with some IOException
uc.writeKeyStore();
Assert.fail();
- } catch (Exceptions.UnableToSaveKeystore e) {
+ } catch (UnableToSaveKeystoreException e) {
Assert.assertEquals(
"There was a problem saving the new Java keystore.",
e.getMessage());
@@ -122,14 +121,13 @@
* Try to send an invalid command ("x") in parseLine : throw UnknownInput
*/
@Test
- public void testWrongCommand() throws IOException,
- GeneralSecurityException, Exceptions.InvalidKeystorePassword {
+ public void testWrongCommand() throws IOException, GeneralSecurityException, InvalidKeystorePasswordException {
UpdateCertificates uc = new UpdateCertificates(this.ksPassword,
this.ksFilename);
try {
uc.parseLine(INVALID_CACERT);
Assert.fail();
- } catch (Exceptions.UnknownInput e) {
+ } catch (UnknownInputException e) {
Assert.assertEquals(INVALID_CACERT, e.getMessage());
}
}
@@ -139,8 +137,8 @@
*/
@Test
public void testAdd() throws IOException, GeneralSecurityException,
- Exceptions.UnknownInput, Exceptions.InvalidKeystorePassword,
- Exceptions.UnableToSaveKeystore {
+ UnknownInputException, InvalidKeystorePasswordException,
+ UnableToSaveKeystoreException {
UpdateCertificates uc = new UpdateCertificates(this.ksPassword,
this.ksFilename);
uc.parseLine(ADD_CACERT);
@@ -155,8 +153,8 @@
*/
@Test
public void testAddInvalidCert() throws IOException,
- GeneralSecurityException, Exceptions.UnknownInput,
- Exceptions.InvalidKeystorePassword, Exceptions.UnableToSaveKeystore {
+ GeneralSecurityException, UnknownInputException,
+ InvalidKeystorePasswordException, UnableToSaveKeystoreException {
UpdateCertificates uc = new UpdateCertificates(this.ksPassword,
this.ksFilename);
uc.parseLine("+/usr/share/ca-certificates/null.crt");
@@ -171,8 +169,8 @@
*/
@Test
public void testReplace() throws IOException, GeneralSecurityException,
- Exceptions.UnknownInput, Exceptions.InvalidKeystorePassword,
- Exceptions.UnableToSaveKeystore {
+ UnknownInputException, InvalidKeystorePasswordException,
+ UnableToSaveKeystoreException {
UpdateCertificates uc = new UpdateCertificates(this.ksPassword,
this.ksFilename);
uc.parseLine(ADD_CACERT);
@@ -187,8 +185,8 @@
*/
@Test
public void testRemove() throws IOException, GeneralSecurityException,
- Exceptions.UnknownInput, Exceptions.InvalidKeystorePassword,
- Exceptions.UnableToSaveKeystore {
+ UnknownInputException, InvalidKeystorePasswordException,
+ UnableToSaveKeystoreException {
UpdateCertificates uc = new UpdateCertificates(this.ksPassword,
this.ksFilename);
uc.parseLine(REMOVE_CACERT);
@@ -203,8 +201,8 @@
*/
@Test
public void testAddThenRemove() throws IOException,
- GeneralSecurityException, Exceptions.UnknownInput,
- Exceptions.InvalidKeystorePassword, Exceptions.UnableToSaveKeystore {
+ GeneralSecurityException, UnknownInputException,
+ InvalidKeystorePasswordException, UnableToSaveKeystoreException {
UpdateCertificates ucAdd = new UpdateCertificates(this.ksPassword,
this.ksFilename);
ucAdd.parseLine(ADD_CACERT);
More information about the pkg-java-commits
mailing list