[jsword-svn] r1942 - trunk/jsword/src/main/java/org/crosswire/jsword/book/basic

dmsmith at crosswire.org dmsmith at crosswire.org
Mon Mar 23 06:00:47 MST 2009


Author: dmsmith
Date: 2009-03-23 06:00:47 -0700 (Mon, 23 Mar 2009)
New Revision: 1942

Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBook.java
Log:
Added a more thorough check of an unlock key to AbstractBook.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBook.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBook.java	2009-03-23 12:31:37 UTC (rev 1941)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBook.java	2009-03-23 13:00:47 UTC (rev 1942)
@@ -296,9 +296,43 @@
      */
     public boolean unlock(String unlockKey)
     {
-        return bmd.unlock(unlockKey);
+        boolean state = bmd.unlock(unlockKey);
+        if (state)
+        {
+            // Double check.
+            return isUnlockKeyValid();
+        }
+        return state;
     }
 
+    /**
+     * This is a heuristic that tries out the key.
+     * @return true if there were no exceptions in reading the enciphered module.
+     */
+    private boolean isUnlockKeyValid()
+    {
+        try
+        {
+            Key key = getGlobalKeyList();
+            if (key == null)
+            {
+                // weird key == null, assume it is valid
+                return true;
+            }
+
+            if (key.getCardinality() > 0)
+            {
+                key = key.get(0);
+            }
+            
+            getRawText(key);
+
+            return true;
+        } catch (Exception ex) {
+            return false;
+        }
+    }
+
     /* (non-Javadoc)
      * @see org.crosswire.jsword.book.BookMetaData#getUnlockKey()
      */




More information about the jsword-svn mailing list