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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10893 - (show annotations) (download)
Mon Jan 20 22:37:30 2014 UTC (5 years, 9 months ago) by sgodin
File MIME type: text/plain
File size: 2979 byte(s)
-add new SHA1 class to builds
-added new API on SHA1 class to support retrieving of binary SHA1 hash
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <assert.h>
6
7 #include "rutil/Sha1.hxx"
8
9 #ifdef USE_SSL
10 #include "rutil/ssl/SHA1Stream.hxx"
11 #endif
12
13 using namespace resip;
14 using namespace std;
15
16 int
17 main(void)
18 {
19 // Test Sha1 class that does not use OpenSSL first
20 {
21 resip::SHA1 sha1test;
22 sha1test.update("");
23 assert(sha1test.final() == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
24 }
25 {
26 resip::SHA1 sha1test;
27 sha1test.update("");
28 Data result = sha1test.finalBin();
29 assert(result.hex() == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
30 }
31 {
32 Data input("sip:alice@atlanta.example.com"
33 ":a84b4c76e66710"
34 ":314159 INVITE"
35 ":Thu, 21 Feb 2002 13:02:03 GMT"
36 ":sip:alice@pc33.atlanta.example.com"
37 ":v=0\r\n"
38 "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
39 "s=Session SDP\r\n"
40 "c=IN IP4 pc33.atlanta.example.com\r\n"
41 "t=0 0\r\n"
42 "m=audio 49172 RTP/AVP 0\r\n"
43 "a=rtpmap:0 PCMU/8000\r\n");
44 {
45
46 resip::SHA1 sha1test;
47 sha1test.update(input.c_str());
48
49 assert(sha1test.final() == "f2eec616bd43c75fd1cd300691e57301b52b3ad3");
50 }
51 }
52
53 #ifdef USE_SSL
54 // Test Sha1Stream class that uses OpenSSL
55 {
56 SHA1Stream str;
57 assert(str.getHex() == "da39a3ee5e6b4b0d3255bfef95601890afd80709");
58 }
59
60 {
61 Data input("sip:alice@atlanta.example.com"
62 ":a84b4c76e66710"
63 ":314159 INVITE"
64 ":Thu, 21 Feb 2002 13:02:03 GMT"
65 ":sip:alice@pc33.atlanta.example.com"
66 ":v=0\r\n"
67 "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
68 "s=Session SDP\r\n"
69 "c=IN IP4 pc33.atlanta.example.com\r\n"
70 "t=0 0\r\n"
71 "m=audio 49172 RTP/AVP 0\r\n"
72 "a=rtpmap:0 PCMU/8000\r\n");
73 {
74
75 SHA1Stream str;
76 str << input;
77
78 assert(str.getHex() == "f2eec616bd43c75fd1cd300691e57301b52b3ad3");
79 }
80 {
81 SHA1Stream str;
82 str << input;
83 assert(str.getBin(32).size() == 4);
84 }
85 {
86 SHA1Stream str;
87 str << input;
88 assert(str.getBin().size() == 20);
89 }
90 {
91 SHA1Stream str;
92 str << input;
93 assert(str.getBin(128).size() == 16);
94 }
95
96 Data a;
97 Data b;
98 {
99 SHA1Stream str;
100 str << input;
101 a = str.getBin(32);
102 cerr << "A: " << a.hex() << endl;
103 }
104 {
105 SHA1Stream str;
106 str << input;
107 b = str.getBin(128);
108 cerr << "B: " << b.hex() << endl;
109 }
110
111 assert(memcmp(a.c_str(), b.c_str()+12, 4) == 0);
112 }
113
114
115 cerr << "All OK" << endl;
116 #endif
117
118 return 0;
119 }

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27