Commits

dloy committed ee27421

Add padding to CRC-32

  • Participants
  • Parent commits c4a70ad

Comments (0)

Files changed (6)

core/src/main/java/org/cdlib/mrt/utility/MessageDigestValue.java

             }
             long checksumL = checksum32.getValue();
             checksum = Long.toHexString(checksumL);
-
+            checksum = StringUtil.leftPad(checksum, 8, '0');
             if (logger.getMessageMaxLevel() >= 10) {
                 String msg = MESSAGE + "fileLen=" + inputSize
                         + " - " + checksumType + "=" + checksum;

core/src/main/java/org/cdlib/mrt/utility/StringUtil.java

         else in = in.trim();
         return in;
     }
+
+    public static String leftPad(String in, int size, char padc)
+    {
+        if (in == null) return in;
+        int padLen = size - in.length();
+        if (padLen <= 0) return in;
+        StringBuffer buf = new StringBuffer();
+        for (int i=0; i < padLen; i++) {
+            buf.append(padc);
+        }
+        return buf.toString() + in;
+    }
 }

core/src/test/java/org/cdlib/mrt/security/InstallCertTest.java

 
     //protected final static String HOSTS = "badger.cdlib.org:1636";
     //protected final static String HOSTS = "dp01.cdlib.org:1636";
-    protected final static String HOSTS = "coot.ucop.edu:1636";
+    //protected final static String HOSTS = "coot.ucop.edu:1636";
+    protected final static String HOSTS = "ferret.cdlib.org:1636";
+    //protected final static String HOSTS = "dp08.cdlib.org:1636";
     //protected final static String HOSTS = "merritt.cdlib.org:1636";
     public InstallCertTest() {
     }
     public void tearDown() {
     }
 
-    @Test
+    //@Test
     public void Dummy()
         throws TException
     {
         assertTrue(true);
     }
 
-    //@Test
+    @Test
     public void Test()
         throws TException
     {

core/src/test/java/org/cdlib/mrt/security/LDAPUtilTest.java

     protected final static String NL = System.getProperty("line.separator");
     protected final static String UID = "dloy";
     protected final static String PW = "Huz8dloy";
-    protected final static String HOSTS = "ldaps://coot.ucop.edu:1636";
+    //protected final static String HOSTS = "ldaps://coot.ucop.edu:1636";
+    //protected final static String HOSTS = "ldaps://dp08.cdlib.org:1636";
+    protected final static String HOSTS = "ldaps://ferret.cdlib.org:1636";
+    //protected final static String HOSTS = "ldaps://coot.ucop.edu:1636";
     //protected final static String HOSTS = "ldaps://badger.cdlib.org:1636";
     protected final static String HOST = "ldap://badger.cdlib.org:1389";
 
         }
     }
 
-    //@Test
+    @Test
     public void TestAuthorize()
         throws TException
     {

core/src/test/java/org/cdlib/mrt/utility/MessageDigestValue2Test.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.cdlib.mrt.utility;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author dloy
+ */
+public class MessageDigestValue2Test {
+
+    public MessageDigestValue2Test() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+
+    @Before
+    public void setUp() {
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    @Test
+    public void dummyTest()
+    {
+        assertTrue(true);
+    }
+    
+    //@Test
+    public void TestPadCRC()
+    {
+        try {
+            File test = new File("C:/Documents and Settings/dloy/My Documents/Bugs/Storage/ucsd/1-1.pdf");
+            InputStream stream = new FileInputStream(test);
+       
+            doFixity(stream,
+                    "crc-32",
+                    "0a253086",
+                    1265228);
+        } catch (Exception ex) {
+            assertFalse("TestPadCRC"
+                    + " - Exception:" + ex
+                    + " - stack:" + StringUtil.stackTrace(ex)
+                    , true);
+        }
+    }
+
+
+    public void doFixity(InputStream inStream, String processChecksum, String match, int matchSize)
+    {
+        try {
+            LoggerInf logger = new TFileLogger("MessageDigestValueTest", 10, 10);
+            assertTrue(inStream != null);
+            MessageDigestValue fixityTest = new MessageDigestValue(inStream, processChecksum, logger );
+            long size = fixityTest.getInputSize();
+            String checksum = fixityTest.getChecksum();
+            MessageDigestType checksumType = fixityTest.getChecksumType();
+            assertTrue("TestIt"
+                    + " - size=" + size
+                    + " - checksum=" + checksum,
+                    size==matchSize
+                            && checksum.equals(match)
+                    );
+
+        } catch (Exception ex) {
+            assertFalse("TestTmp"
+                    + " - Exception:" + ex
+                    + " - stack:" + StringUtil.stackTrace(ex)
+                    , true);
+        }
+    }
+
+
+}

core/src/test/java/org/cdlib/mrt/utility/StringUtilTest.java

         }
 
     }
+    @Test
+    public void testLeftPad()
+    {
+        String tPad = null;
+        try {
+            testLeftPad("aaa", 5, '0', "00aaa");
+            testLeftPad("aaa", 5, 'q', "qqaaa");
+            testLeftPad("bbbbb", 5, '0', "bbbbb");
+            testLeftPad("bbbbbb", 5, '0', "bbbbbb");
+            testLeftPad("", 5, '0', "00000");
+            testLeftPad("ccc", 0, '0', "ccc");
+            testLeftPad("", -5, '0', "");
+            testLeftPad(null, 5, '0', null);
+
+        } catch (Exception ex) {
+            System.out.println(MESSAGE + "Exception:" + ex);
+            assertFalse(MESSAGE
+                    + " - Exception:" + ex
+                    + " - stack:" + StringUtil.stackTrace(ex)
+                    , true);
+        }
+
+    }
+
+    protected void testLeftPad(String in, int size, char padc, String match)
+    {
+        String pad = StringUtil.leftPad(in, size, padc);
+        if (in == null) assertTrue(pad == null);
+        else assertTrue(pad.equals(match));
+    }
 }