incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: rev 6252 - in incubator/depot/trunk/ruper/whiteboard: . mmay
Date Fri, 23 Jan 2004 21:11:12 GMT
Author: mmay
Date: Fri Jan 23 13:11:12 2004
New Revision: 6252

Added:
   incubator/depot/trunk/ruper/whiteboard/
   incubator/depot/trunk/ruper/whiteboard/mmay/
   incubator/depot/trunk/ruper/whiteboard/mmay/HashHelper.java
   incubator/depot/trunk/ruper/whiteboard/mmay/MD5Manager.java
   incubator/depot/trunk/ruper/whiteboard/mmay/md5Utility.xml
Log:
1) Creation of the whiteboard Sub-Folder for new ideas in Ruper
2) Added some first ideas concerning MD5 to the Repository

Added: incubator/depot/trunk/ruper/whiteboard/mmay/HashHelper.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/ruper/whiteboard/mmay/HashHelper.java	Fri Jan 23 13:11:12 2004
@@ -0,0 +1,136 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ *    "Apache Maven" must not be used to endorse or promote products
+ *    derived from this software without prior written permission. For
+ *    written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    "Apache Maven", nor may "Apache" appear in their name, without
+ *    prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * ====================================================================
+ */
+package org.apache.ruper.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.security.MessageDigest;
+
+/**
+ * Encode an MD5 digest into a String. <p>
+ *
+ * The 128 bit MD5 hash is converted into a 32 character long String. Each
+ * character of the String is the hexadecimal representation of 4 bits of the
+ * digest.
+ *
+ * XXX The API here is a mess.  It is combining a static utility class with a
+ *     message digest API. Some methods which should be static are not, presumably
+ *     so Jelly can easily access them.
+ *
+ * @author Remy Maucherat
+ * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
+ * @version $Revision: 1.11 $ $Date: 2003/08/28 23:32:44 $
+ */
+public class HashHelper {
+    /** Hex digits. */
+    private static final char[] HEX_CODES =  {
+            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+            'a', 'b', 'c', 'd', 'e', 'f'
+    };
+
+    /**
+     * Encodes the 128 bit (16 bytes) MD5 into a 32 character String.
+     *
+     * @param binaryData Array containing the digest
+     *
+     * @return Encoded MD5, or null if encoding failed
+     */
+    public static String encode(byte[] binaryData)
+    {
+
+        if ( binaryData.length != 16 ) {
+            return null;
+        }
+
+        char[] buffer = new char[32];
+
+        for ( int i = 0; i < 16; i++ ) {
+            int low = ( binaryData[i] & 0x0f );
+            int high = ( ( binaryData[i] & 0xf0 ) >> 4 );
+            buffer[i * 2] = HashHelper.HEX_CODES[high];
+            buffer[i * 2 + 1] = HashHelper.HEX_CODES[low];
+        }
+
+        return new String( buffer );
+    }
+
+    /** Pull in static content and store it
+     *
+     *  @param file The file to read.
+     *
+     *  @return The bytes of the file.
+     *
+     *  @throws Exception If an error occurs reading in the file's bytes.
+     */
+    public static byte[] getBytes(File file)
+        throws Exception
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        InputStream stream = new FileInputStream( file );
+
+        byte buf[] = new byte[1024];
+        int len = 0;
+
+        while ( ( len = stream.read( buf, 0, 1024 ) ) != -1 )
+        {
+            baos.write( buf, 0, len );
+        }
+
+        return baos.toByteArray();
+    }
+}

Added: incubator/depot/trunk/ruper/whiteboard/mmay/MD5Manager.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/ruper/whiteboard/mmay/MD5Manager.java	Fri Jan 23 13:11:12 2004
@@ -0,0 +1,108 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ *    "Apache Maven" must not be used to endorse or promote products
+ *    derived from this software without prior written permission. For
+ *    written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    "Apache Maven", nor may "Apache" appear in their name, without
+ *    prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * ====================================================================
+ */
+package org.apache.ruper.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.security.MessageDigest;
+
+/**
+ * Encode an MD5 digest into a String. <p>
+ *
+ * The 128 bit MD5 hash is converted into a 32 character long String. Each
+ * character of the String is the hexadecimal representation of 4 bits of the
+ * digest.
+ *
+ * XXX The API here is a mess.  It is combining a static utility class with a
+ *     message digest API. Some methods which should be static are not, presumably
+ *     so Jelly can easily access them.
+ *
+ * @author Remy Maucherat
+ * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
+ * @version $Revision: 1.11 $ $Date: 2003/08/28 23:32:44 $
+ */
+public class MD5Manager {
+
+	private MD5Manager() {
+	}
+
+    /**
+     * Perform the MD5-Sum work.
+     *
+     * @throws Exception If an error occurs while calculating the sum.
+     */
+    public static byte[] generateHash(File file)
+        throws Exception
+    {
+        if ( file.exists() == false ) {
+            System.err.println( "Specified file " + file + " doesn't exist." );
+        }
+
+        MessageDigest md5Helper = MessageDigest.getInstance( "MD5" );
+        byte[] bytes = HashHelper.getBytes(file);
+
+        byte[] digestBytes = md5Helper.digest(bytes);
+
+		return digestBytes;
+    }
+
+    public static byte[] readHashFromFile(File file) {
+
+
+	}
+}

Added: incubator/depot/trunk/ruper/whiteboard/mmay/md5Utility.xml
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/ruper/whiteboard/mmay/md5Utility.xml	Fri Jan 23 13:11:12 2004
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.1//EN" "document-v11.dtd">
+<document> 
+  <header> 
+    <title>MD5 Utilities for Apache Ruper (of Depot)</title> 
+  </header> 
+  <body> 
+    <section>
+      <title>MD5 Utilities</title>
+      <p>
+      	At the Apache.org Servers it is a common procedure to store MD5-Data for published
files to guarantee the integrety of the file. Therefor a Resource Updater like Ruper should
+      	be able to handle such data. 
+      </p>
+    </section>
+    
+    <section><title>Use-Cases</title>
+    	<p>
+    	  Here are some Use-Cases which have to be handled by the utility classes.
+    	</p>
+	<subsection><title>Read Hash from .md5-file</title>
+	
+	</subsection>
+
+	<subsection><title>Generate Hash from original-file</title>
+	
+	</subsection>
+
+	<subsection><title>Compare Hashs</title>
+	
+	</subsection>
+
+	<subsection><title>Write own .md5-files?</title>
+	
+	</subsection>
+
+
+    <source>
+  </body>
+</document>

Mime
View raw message