reSIProcate/rutil  9694
SHA1Stream.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_SHA1STREAM_HXX)
00002 #define RESIP_SHA1STREAM_HXX 
00003 
00004 #if defined(HAVE_CONFIG_H)
00005   #include "config.h"
00006 #endif
00007 
00008 #include <iostream>
00009 #include <memory>
00010 #include <vector>
00011 #include "rutil/Data.hxx"
00012 
00013 // This will not be compiled or installed if USE_SSL isn't set. If you are 
00014 // including this file from a source tree, and you are getting link errors, you 
00015 // are probably trying to link against libs that were built without SSL support. 
00016 // Either stop trying to use this file, or re-build the libs with ssl support 
00017 // enabled.
00018 //#if defined (USE_SSL)
00019 //# include "openssl/sha.h"
00020 //#else
00024 //typedef int SHA_CTX;
00025 //#endif // USE_SSL
00026 
00027 # include "openssl/sha.h"
00028 
00029 namespace resip
00030 {
00031 
00035 class SHA1Buffer : public std::streambuf
00036 {
00037    public:
00038       SHA1Buffer();
00039       virtual ~SHA1Buffer();
00042       Data getHex();
00048       Data getBin(unsigned int bits);
00049 
00050    protected:
00051       virtual int sync();
00052       virtual int overflow(int c = -1);
00053    private:
00054       // !kh!
00055       // used pointers to keep the same object layout.
00056       // this adds overhead, two additional new/delete.
00057       // could get rid of the overhead if, sizeof(SHA_CTX) and SHA_DIGEST_LENGTH are known and FIXED.
00058       // could use pimpl to get rid of one new/delete pair.
00059       std::auto_ptr<SHA_CTX> mContext;
00060       std::vector<char> mBuf;
00061       bool mBlown;
00062 };
00063 
00068 class SHA1Stream : private SHA1Buffer, public std::ostream
00069 {
00070    public:
00071       SHA1Stream();
00072       ~SHA1Stream();
00076       Data getHex();
00082       Data getBin(unsigned int bits=160);
00083 
00085       UInt32 getUInt32();
00086       
00087 };
00088 
00089 }
00090 
00091 #endif
00092 /* ====================================================================
00093  * The Vovida Software License, Version 1.0 
00094  * 
00095  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00096  * 
00097  * Redistribution and use in source and binary forms, with or without
00098  * modification, are permitted provided that the following conditions
00099  * are met:
00100  * 
00101  * 1. Redistributions of source code must retain the above copyright
00102  *    notice, this list of conditions and the following disclaimer.
00103  * 
00104  * 2. Redistributions in binary form must reproduce the above copyright
00105  *    notice, this list of conditions and the following disclaimer in
00106  *    the documentation and/or other materials provided with the
00107  *    distribution.
00108  * 
00109  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00110  *    and "Vovida Open Communication Application Library (VOCAL)" must
00111  *    not be used to endorse or promote products derived from this
00112  *    software without prior written permission. For written
00113  *    permission, please contact vocal@vovida.org.
00114  *
00115  * 4. Products derived from this software may not be called "VOCAL", nor
00116  *    may "VOCAL" appear in their name, without prior written
00117  *    permission of Vovida Networks, Inc.
00118  * 
00119  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00120  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00121  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00122  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00123  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00124  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00125  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00126  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00127  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00128  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00129  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00130  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00131  * DAMAGE.
00132  * 
00133  * ====================================================================
00134  * 
00135  * This software consists of voluntary contributions made by Vovida
00136  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00137  * Inc.  For more information on Vovida Networks, Inc., please see
00138  * <http://www.vovida.org/>.
00139  *
00140  */