From depot-cvs-return-5-apmail-incubator-depot-cvs-archive=incubator.apache.org@incubator.apache.org Fri Jan 23 21:11:13 2004 Return-Path: Delivered-To: apmail-incubator-depot-cvs-archive@www.apache.org Received: (qmail 27772 invoked from network); 23 Jan 2004 21:11:13 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 23 Jan 2004 21:11:13 -0000 Received: (qmail 95232 invoked by uid 500); 23 Jan 2004 21:11:02 -0000 Delivered-To: apmail-incubator-depot-cvs-archive@incubator.apache.org Received: (qmail 95218 invoked by uid 500); 23 Jan 2004 21:11:02 -0000 Mailing-List: contact depot-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: depot-dev@incubator.apache.org Delivered-To: mailing list depot-cvs@incubator.apache.org Received: (qmail 95205 invoked from network); 23 Jan 2004 21:11:01 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 23 Jan 2004 21:11:01 -0000 Received: (qmail 27767 invoked by uid 65534); 23 Jan 2004 21:11:12 -0000 Date: 23 Jan 2004 21:11:12 -0000 Message-ID: <20040123211112.27765.qmail@minotaur.apache.org> From: mmay@apache.org To: depot-cvs@incubator.apache.org Subject: svn commit: rev 6252 - in incubator/depot/trunk/ruper/whiteboard: . mmay X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 + * . + * + * ==================================================================== + */ +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.

+ * + * 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 Jason van Zyl + * @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 + * . + * + * ==================================================================== + */ +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.

+ * + * 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 Jason van Zyl + * @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 @@ + + + +

+ MD5 Utilities for Apache Ruper (of Depot) +
+ +
+ MD5 Utilities +

+ 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. +

+
+ +
Use-Cases +

+ Here are some Use-Cases which have to be handled by the utility classes. +

+ Read Hash from .md5-file + + + + Generate Hash from original-file + + + + Compare Hashs + + + + Write own .md5-files? + + + + + + +