/[resiprocate]/main/rutil/test/testDigestStream.cxx
ViewVC logotype

Contents of /main/rutil/test/testDigestStream.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8554 - (show annotations) (download)
Tue Aug 25 00:04:50 2009 UTC (10 years, 2 months ago) by derek
File size: 4291 byte(s)
only tests stolen from SHA1Stream so far

1 #include "rutil/Data.hxx"
2 #include "rutil/DigestStream.hxx"
3 #include "rutil/Log.hxx"
4 #include "assert.h"
5
6 #include <openssl/evp.h>
7
8
9 using namespace resip;
10 using namespace std;
11
12
13 int
14 main()
15 {
16 {
17 DigestStream str(EVP_sha1());
18 assert(str.getHex() == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
19 }
20
21 {
22 Data input("sip:alice@atlanta.example.com"
23 ":a84b4c76e66710"
24 ":314159 INVITE"
25 ":Thu, 21 Feb 2002 13:02:03 GMT"
26 ":sip:alice@pc33.atlanta.example.com"
27 ":v=0\r\n"
28 "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
29 "s=Session SDP\r\n"
30 "c=IN IP4 pc33.atlanta.example.com\r\n"
31 "t=0 0\r\n"
32 "m=audio 49172 RTP/AVP 0\r\n"
33 "a=rtpmap:0 PCMU/8000\r\n");
34 {
35
36 DigestStream str(EVP_sha1());
37 str << input;
38
39 assert(str.getHex() == "f2eec616bd43c75fd1cd300691e57301b52b3ad3");
40 }
41 // {
42 // DigestStream str(EVP_sha1());
43 // str << input;
44 // assert(str.getBin(32).size() == 4);
45 // }
46 {
47 DigestStream str(EVP_sha1());
48 str << input;
49 assert(str.getBin().size() == 20);
50 }
51 // {
52 // DigestStream str(EVP_sha1());
53 // str << input;
54 // assert(str.getBin(128).size() == 16);
55 // }
56
57 Data a;
58 Data b;
59 // {
60 // DigestStream str(EVP_sha1());
61 // str << input;
62 // a = str.getBin(32);
63 // cerr << "A: " << a.hex() << endl;
64 // }
65 // {
66 // DigestStream str(EVP_sha1());
67 // str << input;
68 // b = str.getBin(128);
69 // cerr << "B: " << b.hex() << endl;
70 // }
71
72 // assert(memcmp(a.c_str(), b.c_str()+12, 4) == 0);
73 }
74
75
76 cerr << "All OK" << endl;
77
78 return 0;
79 }
80 /* ====================================================================
81 * The Vovida Software License, Version 1.0
82 *
83 * Copyright (c) 2005 Vovida Networks, Inc. All rights reserved.
84 *
85 * Redistribution and use in source and binary forms, with or without
86 * modification, are permitted provided that the following conditions
87 * are met:
88 *
89 * 1. Redistributions of source code must retain the above copyright
90 * notice, this list of conditions and the following disclaimer.
91 *
92 * 2. Redistributions in binary form must reproduce the above copyright
93 * notice, this list of conditions and the following disclaimer in
94 * the documentation and/or other materials provided with the
95 * distribution.
96 *
97 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
98 * and "Vovida Open Communication Application Library (VOCAL)" must
99 * not be used to endorse or promote products derived from this
100 * software without prior written permission. For written
101 * permission, please contact vocal@vovida.org.
102 *
103 * 4. Products derived from this software may not be called "VOCAL", nor
104 * may "VOCAL" appear in their name, without prior written
105 * permission of Vovida Networks, Inc.
106 *
107 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
108 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
109 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
110 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
111 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
112 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
113 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
114 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
115 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
116 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
117 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
118 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
119 * DAMAGE.
120 *
121 * ====================================================================
122 *
123 * This software consists of voluntary contributions made by Vovida
124 * Networks, Inc. and many individuals on behalf of Vovida Networks,
125 * Inc. For more information on Vovida Networks, Inc., please see
126 * <http://www.vovida.org/>.
127 *
128 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27