FileDocCategorySizeDatePackage
SSLWrapper.javaAPI DocphoneME MR2 API (J2ME)2238Wed May 02 18:00:32 BST 2007com.sun.kvem.jsr082.obex

SSLWrapper.java

/*
 *
 *
 * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 only, as published by the Free Software Foundation.
 * 
 * This program 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 version 2 for more details (a copy is
 * included at /legal/license.txt).
 * 
 * You should have received a copy of the GNU General Public License
 * version 2 along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 * 
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 or visit www.sun.com if you need additional
 * information or have any questions.
 */
package com.sun.kvem.jsr082.obex;

// J2ME security classes
import com.sun.midp.crypto.MessageDigest;
import com.sun.midp.crypto.GeneralSecurityException;
import com.sun.midp.crypto.DigestException;

// cldc API classes
import java.io.IOException;

/**
 * The platform dependent class which provides a wrapper for
 * security API in J2ME or J2SE.
 */
final class SSLWrapper {
    private MessageDigest md5;

    SSLWrapper() throws IOException {
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (GeneralSecurityException e) {
            throw new IOException(e.getMessage());
        }
    }

    void update(byte[] input, int offset, int length) {
        md5.update(input, offset, length);
    }

    void doFinal(byte[] srcData, int srcOff, int srcLen, byte[] dstData,
            int dstOff) {

        if (srcLen != 0) {
            md5.update(srcData, srcOff, srcLen);
        }

        try {
            md5.digest(dstData, dstOff, dstData.length - dstOff);
        } catch (DigestException e) {
            // Buffer too short
            throw new RuntimeException("output buffer too short");
        }
    }
} // end of class 'SSLWrapper' definition