diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f90c21000..caf6bf117 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -58,9 +58,9 @@ - - diff --git a/res/drawable/notify_profile.png b/res/drawable/notify_profile.png new file mode 100644 index 000000000..10ac41684 Binary files /dev/null and b/res/drawable/notify_profile.png differ diff --git a/src/com/keepassdroid/Database.java b/src/com/keepassdroid/Database.java index fa3b8ec26..fa6d413b9 100644 --- a/src/com/keepassdroid/Database.java +++ b/src/com/keepassdroid/Database.java @@ -47,7 +47,8 @@ import com.keepassdroid.database.load.ImporterFactory; import com.keepassdroid.database.save.PwDbOutput; import com.keepassdroid.icons.DrawableFactory; -import com.keepassdroid.search.SearchDbHelper; +import com.keepassdroid.search.InMemorySearchHelper; +import com.keepassdroid.search.SearchHelper; /** * @author bpellin @@ -59,7 +60,7 @@ public class Database { public PwGroup root; public PwDatabase pm; public String mFilename; - public SearchDbHelper searchHelper; + private SearchHelper searchHelper; public boolean indexBuilt = false; public DrawableFactory drawFactory = new DrawableFactory(); @@ -129,7 +130,8 @@ public void LoadData(Context ctx, InputStream is, String password, String keyfil */ public void buildSearchIndex(Context ctx) { - searchHelper = new SearchDbHelper(ctx); + searchHelper = new InMemorySearchHelper(); +// searchHelper = new SearchDbHelper(ctx); initSearch(); @@ -235,5 +237,12 @@ public void markAllGroupsAsDirty() { } } + public SearchHelper getSearchHelper() { + if( searchHelper == null ) { + searchHelper = new InMemorySearchHelper(); + } + return searchHelper; + } + } diff --git a/src/com/keepassdroid/EntryActivity.java b/src/com/keepassdroid/EntryActivity.java index 7f8bd4884..712bde751 100644 --- a/src/com/keepassdroid/EntryActivity.java +++ b/src/com/keepassdroid/EntryActivity.java @@ -148,15 +148,19 @@ protected void onCreate(Bundle savedInstanceState) { // Notification Manager mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + String title = mEntry.getTitle(); + if( title == null ) { + title = ""; + } if ( mEntry.getPassword().length() > 0 ) { - // only show notification if password is available - Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password); + // only show notification if password is available + Notification password = getNotification(Intents.COPY_PASSWORD, String.format( "%s [%s]", getString(R.string.copy_password), title ), R.drawable.notify); mNM.notify(NOTIFY_PASSWORD, password); } if ( mEntry.getUsername().length() > 0 ) { // only show notification if username is available - Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username); + Notification username = getNotification(Intents.COPY_USERNAME, String.format( "%s [%s]", getString(R.string.copy_username), title ), R.drawable.notify_profile); mNM.notify(NOTIFY_USERNAME, username); } @@ -200,16 +204,32 @@ protected void onDestroy() { super.onDestroy(); } + /** + * Get {@link Notification} using custom icon resource + * @param intentText + * @param desc + * @param icon + * @return + */ + private Notification getNotification(String intentText, String desc, int icon) { + Notification notify = new Notification(icon, desc, System.currentTimeMillis()); + + Intent intent = new Intent(intentText); + PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); + + notify.setLatestEventInfo(this, getString(R.string.app_name), desc, pending); + + return notify; + } + + /** + * Get {@link Notification} using default icon (R.drawable.notify) + * @param intentText + * @param descResId + * @return + */ private Notification getNotification(String intentText, int descResId) { - String desc = getString(descResId); - Notification notify = new Notification(R.drawable.notify, desc, System.currentTimeMillis()); - - Intent intent = new Intent(intentText); - PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); - - notify.setLatestEventInfo(this, getString(R.string.app_name), desc, pending); - - return notify; + return getNotification(intentText, getString(descResId), R.drawable.notify); } private String getDateTime(Date dt) { diff --git a/src/com/keepassdroid/compat/BackupManagerCompat.java b/src/com/keepassdroid/compat/BackupManagerCompat.java index f62ed8f83..9470d6302 100644 --- a/src/com/keepassdroid/compat/BackupManagerCompat.java +++ b/src/com/keepassdroid/compat/BackupManagerCompat.java @@ -25,10 +25,9 @@ import android.content.Context; -@SuppressWarnings("unchecked") public class BackupManagerCompat { - private static Class classBackupManager; - private static Constructor constructorBackupManager; + private static Class classBackupManager; + private static Constructor constructorBackupManager; private static Method dataChanged; private Object backupManager; diff --git a/src/com/keepassdroid/database/edit/AddEntry.java b/src/com/keepassdroid/database/edit/AddEntry.java index 8bb911c8b..3af91dd4e 100644 --- a/src/com/keepassdroid/database/edit/AddEntry.java +++ b/src/com/keepassdroid/database/edit/AddEntry.java @@ -22,7 +22,7 @@ import com.keepassdroid.Database; import com.keepassdroid.database.PwEntry; import com.keepassdroid.database.PwGroup; -import com.keepassdroid.search.SearchDbHelper; +import com.keepassdroid.search.SearchHelper; public class AddEntry extends RunnableOnFinish { protected Database mDb; @@ -70,7 +70,7 @@ public void run() { if ( mDb.indexBuilt ) { // Add entry to search index - SearchDbHelper helper = mDb.searchHelper; + SearchHelper helper = mDb.getSearchHelper(); helper.open(); helper.insertEntry(mDb.pm, mEntry); helper.close(); diff --git a/src/com/keepassdroid/database/edit/DeleteEntry.java b/src/com/keepassdroid/database/edit/DeleteEntry.java index ba0115e00..afc1a19b5 100644 --- a/src/com/keepassdroid/database/edit/DeleteEntry.java +++ b/src/com/keepassdroid/database/edit/DeleteEntry.java @@ -22,7 +22,7 @@ import com.keepassdroid.Database; import com.keepassdroid.database.PwEntry; import com.keepassdroid.database.PwGroup; -import com.keepassdroid.search.SearchDbHelper; +import com.keepassdroid.search.SearchHelper; /** Task to delete entries * @author bpellin @@ -88,7 +88,7 @@ public AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry) { public void run() { if ( mSuccess ) { if ( mDb.indexBuilt ) { - SearchDbHelper dbHelper = mDb.searchHelper; + SearchHelper dbHelper = mDb.getSearchHelper(); dbHelper.open(); // Remove from entry global diff --git a/src/com/keepassdroid/database/edit/UpdateEntry.java b/src/com/keepassdroid/database/edit/UpdateEntry.java index dfc652f9c..9219592ba 100644 --- a/src/com/keepassdroid/database/edit/UpdateEntry.java +++ b/src/com/keepassdroid/database/edit/UpdateEntry.java @@ -22,7 +22,7 @@ import com.keepassdroid.Database; import com.keepassdroid.database.PwEntry; import com.keepassdroid.database.PwGroup; -import com.keepassdroid.search.SearchDbHelper; +import com.keepassdroid.search.SearchHelper; public class UpdateEntry extends RunnableOnFinish { private Database mDb; @@ -79,7 +79,7 @@ public void run() { if ( mDb.indexBuilt ) { // Update search index - SearchDbHelper helper = mDb.searchHelper; + SearchHelper helper = mDb.getSearchHelper(); helper.open(); helper.updateEntry(mDb.pm, mOldE); helper.close(); diff --git a/src/com/keepassdroid/search/InMemorySearchHelper.java b/src/com/keepassdroid/search/InMemorySearchHelper.java new file mode 100644 index 000000000..3df568b5f --- /dev/null +++ b/src/com/keepassdroid/search/InMemorySearchHelper.java @@ -0,0 +1,134 @@ +/* + * Copyright 2009-2011 Brian Pellin. + * Copyright 2011 riku salkia + * + * This file is part of KeePassDroid. + * + * KeePassDroid 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. + * + * KeePassDroid 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 KeePassDroid. If not, see . + * + */ +package com.keepassdroid.search; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import android.util.Log; + +import com.keepassdroid.Database; +import com.keepassdroid.database.PwDatabase; +import com.keepassdroid.database.PwDatabaseV3; +import com.keepassdroid.database.PwDatabaseV4; +import com.keepassdroid.database.PwEntry; +import com.keepassdroid.database.PwEntryV4; +import com.keepassdroid.database.PwGroup; +import com.keepassdroid.database.PwGroupV3; +import com.keepassdroid.database.PwGroupV4; + +public class InMemorySearchHelper implements SearchHelper { + private static final String TAG = InMemorySearchHelper.class.getSimpleName(); + private Map> stringMap = new HashMap>(); + + @Override + public SearchHelper open(){ + return this; + } + + @Override + public void close() { + } + + @Override + public void clear() { + } + + @Override + public void insertEntry(PwDatabase db, PwEntry entry) { + UUID uuid = entry.getUUID(); + Collection strings = new ArrayList(); + strings.add( entry.getTitle().toLowerCase() ); + strings.add( entry.getUrl().toLowerCase() ); + strings.add( entry.getUsername().toLowerCase() ); + strings.add( entry.getNotes().toLowerCase() ); + + if( entry instanceof PwEntryV4 ) { + // Add Advanced keys&values https://code.google.com/p/keepassdroid/issues/detail?id=162 + PwEntryV4 v4 = (PwEntryV4) entry; + for( String key : v4.strings.keySet() ) { + strings.add(key.toLowerCase()); + strings.add(v4.strings.get(key).toLowerCase()); + } + } + + stringMap.put(uuid, strings); + } + + @Override + public void insertEntry(PwDatabase db, List entries) { + for( PwEntry entry : entries ) { + insertEntry( db, entry ); + } + } + + @Override + public void updateEntry(PwDatabase db, PwEntry entry) { + insertEntry(db, entry); + } + + @Override + public void deleteEntry(PwEntry entry) { + stringMap.remove( entry.getUUID() ); + } + + @Override + public PwGroup search(Database db, String qStr) { + long start = System.currentTimeMillis(); + + final String searchStr = qStr.toLowerCase(); + + PwGroup group; + if ( db.pm instanceof PwDatabaseV3 ) { + group = new PwGroupV3(); + } else if ( db.pm instanceof PwDatabaseV4 ) { + group = new PwGroupV4(); + } else { + Log.d(TAG, "Tried to search with unknown db"); + return null; + } + group.name = "Search results"; + group.childEntries = new ArrayList(); + + int entries = 0; + int total = 0; + + for( UUID uuid : stringMap.keySet() ) { + for( String str : stringMap.get(uuid) ) { + if( str.contains( searchStr ) ) { + PwEntry entry = (PwEntry) db.entries.get(uuid); + group.childEntries.add(entry); + } + + total++; + } + entries++; + } + Log.d(TAG, String.format("Searched %d entries, %d strings. Search took %dms to complete", entries, total, System.currentTimeMillis()-start) ); + + return group; + } + +} diff --git a/src/com/keepassdroid/search/SearchDbHelper.java b/src/com/keepassdroid/search/SearchDbHelper.java index 3285b4110..c905b5f06 100644 --- a/src/com/keepassdroid/search/SearchDbHelper.java +++ b/src/com/keepassdroid/search/SearchDbHelper.java @@ -43,7 +43,8 @@ import com.keepassdroid.database.PwGroupV3; import com.keepassdroid.database.PwGroupV4; -public class SearchDbHelper { +@Deprecated +public class SearchDbHelper implements SearchHelper { private static final String DATABASE_NAME = "search"; private static final String SEARCH_TABLE = "entries"; private static final int DATABASE_VERSION = 3; @@ -104,18 +105,30 @@ private void initOmitBackup() { } - public SearchDbHelper open() throws SQLException { + /* (non-Javadoc) + * @see com.keepassdroid.search.SearchHelper#open() + */ + @Override + public SearchHelper open() throws SQLException { mDbHelper = new DatabaseHelper(mCtx); mDb = mDbHelper.getWritableDatabase(); mDb.execSQL(PRAGMA_NO_SYNCHRONOUS); return this; } - public void close() { + /* (non-Javadoc) + * @see com.keepassdroid.search.SearchHelper#close() + */ + @Override + public void close() { mDb.close(); } - public void clear() { + /* (non-Javadoc) + * @see com.keepassdroid.search.SearchHelper#clear() + */ + @Override + public void clear() { mDb.delete(SEARCH_TABLE, null, null); initOmitBackup(); } @@ -135,14 +148,22 @@ private ContentValues buildNewEntryContent(PwDatabase db, PwEntry entry) { return cv; } - public void insertEntry(PwDatabase db, PwEntry entry) { + /* (non-Javadoc) + * @see com.keepassdroid.search.SearchHelper#insertEntry(com.keepassdroid.database.PwDatabase, com.keepassdroid.database.PwEntry) + */ + @Override + public void insertEntry(PwDatabase db, PwEntry entry) { if (!isOmitBackup || !db.isBackup(entry.getParent())) { ContentValues cv = buildNewEntryContent(db, entry); mDb.insert(SEARCH_TABLE, null, cv); } } - public void insertEntry(PwDatabase db, List entries) { + /* (non-Javadoc) + * @see com.keepassdroid.search.SearchHelper#insertEntry(com.keepassdroid.database.PwDatabase, java.util.List) + */ + @Override + public void insertEntry(PwDatabase db, List entries) { mDb.beginTransaction(); try { @@ -155,21 +176,33 @@ public void insertEntry(PwDatabase db, List entries) { } } - public void updateEntry(PwDatabase db, PwEntry entry) { + /* (non-Javadoc) + * @see com.keepassdroid.search.SearchHelper#updateEntry(com.keepassdroid.database.PwDatabase, com.keepassdroid.database.PwEntry) + */ + @Override + public void updateEntry(PwDatabase db, PwEntry entry) { ContentValues cv = buildNewEntryContent(db, entry); String uuidStr = cv.getAsString(KEY_UUID); mDb.update(SEARCH_TABLE, cv, KEY_UUID + " = ?", new String[] {uuidStr}); } - public void deleteEntry(PwEntry entry) { + /* (non-Javadoc) + * @see com.keepassdroid.search.SearchHelper#deleteEntry(com.keepassdroid.database.PwEntry) + */ + @Override + public void deleteEntry(PwEntry entry) { UUID uuid = entry.getUUID(); String uuidStr = uuid.toString(); mDb.delete(SEARCH_TABLE, KEY_UUID + " = ?", new String[] {uuidStr}); } - public PwGroup search(Database db, String qStr) { + /* (non-Javadoc) + * @see com.keepassdroid.search.SearchHelper#search(com.keepassdroid.Database, java.lang.String) + */ + @Override + public PwGroup search(Database db, String qStr) { Cursor cursor; String queryWithWildCard = addWildCard(qStr); diff --git a/src/com/keepassdroid/search/SearchHelper.java b/src/com/keepassdroid/search/SearchHelper.java new file mode 100644 index 000000000..ad41ddc4b --- /dev/null +++ b/src/com/keepassdroid/search/SearchHelper.java @@ -0,0 +1,56 @@ +/* + * Copyright 2009-2011 Brian Pellin. + * Copyright 2011 riku salkia + * + * This file is part of KeePassDroid. + * + * KeePassDroid 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. + * + * KeePassDroid 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 KeePassDroid. If not, see . + * + */ +package com.keepassdroid.search; + +import java.util.List; + +import com.keepassdroid.Database; +import com.keepassdroid.database.PwDatabase; +import com.keepassdroid.database.PwEntry; +import com.keepassdroid.database.PwGroup; + +public interface SearchHelper { + + /** + * Called before insert/update/delete for opening a backing resource (database/file/whatever) + * @return this + */ + public abstract SearchHelper open(); + + /** + * Called after insert/update/delete for closing backing resource (database/file/whatever) + * @return this + */ + public abstract void close(); + + public abstract void clear(); + + public abstract void insertEntry(PwDatabase db, PwEntry entry); + + public abstract void insertEntry(PwDatabase db, List entries); + + public abstract void updateEntry(PwDatabase db, PwEntry entry); + + public abstract void deleteEntry(PwEntry entry); + + public abstract PwGroup search(Database db, String qStr); + +} \ No newline at end of file diff --git a/src/org/bouncycastle/asn1/ASN1OctetString.java b/src/org/bouncycastle/asn1/ASN1OctetString.java index d235458e1..f4cde8d0f 100644 --- a/src/org/bouncycastle/asn1/ASN1OctetString.java +++ b/src/org/bouncycastle/asn1/ASN1OctetString.java @@ -37,7 +37,6 @@ public static ASN1OctetString getInstance( * @param obj the object we want converted. * @exception IllegalArgumentException if the object cannot be converted. */ - @SuppressWarnings("unchecked") public static ASN1OctetString getInstance( Object obj) { @@ -53,8 +52,8 @@ public static ASN1OctetString getInstance( if (obj instanceof ASN1Sequence) { - Vector v = new Vector(); - Enumeration e = ((ASN1Sequence)obj).getObjects(); + Vector v = new Vector(); + Enumeration e = ((ASN1Sequence)obj).getObjects(); while (e.hasMoreElements()) { diff --git a/src/org/bouncycastle/asn1/ASN1Sequence.java b/src/org/bouncycastle/asn1/ASN1Sequence.java index da80adec3..b48a54949 100644 --- a/src/org/bouncycastle/asn1/ASN1Sequence.java +++ b/src/org/bouncycastle/asn1/ASN1Sequence.java @@ -4,11 +4,10 @@ import java.util.Enumeration; import java.util.Vector; -@SuppressWarnings("unchecked") public abstract class ASN1Sequence extends ASN1Object { - private Vector seq = new Vector(); + private Vector seq = new Vector(); /** * return an ASN1Sequence from the given object. @@ -86,7 +85,7 @@ public static ASN1Sequence getInstance( throw new IllegalArgumentException("unknown object in getInstance: " + obj.getClass().getName()); } - public Enumeration getObjects() + public Enumeration getObjects() { return seq.elements(); } @@ -152,7 +151,7 @@ public int size() public int hashCode() { - Enumeration e = this.getObjects(); + Enumeration e = this.getObjects(); int hashCode = size(); while (e.hasMoreElements()) @@ -183,8 +182,8 @@ boolean asn1Equals( return false; } - Enumeration s1 = this.getObjects(); - Enumeration s2 = other.getObjects(); + Enumeration s1 = this.getObjects(); + Enumeration s2 = other.getObjects(); while (s1.hasMoreElements()) { diff --git a/src/org/bouncycastle/asn1/ASN1Set.java b/src/org/bouncycastle/asn1/ASN1Set.java index 2eaafe0ec..2f3496b42 100644 --- a/src/org/bouncycastle/asn1/ASN1Set.java +++ b/src/org/bouncycastle/asn1/ASN1Set.java @@ -5,11 +5,10 @@ import java.util.Enumeration; import java.util.Vector; -@SuppressWarnings("unchecked") abstract public class ASN1Set extends ASN1Object { - protected Vector set = new Vector(); + protected Vector set = new Vector(); /** * return an ASN1Set from the given object. @@ -86,7 +85,7 @@ public static ASN1Set getInstance( if (obj.getObject() instanceof ASN1Sequence) { ASN1Sequence s = (ASN1Sequence)obj.getObject(); - Enumeration e = s.getObjects(); + Enumeration e = s.getObjects(); while (e.hasMoreElements()) { @@ -105,7 +104,7 @@ public ASN1Set() { } - public Enumeration getObjects() + public Enumeration getObjects() { return set.elements(); } @@ -171,7 +170,7 @@ public DERObject getDERObject() public int hashCode() { - Enumeration e = this.getObjects(); + Enumeration e = this.getObjects(); int hashCode = size(); while (e.hasMoreElements()) @@ -202,8 +201,8 @@ boolean asn1Equals( return false; } - Enumeration s1 = this.getObjects(); - Enumeration s2 = other.getObjects(); + Enumeration s1 = this.getObjects(); + Enumeration s2 = other.getObjects(); while (s1.hasMoreElements()) { diff --git a/src/org/bouncycastle/asn1/BERConstructedOctetString.java b/src/org/bouncycastle/asn1/BERConstructedOctetString.java index dfa8ac477..628341ba8 100644 --- a/src/org/bouncycastle/asn1/BERConstructedOctetString.java +++ b/src/org/bouncycastle/asn1/BERConstructedOctetString.java @@ -5,7 +5,6 @@ import java.util.Enumeration; import java.util.Vector; -@SuppressWarnings("unchecked") public class BERConstructedOctetString extends DEROctetString { @@ -15,7 +14,7 @@ public class BERConstructedOctetString * convert a vector of octet strings into a single byte string */ static private byte[] toBytes( - Vector octs) + Vector octs) { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); @@ -40,7 +39,7 @@ static private byte[] toBytes( return bOut.toByteArray(); } - private Vector octs; + private Vector octs; /** * @param string the octets making up the octet string. @@ -52,7 +51,7 @@ public BERConstructedOctetString( } public BERConstructedOctetString( - Vector octs) + Vector octs) { super(toBytes(octs)); @@ -79,7 +78,7 @@ public byte[] getOctets() /** * return the DER octets that make up this string. */ - public Enumeration getObjects() + public Enumeration getObjects() { if (octs == null) { @@ -89,9 +88,9 @@ public Enumeration getObjects() return octs.elements(); } - private Vector generateOcts() + private Vector generateOcts() { - Vector vec = new Vector(); + Vector vec = new Vector(); for (int i = 0; i < string.length; i += MAX_LENGTH) { int end; @@ -128,7 +127,7 @@ public void encode( // // write out the octet array // - Enumeration e = getObjects(); + Enumeration e = getObjects(); while (e.hasMoreElements()) { out.writeObject(e.nextElement()); diff --git a/src/org/bouncycastle/asn1/BERConstructedSequence.java b/src/org/bouncycastle/asn1/BERConstructedSequence.java index 9e1d6a591..d7f8fee99 100644 --- a/src/org/bouncycastle/asn1/BERConstructedSequence.java +++ b/src/org/bouncycastle/asn1/BERConstructedSequence.java @@ -6,7 +6,6 @@ /** * @deprecated use BERSequence */ -@SuppressWarnings("unchecked") public class BERConstructedSequence extends DERConstructedSequence { @@ -21,7 +20,7 @@ void encode( out.write(SEQUENCE | CONSTRUCTED); out.write(0x80); - Enumeration e = getObjects(); + Enumeration e = getObjects(); while (e.hasMoreElements()) { out.writeObject(e.nextElement()); diff --git a/src/org/bouncycastle/asn1/BERInputStream.java b/src/org/bouncycastle/asn1/BERInputStream.java index 1dfa06d9d..1c2f6c59e 100644 --- a/src/org/bouncycastle/asn1/BERInputStream.java +++ b/src/org/bouncycastle/asn1/BERInputStream.java @@ -9,7 +9,6 @@ /** * @deprecated use ASN1InputStream */ -@SuppressWarnings("unchecked") public class BERInputStream extends DERInputStream { @@ -65,7 +64,7 @@ private byte[] readIndefiniteLengthFully() private BERConstructedOctetString buildConstructedOctetString() throws IOException { - Vector octs = new Vector(); + Vector octs = new Vector(); for (;;) { diff --git a/src/org/bouncycastle/asn1/BERSequence.java b/src/org/bouncycastle/asn1/BERSequence.java index 5054fb528..14d407ef6 100644 --- a/src/org/bouncycastle/asn1/BERSequence.java +++ b/src/org/bouncycastle/asn1/BERSequence.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.util.Enumeration; -@SuppressWarnings("unchecked") public class BERSequence extends DERSequence { @@ -43,7 +42,7 @@ void encode( out.write(SEQUENCE | CONSTRUCTED); out.write(0x80); - Enumeration e = getObjects(); + Enumeration e = getObjects(); while (e.hasMoreElements()) { out.writeObject(e.nextElement()); diff --git a/src/org/bouncycastle/asn1/BERSet.java b/src/org/bouncycastle/asn1/BERSet.java index 9f3320293..ab16fb19f 100644 --- a/src/org/bouncycastle/asn1/BERSet.java +++ b/src/org/bouncycastle/asn1/BERSet.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.util.Enumeration; -@SuppressWarnings("unchecked") public class BERSet extends DERSet { @@ -53,7 +52,7 @@ void encode( out.write(SET | CONSTRUCTED); out.write(0x80); - Enumeration e = getObjects(); + Enumeration e = getObjects(); while (e.hasMoreElements()) { out.writeObject(e.nextElement()); diff --git a/src/org/bouncycastle/asn1/BERTaggedObject.java b/src/org/bouncycastle/asn1/BERTaggedObject.java index 990c1432a..4ff336d45 100644 --- a/src/org/bouncycastle/asn1/BERTaggedObject.java +++ b/src/org/bouncycastle/asn1/BERTaggedObject.java @@ -8,7 +8,6 @@ * a [n] where n is some number - these are assumed to follow the construction * rules (as with sequences). */ -@SuppressWarnings("unchecked") public class BERTaggedObject extends DERTaggedObject { @@ -59,7 +58,7 @@ void encode( { if (!explicit) { - Enumeration e; + Enumeration e; if (obj instanceof ASN1OctetString) { if (obj instanceof BERConstructedOctetString) diff --git a/src/org/bouncycastle/asn1/DERConstructedSequence.java b/src/org/bouncycastle/asn1/DERConstructedSequence.java index 1011cb936..d659783b9 100644 --- a/src/org/bouncycastle/asn1/DERConstructedSequence.java +++ b/src/org/bouncycastle/asn1/DERConstructedSequence.java @@ -7,7 +7,6 @@ /** * @deprecated use DERSequence. */ -@SuppressWarnings("unchecked") public class DERConstructedSequence extends ASN1Sequence { @@ -36,7 +35,7 @@ void encode( { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); - Enumeration e = this.getObjects(); + Enumeration e = this.getObjects(); while (e.hasMoreElements()) { diff --git a/src/org/bouncycastle/asn1/DERConstructedSet.java b/src/org/bouncycastle/asn1/DERConstructedSet.java index 656d56b2e..0acd609c3 100644 --- a/src/org/bouncycastle/asn1/DERConstructedSet.java +++ b/src/org/bouncycastle/asn1/DERConstructedSet.java @@ -8,7 +8,6 @@ * * @deprecated use DERSet */ -@SuppressWarnings("unchecked") public class DERConstructedSet extends ASN1Set { @@ -62,7 +61,7 @@ void encode( { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); - Enumeration e = this.getObjects(); + Enumeration e = this.getObjects(); while (e.hasMoreElements()) { diff --git a/src/org/bouncycastle/asn1/DEREncodableVector.java b/src/org/bouncycastle/asn1/DEREncodableVector.java index 86a294504..625c6c164 100644 --- a/src/org/bouncycastle/asn1/DEREncodableVector.java +++ b/src/org/bouncycastle/asn1/DEREncodableVector.java @@ -7,10 +7,9 @@ * this will eventually be superceded by ASN1EncodableVector so you should * use that class in preference. */ -@SuppressWarnings("unchecked") public class DEREncodableVector { - Vector v = new Vector(); + Vector v = new Vector(); /** * @deprecated use ASN1EncodableVector instead. diff --git a/src/org/bouncycastle/asn1/DERSequence.java b/src/org/bouncycastle/asn1/DERSequence.java index 593dfe99b..3bb0867f0 100644 --- a/src/org/bouncycastle/asn1/DERSequence.java +++ b/src/org/bouncycastle/asn1/DERSequence.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.util.Enumeration; -@SuppressWarnings("unchecked") public class DERSequence extends ASN1Sequence { @@ -63,7 +62,7 @@ void encode( // TODO Intermediate buffer could be avoided if we could calculate expected length ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); - Enumeration e = this.getObjects(); + Enumeration e = this.getObjects(); while (e.hasMoreElements()) { diff --git a/src/org/bouncycastle/asn1/DERSet.java b/src/org/bouncycastle/asn1/DERSet.java index 2634e13d3..d4f27052d 100644 --- a/src/org/bouncycastle/asn1/DERSet.java +++ b/src/org/bouncycastle/asn1/DERSet.java @@ -7,7 +7,6 @@ /** * A DER encoded set object */ -@SuppressWarnings("unchecked") public class DERSet extends ASN1Set { @@ -83,7 +82,7 @@ void encode( // TODO Intermediate buffer could be avoided if we could calculate expected length ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); - Enumeration e = this.getObjects(); + Enumeration e = this.getObjects(); while (e.hasMoreElements()) { diff --git a/src/org/bouncycastle/asn1/LazyDERConstructionEnumeration.java b/src/org/bouncycastle/asn1/LazyDERConstructionEnumeration.java index 379c7bf13..fa2124dac 100644 --- a/src/org/bouncycastle/asn1/LazyDERConstructionEnumeration.java +++ b/src/org/bouncycastle/asn1/LazyDERConstructionEnumeration.java @@ -3,9 +3,8 @@ import java.util.Enumeration; import java.io.IOException; -@SuppressWarnings("unchecked") class LazyDERConstructionEnumeration - implements Enumeration + implements Enumeration { private ASN1InputStream aIn; private Object nextObj; diff --git a/src/org/bouncycastle/asn1/oiw/ElGamalParameter.java b/src/org/bouncycastle/asn1/oiw/ElGamalParameter.java index 21ffeeeb3..5e9d61e33 100644 --- a/src/org/bouncycastle/asn1/oiw/ElGamalParameter.java +++ b/src/org/bouncycastle/asn1/oiw/ElGamalParameter.java @@ -5,7 +5,6 @@ import org.bouncycastle.asn1.*; -@SuppressWarnings("unchecked") public class ElGamalParameter extends ASN1Encodable { @@ -22,7 +21,7 @@ public ElGamalParameter( public ElGamalParameter( ASN1Sequence seq) { - Enumeration e = seq.getObjects(); + Enumeration e = seq.getObjects(); p = (DERInteger)e.nextElement(); g = (DERInteger)e.nextElement(); diff --git a/src/org/bouncycastle/asn1/pkcs/ContentInfo.java b/src/org/bouncycastle/asn1/pkcs/ContentInfo.java index 06b03ffd1..bad77dd0d 100644 --- a/src/org/bouncycastle/asn1/pkcs/ContentInfo.java +++ b/src/org/bouncycastle/asn1/pkcs/ContentInfo.java @@ -12,7 +12,6 @@ import org.bouncycastle.asn1.DERObjectIdentifier; import org.bouncycastle.asn1.DERTaggedObject; -@SuppressWarnings("unchecked") public class ContentInfo extends ASN1Encodable implements PKCSObjectIdentifiers @@ -38,7 +37,7 @@ else if (obj instanceof ASN1Sequence) public ContentInfo( ASN1Sequence seq) { - Enumeration e = seq.getObjects(); + Enumeration e = seq.getObjects(); contentType = (DERObjectIdentifier)e.nextElement(); diff --git a/src/org/bouncycastle/asn1/pkcs/DHParameter.java b/src/org/bouncycastle/asn1/pkcs/DHParameter.java index 4ab8cf703..b31f335ca 100644 --- a/src/org/bouncycastle/asn1/pkcs/DHParameter.java +++ b/src/org/bouncycastle/asn1/pkcs/DHParameter.java @@ -10,7 +10,6 @@ import org.bouncycastle.asn1.DERObject; import org.bouncycastle.asn1.DERSequence; -@SuppressWarnings("unchecked") public class DHParameter extends ASN1Encodable { @@ -37,7 +36,7 @@ public DHParameter( public DHParameter( ASN1Sequence seq) { - Enumeration e = seq.getObjects(); + Enumeration e = seq.getObjects(); p = (DERInteger)e.nextElement(); g = (DERInteger)e.nextElement(); diff --git a/src/org/bouncycastle/asn1/pkcs/PBKDF2Params.java b/src/org/bouncycastle/asn1/pkcs/PBKDF2Params.java index 9fe14bd84..f0533efb4 100644 --- a/src/org/bouncycastle/asn1/pkcs/PBKDF2Params.java +++ b/src/org/bouncycastle/asn1/pkcs/PBKDF2Params.java @@ -12,7 +12,6 @@ import org.bouncycastle.asn1.DEROctetString; import org.bouncycastle.asn1.DERSequence; -@SuppressWarnings("unchecked") public class PBKDF2Params extends ASN1Encodable { @@ -47,7 +46,7 @@ public PBKDF2Params( public PBKDF2Params( ASN1Sequence seq) { - Enumeration e = seq.getObjects(); + Enumeration e = seq.getObjects(); octStr = (ASN1OctetString)e.nextElement(); iterationCount = (DERInteger)e.nextElement(); diff --git a/src/org/bouncycastle/asn1/pkcs/RSAPrivateKeyStructure.java b/src/org/bouncycastle/asn1/pkcs/RSAPrivateKeyStructure.java index b931ee7d2..737338b36 100644 --- a/src/org/bouncycastle/asn1/pkcs/RSAPrivateKeyStructure.java +++ b/src/org/bouncycastle/asn1/pkcs/RSAPrivateKeyStructure.java @@ -11,7 +11,6 @@ import org.bouncycastle.asn1.DERObject; import org.bouncycastle.asn1.DERSequence; -@SuppressWarnings("unchecked") public class RSAPrivateKeyStructure extends ASN1Encodable { @@ -72,7 +71,7 @@ public RSAPrivateKeyStructure( public RSAPrivateKeyStructure( ASN1Sequence seq) { - Enumeration e = seq.getObjects(); + Enumeration e = seq.getObjects(); BigInteger v = ((DERInteger)e.nextElement()).getValue(); if (v.intValue() != 0 && v.intValue() != 1) diff --git a/src/org/bouncycastle/asn1/pkcs/SignedData.java b/src/org/bouncycastle/asn1/pkcs/SignedData.java index 1ac0c05ea..aedbaab26 100644 --- a/src/org/bouncycastle/asn1/pkcs/SignedData.java +++ b/src/org/bouncycastle/asn1/pkcs/SignedData.java @@ -14,7 +14,6 @@ /** * a PKCS#7 signed data object. */ -@SuppressWarnings("unchecked") public class SignedData extends ASN1Encodable implements PKCSObjectIdentifiers @@ -60,7 +59,7 @@ public SignedData( public SignedData( ASN1Sequence seq) { - Enumeration e = seq.getObjects(); + Enumeration e = seq.getObjects(); version = (DERInteger)e.nextElement(); digestAlgorithms = ((ASN1Set)e.nextElement()); diff --git a/src/org/bouncycastle/asn1/util/ASN1Dump.java b/src/org/bouncycastle/asn1/util/ASN1Dump.java index 250fac1de..68a793439 100644 --- a/src/org/bouncycastle/asn1/util/ASN1Dump.java +++ b/src/org/bouncycastle/asn1/util/ASN1Dump.java @@ -40,7 +40,7 @@ import org.bouncycastle.asn1.DERVisibleString; import org.bouncycastle.util.encoders.Hex; -@SuppressWarnings({ "unchecked", "deprecation" }) +@SuppressWarnings({ "deprecation" }) public class ASN1Dump { private static final String TAB = " "; @@ -60,7 +60,7 @@ static void _dumpAsString( String nl = System.getProperty("line.separator"); if (obj instanceof ASN1Sequence) { - Enumeration e = ((ASN1Sequence)obj).getObjects(); + Enumeration e = ((ASN1Sequence)obj).getObjects(); String tab = indent + TAB; buf.append(indent); @@ -146,7 +146,7 @@ else if (obj instanceof DERTaggedObject) } else if (obj instanceof DERConstructedSet) { - Enumeration e = ((ASN1Set)obj).getObjects(); + Enumeration e = ((ASN1Set)obj).getObjects(); String tab = indent + TAB; buf.append(indent); @@ -175,7 +175,7 @@ else if (o instanceof DERObject) } else if (obj instanceof BERSet) { - Enumeration e = ((ASN1Set)obj).getObjects(); + Enumeration e = ((ASN1Set)obj).getObjects(); String tab = indent + TAB; buf.append(indent); @@ -204,7 +204,7 @@ else if (o instanceof DERObject) } else if (obj instanceof DERSet) { - Enumeration e = ((ASN1Set)obj).getObjects(); + Enumeration e = ((ASN1Set)obj).getObjects(); String tab = indent + TAB; buf.append(indent); @@ -365,7 +365,7 @@ private static String outputApplicationSpecific(String type, String indent, bool { ASN1Sequence s = ASN1Sequence.getInstance(app.getObject(DERTags.SEQUENCE)); buf.append(indent + type + " ApplicationSpecific[" + app.getApplicationTag() + "]" + nl); - for (Enumeration e = s.getObjects(); e.hasMoreElements();) + for (Enumeration e = s.getObjects(); e.hasMoreElements();) { _dumpAsString(indent + TAB, verbose, (DERObject)e.nextElement(), buf); } diff --git a/src/org/bouncycastle/crypto/macs/HMac.java b/src/org/bouncycastle/crypto/macs/HMac.java index cbe87ed5d..5b62f124a 100644 --- a/src/org/bouncycastle/crypto/macs/HMac.java +++ b/src/org/bouncycastle/crypto/macs/HMac.java @@ -13,7 +13,6 @@ * * H(K XOR opad, H(K XOR ipad, text)) */ -@SuppressWarnings("unchecked") public class HMac implements Mac { @@ -27,11 +26,11 @@ public class HMac private byte[] inputPad; private byte[] outputPad; - private static Hashtable blockLengths; + private static Hashtable blockLengths; static { - blockLengths = new Hashtable(); + blockLengths = new Hashtable(); blockLengths.put("GOST3411", new Integer(32)); diff --git a/src/org/bouncycastle/jce/interfaces/PKCS12BagAttributeCarrier.java b/src/org/bouncycastle/jce/interfaces/PKCS12BagAttributeCarrier.java index 25f2947e0..a1f0b2c7e 100644 --- a/src/org/bouncycastle/jce/interfaces/PKCS12BagAttributeCarrier.java +++ b/src/org/bouncycastle/jce/interfaces/PKCS12BagAttributeCarrier.java @@ -8,7 +8,6 @@ /** * allow us to set attributes on objects that can go into a PKCS12 store. */ -@SuppressWarnings("unchecked") public interface PKCS12BagAttributeCarrier { void setBagAttribute( @@ -18,5 +17,5 @@ void setBagAttribute( DEREncodable getBagAttribute( DERObjectIdentifier oid); - Enumeration getBagAttributeKeys(); + Enumeration getBagAttributeKeys(); } diff --git a/src/org/bouncycastle/jce/provider/JCEBlockCipher.java b/src/org/bouncycastle/jce/provider/JCEBlockCipher.java index 73448fd1b..768a51443 100644 --- a/src/org/bouncycastle/jce/provider/JCEBlockCipher.java +++ b/src/org/bouncycastle/jce/provider/JCEBlockCipher.java @@ -89,7 +89,8 @@ public class JCEBlockCipher extends WrapCipherSpi // // specs we can handle. // - private Class[] availableSpecs = + @SuppressWarnings("rawtypes") + private Class[] availableSpecs = { //RC2ParameterSpec.class, //RC5ParameterSpec.class, diff --git a/src/org/bouncycastle/jce/provider/JCEStreamCipher.java b/src/org/bouncycastle/jce/provider/JCEStreamCipher.java index d366c10b9..1746424d3 100644 --- a/src/org/bouncycastle/jce/provider/JCEStreamCipher.java +++ b/src/org/bouncycastle/jce/provider/JCEStreamCipher.java @@ -43,6 +43,7 @@ public class JCEStreamCipher // // specs we can handle. // + @SuppressWarnings("rawtypes") private Class[] availableSpecs = { RC2ParameterSpec.class, diff --git a/src/org/bouncycastle/jce/provider/PKCS12BagAttributeCarrierImpl.java b/src/org/bouncycastle/jce/provider/PKCS12BagAttributeCarrierImpl.java index 9907b2007..a1ce44f03 100644 --- a/src/org/bouncycastle/jce/provider/PKCS12BagAttributeCarrierImpl.java +++ b/src/org/bouncycastle/jce/provider/PKCS12BagAttributeCarrierImpl.java @@ -18,10 +18,10 @@ class PKCS12BagAttributeCarrierImpl implements PKCS12BagAttributeCarrier { - private Hashtable pkcs12Attributes; - private Vector pkcs12Ordering; + private Hashtable pkcs12Attributes; + private Vector pkcs12Ordering; - PKCS12BagAttributeCarrierImpl(Hashtable attributes, Vector ordering) + PKCS12BagAttributeCarrierImpl(Hashtable attributes, Vector ordering) { this.pkcs12Attributes = attributes; this.pkcs12Ordering = ordering; @@ -29,7 +29,7 @@ class PKCS12BagAttributeCarrierImpl public PKCS12BagAttributeCarrierImpl() { - this(new Hashtable(), new Vector()); + this(new Hashtable(), new Vector()); } public void setBagAttribute( @@ -53,7 +53,7 @@ public DEREncodable getBagAttribute( return (DEREncodable)pkcs12Attributes.get(oid); } - public Enumeration getBagAttributeKeys() + public Enumeration getBagAttributeKeys() { return pkcs12Ordering.elements(); } @@ -63,12 +63,12 @@ int size() return pkcs12Ordering.size(); } - Hashtable getAttributes() + Hashtable getAttributes() { return pkcs12Attributes; } - Vector getOrdering() + Vector getOrdering() { return pkcs12Ordering; } @@ -78,15 +78,15 @@ public void writeObject(ObjectOutputStream out) { if (pkcs12Ordering.size() == 0) { - out.writeObject(new Hashtable()); - out.writeObject(new Vector()); + out.writeObject(new Hashtable()); + out.writeObject(new Vector()); } else { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ASN1OutputStream aOut = new ASN1OutputStream(bOut); - Enumeration e = this.getBagAttributeKeys(); + Enumeration e = this.getBagAttributeKeys(); while (e.hasMoreElements()) { @@ -107,8 +107,8 @@ public void readObject(ObjectInputStream in) if (obj instanceof Hashtable) { - this.pkcs12Attributes = (Hashtable)obj; - this.pkcs12Ordering = (Vector)in.readObject(); + this.pkcs12Attributes = (Hashtable)obj; + this.pkcs12Ordering = (Vector)in.readObject(); } else { diff --git a/src/org/bouncycastle/jce/provider/WrapCipherSpi.java b/src/org/bouncycastle/jce/provider/WrapCipherSpi.java index 090fbf130..a9ab193bd 100644 --- a/src/org/bouncycastle/jce/provider/WrapCipherSpi.java +++ b/src/org/bouncycastle/jce/provider/WrapCipherSpi.java @@ -50,8 +50,8 @@ public abstract class WrapCipherSpi extends CipherSpi // // specs we can handle. // - @SuppressWarnings("unchecked") - private Class[] availableSpecs = + @SuppressWarnings("rawtypes") + private Class[] availableSpecs = { IvParameterSpec.class, PBEParameterSpec.class, diff --git a/src/org/bouncycastle/util/Strings.java b/src/org/bouncycastle/util/Strings.java index 253e72261..7985d6a82 100644 --- a/src/org/bouncycastle/util/Strings.java +++ b/src/org/bouncycastle/util/Strings.java @@ -213,10 +213,9 @@ public static byte[] toByteArray(String string) return bytes; } - @SuppressWarnings("unchecked") - public static String[] split(String input, char delimiter) + public static String[] split(String input, char delimiter) { - Vector v = new Vector(); + Vector v = new Vector(); boolean moreTokens = true; String subString;