reSIProcate/rutil  9694
MD5Stream.cxx
Go to the documentation of this file.
00001 #include "rutil/MD5Stream.hxx"
00002 
00003 // Remove warning about 'this' use in initiator list - pointer is only stored
00004 #if defined(WIN32) && !defined(__GNUC__)
00005 #pragma warning( disable : 4355 ) // using this in base member initializer list 
00006 #endif
00007 
00008 using namespace resip;
00009 
00010 MD5Buffer::MD5Buffer()
00011 {
00012    MD5Init(&mContext);
00013    setp(mBuf, mBuf + sizeof(mBuf));
00014 }
00015 
00016 MD5Buffer::~MD5Buffer()
00017 {
00018 }
00019 
00020 int
00021 MD5Buffer::sync()
00022 {
00023    size_t len = pptr() - pbase();
00024    if (len > 0) 
00025    {
00026       MD5Update(&mContext, reinterpret_cast <unsigned const char*>(pbase()), (unsigned int)len);
00027       // reset the put buffer
00028       setp(mBuf, mBuf + sizeof(mBuf));
00029    }
00030    return 0;
00031 }
00032 
00033 int
00034 MD5Buffer::overflow(int c)
00035 {
00036    sync();
00037    if (c != -1) 
00038    {
00039       mBuf[0] = c;
00040       pbump(1);
00041       return c;
00042    }
00043    return 0;
00044 }
00045 
00046 Data 
00047 MD5Buffer::getHex()
00048 {
00049    MD5Context tmp = mContext;
00050    MD5Final((unsigned char*)mBuf, &tmp);
00051    Data digest(Data::Share, (const char*)mBuf,16);
00052    return digest.hex();   
00053 }
00054 
00055 Data
00056 MD5Buffer::getBin()
00057 {
00058    MD5Context tmp = mContext;
00059    MD5Final((unsigned char*)mBuf, &tmp);
00060    Data digest(Data::Share, (const char*)mBuf,16);
00061    return digest;
00062 }
00063 
00064 MD5Stream::MD5Stream()
00065    : std::ostream(this)
00066 {
00067 }
00068 
00069 MD5Stream::~MD5Stream()
00070 {}
00071 
00072 Data 
00073 MD5Stream::getHex()
00074 {
00075    flush();
00076    return MD5Buffer::getHex();
00077    //return mStreambuf.getHex();
00078 }
00079 
00080 Data
00081 MD5Stream::getBin()
00082 {
00083    flush();
00084    return MD5Buffer::getBin();
00085 }
00086 
00087 /* ====================================================================
00088  * The Vovida Software License, Version 1.0 
00089  * 
00090  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00091  * 
00092  * Redistribution and use in source and binary forms, with or without
00093  * modification, are permitted provided that the following conditions
00094  * are met:
00095  * 
00096  * 1. Redistributions of source code must retain the above copyright
00097  *    notice, this list of conditions and the following disclaimer.
00098  * 
00099  * 2. Redistributions in binary form must reproduce the above copyright
00100  *    notice, this list of conditions and the following disclaimer in
00101  *    the documentation and/or other materials provided with the
00102  *    distribution.
00103  * 
00104  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00105  *    and "Vovida Open Communication Application Library (VOCAL)" must
00106  *    not be used to endorse or promote products derived from this
00107  *    software without prior written permission. For written
00108  *    permission, please contact vocal@vovida.org.
00109  *
00110  * 4. Products derived from this software may not be called "VOCAL", nor
00111  *    may "VOCAL" appear in their name, without prior written
00112  *    permission of Vovida Networks, Inc.
00113  * 
00114  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00115  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00116  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00117  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00118  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00119  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00120  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00121  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00122  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00123  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00124  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00125  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00126  * DAMAGE.
00127  * 
00128  * ====================================================================
00129  * 
00130  * This software consists of voluntary contributions made by Vovida
00131  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00132  * Inc.  For more information on Vovida Networks, Inc., please see
00133  * <http://www.vovida.org/>.
00134  *
00135  */