reSIProcate/rutil  9694
testDigestStream.cxx
Go to the documentation of this file.
00001 #include "rutil/Data.hxx"
00002 #include "rutil/DigestStream.hxx"
00003 #include "rutil/Log.hxx"
00004 #include "assert.h"
00005 
00006 #include <openssl/evp.h>
00007 
00008 
00009 using namespace resip;
00010 using namespace std;
00011 
00012 
00013 int
00014 main()
00015 {
00016    {
00017       DigestStream str(EVP_sha1());
00018       assert(str.getHex() == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
00019    }
00020 
00021    {
00022       Data input("sip:alice@atlanta.example.com"
00023                  ":a84b4c76e66710"
00024                  ":314159 INVITE"
00025                  ":Thu, 21 Feb 2002 13:02:03 GMT"
00026                  ":sip:alice@pc33.atlanta.example.com"
00027                  ":v=0\r\n"
00028                  "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
00029                  "s=Session SDP\r\n"
00030                  "c=IN IP4 pc33.atlanta.example.com\r\n"
00031                  "t=0 0\r\n"
00032                  "m=audio 49172 RTP/AVP 0\r\n"
00033                  "a=rtpmap:0 PCMU/8000\r\n");
00034       {
00035          
00036          DigestStream str(EVP_sha1());
00037          str << input;
00038 
00039          assert(str.getHex() == "f2eec616bd43c75fd1cd300691e57301b52b3ad3");
00040       }
00041 //       {
00042 //          DigestStream str(EVP_sha1());
00043 //          str << input;
00044 //          assert(str.getBin(32).size() == 4);
00045 //       }
00046       {
00047          DigestStream str(EVP_sha1());
00048          str << input;
00049          assert(str.getBin().size() == 20);
00050       }
00051 //       {
00052 //          DigestStream str(EVP_sha1());
00053 //          str << input;
00054 //          assert(str.getBin(128).size() == 16);
00055 //       }
00056 
00057       Data a;
00058       Data b;
00059 //       {
00060 //          DigestStream str(EVP_sha1());
00061 //          str << input;
00062 //          a = str.getBin(32);
00063 //          cerr << "A: " << a.hex() << endl;
00064 //       }
00065 //       {
00066 //          DigestStream str(EVP_sha1());
00067 //          str << input;
00068 //          b = str.getBin(128);
00069 //          cerr << "B: " << b.hex() << endl;
00070 //       }
00071       
00072 //      assert(memcmp(a.c_str(), b.c_str()+12, 4) == 0);
00073    }
00074 
00075 
00076    cerr << "All OK" << endl;
00077 
00078    return 0;
00079 }
00080 /* ====================================================================
00081  * The Vovida Software License, Version 1.0 
00082  * 
00083  * Copyright (c) 2005 Vovida Networks, Inc.  All rights reserved.
00084  * 
00085  * Redistribution and use in source and binary forms, with or without
00086  * modification, are permitted provided that the following conditions
00087  * are met:
00088  * 
00089  * 1. Redistributions of source code must retain the above copyright
00090  *    notice, this list of conditions and the following disclaimer.
00091  * 
00092  * 2. Redistributions in binary form must reproduce the above copyright
00093  *    notice, this list of conditions and the following disclaimer in
00094  *    the documentation and/or other materials provided with the
00095  *    distribution.
00096  * 
00097  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00098  *    and "Vovida Open Communication Application Library (VOCAL)" must
00099  *    not be used to endorse or promote products derived from this
00100  *    software without prior written permission. For written
00101  *    permission, please contact vocal@vovida.org.
00102  *
00103  * 4. Products derived from this software may not be called "VOCAL", nor
00104  *    may "VOCAL" appear in their name, without prior written
00105  *    permission of Vovida Networks, Inc.
00106  * 
00107  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00108  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00109  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00110  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00111  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00112  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00113  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00114  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00115  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00116  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00117  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00118  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00119  * DAMAGE.
00120  * 
00121  * ====================================================================
00122  * 
00123  * This software consists of voluntary contributions made by Vovida
00124  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00125  * Inc.  For more information on Vovida Networks, Inc., please see
00126  * <http://www.vovida.org/>.
00127  *
00128  */