summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2007-11-21 14:01:36 (UTC)
committer Michael Krelin <hacker@klever.net>2007-11-21 14:01:36 (UTC)
commit8e397698d6a224e36f2b4a188380ec04400aac66 (patch) (unidiff)
treeda7aa7d75f6dd74b8d7260b7ab9c39241726ca88
parent10916ef2b15b91badb17af5404acd9981b8a2087 (diff)
downloadlibopkele-8e397698d6a224e36f2b4a188380ec04400aac66.zip
libopkele-8e397698d6a224e36f2b4a188380ec04400aac66.tar.gz
libopkele-8e397698d6a224e36f2b4a188380ec04400aac66.tar.bz2
added some missing includes for gcc 4.3
According to Marcus Rueckert gcc 4.3 wants these. Thanks, Marcus! Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/consumer.cc1
-rw-r--r--lib/server.cc1
-rw-r--r--lib/util.cc1
3 files changed, 3 insertions, 0 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc
index f9212ea..d578546 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -1,98 +1,99 @@
1#include <algorithm> 1#include <algorithm>
2#include <cassert> 2#include <cassert>
3#include <cstring>
3#include <opkele/util.h> 4#include <opkele/util.h>
4#include <opkele/exception.h> 5#include <opkele/exception.h>
5#include <opkele/data.h> 6#include <opkele/data.h>
6#include <opkele/consumer.h> 7#include <opkele/consumer.h>
7#include <openssl/sha.h> 8#include <openssl/sha.h>
8#include <openssl/hmac.h> 9#include <openssl/hmac.h>
9#include <curl/curl.h> 10#include <curl/curl.h>
10 11
11#include <iostream> 12#include <iostream>
12 13
13#include "config.h" 14#include "config.h"
14 15
15#include <pcre.h> 16#include <pcre.h>
16 17
17namespace opkele { 18namespace opkele {
18 using namespace std; 19 using namespace std;
19 20
20 class pcre_matches_t { 21 class pcre_matches_t {
21 public: 22 public:
22 int *_ov; 23 int *_ov;
23 int _s; 24 int _s;
24 25
25 pcre_matches_t() : _ov(0), _s(0) { } 26 pcre_matches_t() : _ov(0), _s(0) { }
26 pcre_matches_t(int s) : _ov(0), _s(s) { 27 pcre_matches_t(int s) : _ov(0), _s(s) {
27 if(_s&1) ++_s; 28 if(_s&1) ++_s;
28 _s += _s>>1; 29 _s += _s>>1;
29 _ov = new int[_s]; 30 _ov = new int[_s];
30 } 31 }
31 ~pcre_matches_t() throw() { if(_ov) delete[] _ov; } 32 ~pcre_matches_t() throw() { if(_ov) delete[] _ov; }
32 33
33 int begin(int i) const { return _ov[i<<1]; } 34 int begin(int i) const { return _ov[i<<1]; }
34 int end(int i) const { return _ov[(i<<1)+1]; } 35 int end(int i) const { return _ov[(i<<1)+1]; }
35 int length(int i) const { int t=i<<1; return _ov[t+1]-_ov[t]; } 36 int length(int i) const { int t=i<<1; return _ov[t+1]-_ov[t]; }
36 }; 37 };
37 38
38 class pcre_t { 39 class pcre_t {
39 public: 40 public:
40 pcre *_p; 41 pcre *_p;
41 42
42 pcre_t() : _p(0) { } 43 pcre_t() : _p(0) { }
43 pcre_t(pcre *p) : _p(p) { } 44 pcre_t(pcre *p) : _p(p) { }
44 pcre_t(const char *re,int opts) : _p(0) { 45 pcre_t(const char *re,int opts) : _p(0) {
45 static const char *errptr; static int erroffset; 46 static const char *errptr; static int erroffset;
46 _p = pcre_compile(re,opts,&errptr,&erroffset,NULL); 47 _p = pcre_compile(re,opts,&errptr,&erroffset,NULL);
47 if(!_p) 48 if(!_p)
48 throw internal_error(OPKELE_CP_ string("Failed to compile regexp: ")+errptr); 49 throw internal_error(OPKELE_CP_ string("Failed to compile regexp: ")+errptr);
49 } 50 }
50 ~pcre_t() throw() { if(_p) (*pcre_free)(_p); } 51 ~pcre_t() throw() { if(_p) (*pcre_free)(_p); }
51 52
52 pcre_t& operator=(pcre *p) { if(_p) (*pcre_free)(_p); _p=p; return *this; } 53 pcre_t& operator=(pcre *p) { if(_p) (*pcre_free)(_p); _p=p; return *this; }
53 54
54 operator const pcre*(void) const { return _p; } 55 operator const pcre*(void) const { return _p; }
55 operator pcre*(void) { return _p; } 56 operator pcre*(void) { return _p; }
56 57
57 int exec(const string& s,pcre_matches_t& m) { 58 int exec(const string& s,pcre_matches_t& m) {
58 if(!_p) 59 if(!_p)
59 throw internal_error(OPKELE_CP_ "Trying to execute absent regexp"); 60 throw internal_error(OPKELE_CP_ "Trying to execute absent regexp");
60 return pcre_exec(_p,NULL,s.c_str(),s.length(),0,0,m._ov,m._s); 61 return pcre_exec(_p,NULL,s.c_str(),s.length(),0,0,m._ov,m._s);
61 } 62 }
62 }; 63 };
63 64
64 class curl_t { 65 class curl_t {
65 public: 66 public:
66 CURL *_c; 67 CURL *_c;
67 68
68 curl_t() : _c(0) { } 69 curl_t() : _c(0) { }
69 curl_t(CURL *c) : _c(c) { } 70 curl_t(CURL *c) : _c(c) { }
70 ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); } 71 ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); }
71 72
72 curl_t& operator=(CURL *c) { if(_c) curl_easy_cleanup(_c); _c=c; return *this; } 73 curl_t& operator=(CURL *c) { if(_c) curl_easy_cleanup(_c); _c=c; return *this; }
73 74
74 operator const CURL*(void) const { return _c; } 75 operator const CURL*(void) const { return _c; }
75 operator CURL*(void) { return _c; } 76 operator CURL*(void) { return _c; }
76 }; 77 };
77 78
78 static CURLcode curl_misc_sets(CURL* c) { 79 static CURLcode curl_misc_sets(CURL* c) {
79 CURLcode r; 80 CURLcode r;
80 (r=curl_easy_setopt(c,CURLOPT_FOLLOWLOCATION,1)) 81 (r=curl_easy_setopt(c,CURLOPT_FOLLOWLOCATION,1))
81 || (r=curl_easy_setopt(c,CURLOPT_MAXREDIRS,5)) 82 || (r=curl_easy_setopt(c,CURLOPT_MAXREDIRS,5))
82 || (r=curl_easy_setopt(c,CURLOPT_DNS_CACHE_TIMEOUT,120)) 83 || (r=curl_easy_setopt(c,CURLOPT_DNS_CACHE_TIMEOUT,120))
83 || (r=curl_easy_setopt(c,CURLOPT_DNS_USE_GLOBAL_CACHE,1)) 84 || (r=curl_easy_setopt(c,CURLOPT_DNS_USE_GLOBAL_CACHE,1))
84 || (r=curl_easy_setopt(c,CURLOPT_USERAGENT,PACKAGE_NAME"/"PACKAGE_SRC_VERSION)) 85 || (r=curl_easy_setopt(c,CURLOPT_USERAGENT,PACKAGE_NAME"/"PACKAGE_SRC_VERSION))
85 || (r=curl_easy_setopt(c,CURLOPT_TIMEOUT,20)) 86 || (r=curl_easy_setopt(c,CURLOPT_TIMEOUT,20))
86 #ifdefDISABLE_CURL_SSL_VERIFYHOST 87 #ifdefDISABLE_CURL_SSL_VERIFYHOST
87 || (r=curl_easy_setopt(c,CURLOPT_SSL_VERIFYHOST,0)) 88 || (r=curl_easy_setopt(c,CURLOPT_SSL_VERIFYHOST,0))
88#endif 89#endif
89 #ifdefDISABLE_CURL_SSL_VERIFYPEER 90 #ifdefDISABLE_CURL_SSL_VERIFYPEER
90 || (r=curl_easy_setopt(c,CURLOPT_SSL_VERIFYPEER,0)) 91 || (r=curl_easy_setopt(c,CURLOPT_SSL_VERIFYPEER,0))
91#endif 92#endif
92 ; 93 ;
93 return r; 94 return r;
94 } 95 }
95 96
96 static size_t _curl_tostring(void *ptr,size_t size,size_t nmemb,void *stream) { 97 static size_t _curl_tostring(void *ptr,size_t size,size_t nmemb,void *stream) {
97 string *str = (string*)stream; 98 string *str = (string*)stream;
98 size_t bytes = size*nmemb; 99 size_t bytes = size*nmemb;
diff --git a/lib/server.cc b/lib/server.cc
index b1c5c3a..aa61035 100644
--- a/lib/server.cc
+++ b/lib/server.cc
@@ -1,96 +1,97 @@
1#include <cstring>
1#include <vector> 2#include <vector>
2#include <openssl/sha.h> 3#include <openssl/sha.h>
3#include <openssl/hmac.h> 4#include <openssl/hmac.h>
4#include <opkele/util.h> 5#include <opkele/util.h>
5#include <opkele/exception.h> 6#include <opkele/exception.h>
6#include <opkele/server.h> 7#include <opkele/server.h>
7#include <opkele/data.h> 8#include <opkele/data.h>
8 9
9namespace opkele { 10namespace opkele {
10 using namespace std; 11 using namespace std;
11 12
12 void server_t::associate(const params_t& pin,params_t& pout) { 13 void server_t::associate(const params_t& pin,params_t& pout) {
13 util::dh_t dh; 14 util::dh_t dh;
14 util::bignum_t c_pub; 15 util::bignum_t c_pub;
15 unsigned char key_sha1[SHA_DIGEST_LENGTH]; 16 unsigned char key_sha1[SHA_DIGEST_LENGTH];
16 enum { 17 enum {
17 sess_cleartext, 18 sess_cleartext,
18 sess_dh_sha1 19 sess_dh_sha1
19 } st = sess_cleartext; 20 } st = sess_cleartext;
20 if( 21 if(
21 pin.has_param("openid.session_type") 22 pin.has_param("openid.session_type")
22 && pin.get_param("openid.session_type")=="DH-SHA1" ) { 23 && pin.get_param("openid.session_type")=="DH-SHA1" ) {
23 /* TODO: fallback to cleartext in case of exceptions here? */ 24 /* TODO: fallback to cleartext in case of exceptions here? */
24 if(!(dh = DH_new())) 25 if(!(dh = DH_new()))
25 throw exception_openssl(OPKELE_CP_ "failed to DH_new()"); 26 throw exception_openssl(OPKELE_CP_ "failed to DH_new()");
26 c_pub = util::base64_to_bignum(pin.get_param("openid.dh_consumer_public")); 27 c_pub = util::base64_to_bignum(pin.get_param("openid.dh_consumer_public"));
27 if(pin.has_param("openid.dh_modulus")) 28 if(pin.has_param("openid.dh_modulus"))
28 dh->p = util::base64_to_bignum(pin.get_param("openid.dh_modulus")); 29 dh->p = util::base64_to_bignum(pin.get_param("openid.dh_modulus"));
29 else 30 else
30 dh->p = util::dec_to_bignum(data::_default_p); 31 dh->p = util::dec_to_bignum(data::_default_p);
31 if(pin.has_param("openid.dh_gen")) 32 if(pin.has_param("openid.dh_gen"))
32 dh->g = util::base64_to_bignum(pin.get_param("openid.dh_gen")); 33 dh->g = util::base64_to_bignum(pin.get_param("openid.dh_gen"));
33 else 34 else
34 dh->g = util::dec_to_bignum(data::_default_g); 35 dh->g = util::dec_to_bignum(data::_default_g);
35 if(!DH_generate_key(dh)) 36 if(!DH_generate_key(dh))
36 throw exception_openssl(OPKELE_CP_ "failed to DH_generate_key()"); 37 throw exception_openssl(OPKELE_CP_ "failed to DH_generate_key()");
37 vector<unsigned char> ck(DH_size(dh)+1); 38 vector<unsigned char> ck(DH_size(dh)+1);
38 unsigned char *ckptr = &(ck.front())+1; 39 unsigned char *ckptr = &(ck.front())+1;
39 int cklen = DH_compute_key(ckptr,c_pub,dh); 40 int cklen = DH_compute_key(ckptr,c_pub,dh);
40 if(cklen<0) 41 if(cklen<0)
41 throw exception_openssl(OPKELE_CP_ "failed to DH_compute_key()"); 42 throw exception_openssl(OPKELE_CP_ "failed to DH_compute_key()");
42 if(cklen && (*ckptr)&0x80) { 43 if(cklen && (*ckptr)&0x80) {
43 (*(--ckptr)) = 0; ++cklen; 44 (*(--ckptr)) = 0; ++cklen;
44 } 45 }
45 SHA1(ckptr,cklen,key_sha1); 46 SHA1(ckptr,cklen,key_sha1);
46 st = sess_dh_sha1; 47 st = sess_dh_sha1;
47 } 48 }
48 assoc_t assoc = alloc_assoc(mode_associate); 49 assoc_t assoc = alloc_assoc(mode_associate);
49 time_t now = time(0); 50 time_t now = time(0);
50 pout.clear(); 51 pout.clear();
51 pout["assoc_type"] = assoc->assoc_type(); 52 pout["assoc_type"] = assoc->assoc_type();
52 pout["assoc_handle"] = assoc->handle(); 53 pout["assoc_handle"] = assoc->handle();
53 /* TODO: eventually remove deprecated stuff */ 54 /* TODO: eventually remove deprecated stuff */
54 pout["issued"] = util::time_to_w3c(now); 55 pout["issued"] = util::time_to_w3c(now);
55 pout["expiry"] = util::time_to_w3c(now+assoc->expires_in()); 56 pout["expiry"] = util::time_to_w3c(now+assoc->expires_in());
56 pout["expires_in"] = util::long_to_string(assoc->expires_in()); 57 pout["expires_in"] = util::long_to_string(assoc->expires_in());
57 secret_t secret = assoc->secret(); 58 secret_t secret = assoc->secret();
58 switch(st) { 59 switch(st) {
59 case sess_dh_sha1: 60 case sess_dh_sha1:
60 pout["session_type"] = "DH-SHA1"; 61 pout["session_type"] = "DH-SHA1";
61 pout["dh_server_public"] = util::bignum_to_base64(dh->pub_key); 62 pout["dh_server_public"] = util::bignum_to_base64(dh->pub_key);
62 secret.enxor_to_base64(key_sha1,pout["enc_mac_key"]); 63 secret.enxor_to_base64(key_sha1,pout["enc_mac_key"]);
63 break; 64 break;
64 default: 65 default:
65 secret.to_base64(pout["mac_key"]); 66 secret.to_base64(pout["mac_key"]);
66 break; 67 break;
67 } 68 }
68 } 69 }
69 70
70 void server_t::checkid_immediate(const params_t& pin,string& return_to,params_t& pout,extension_t *ext) { 71 void server_t::checkid_immediate(const params_t& pin,string& return_to,params_t& pout,extension_t *ext) {
71 checkid_(mode_checkid_immediate,pin,return_to,pout,ext); 72 checkid_(mode_checkid_immediate,pin,return_to,pout,ext);
72 } 73 }
73 74
74 void server_t::checkid_setup(const params_t& pin,string& return_to,params_t& pout,extension_t *ext) { 75 void server_t::checkid_setup(const params_t& pin,string& return_to,params_t& pout,extension_t *ext) {
75 checkid_(mode_checkid_setup,pin,return_to,pout,ext); 76 checkid_(mode_checkid_setup,pin,return_to,pout,ext);
76 } 77 }
77 78
78 void server_t::checkid_(mode_t mode,const params_t& pin,string& return_to,params_t& pout,extension_t *ext) { 79 void server_t::checkid_(mode_t mode,const params_t& pin,string& return_to,params_t& pout,extension_t *ext) {
79 if(mode!=mode_checkid_immediate && mode!=mode_checkid_setup) 80 if(mode!=mode_checkid_immediate && mode!=mode_checkid_setup)
80 throw bad_input(OPKELE_CP_ "invalid checkid_* mode"); 81 throw bad_input(OPKELE_CP_ "invalid checkid_* mode");
81 pout.clear(); 82 pout.clear();
82 assoc_t assoc; 83 assoc_t assoc;
83 try { 84 try {
84 assoc = retrieve_assoc(pin.get_param("openid.assoc_handle")); 85 assoc = retrieve_assoc(pin.get_param("openid.assoc_handle"));
85 }catch(failed_lookup& fl) { 86 }catch(failed_lookup& fl) {
86 // no handle specified or no valid handle found, going dumb 87 // no handle specified or no valid handle found, going dumb
87 assoc = alloc_assoc(mode_checkid_setup); 88 assoc = alloc_assoc(mode_checkid_setup);
88 if(pin.has_param("openid.assoc_handle")) 89 if(pin.has_param("openid.assoc_handle"))
89 pout["invalidate_handle"]=pin.get_param("openid.assoc_handle"); 90 pout["invalidate_handle"]=pin.get_param("openid.assoc_handle");
90 } 91 }
91 string trust_root; 92 string trust_root;
92 try { 93 try {
93 trust_root = pin.get_param("openid.trust_root"); 94 trust_root = pin.get_param("openid.trust_root");
94 }catch(failed_lookup& fl) { } 95 }catch(failed_lookup& fl) { }
95 string identity = pin.get_param("openid.identity"); 96 string identity = pin.get_param("openid.identity");
96 return_to = pin.get_param("openid.return_to"); 97 return_to = pin.get_param("openid.return_to");
diff --git a/lib/util.cc b/lib/util.cc
index 94e09ed..26be66a 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -1,98 +1,99 @@
1#include <errno.h> 1#include <errno.h>
2#include <cassert> 2#include <cassert>
3#include <cstring>
3#include <vector> 4#include <vector>
4#include <string> 5#include <string>
5#include <openssl/bio.h> 6#include <openssl/bio.h>
6#include <openssl/evp.h> 7#include <openssl/evp.h>
7#include <curl/curl.h> 8#include <curl/curl.h>
8#include "opkele/util.h" 9#include "opkele/util.h"
9#include "opkele/exception.h" 10#include "opkele/exception.h"
10 11
11namespace opkele { 12namespace opkele {
12 using namespace std; 13 using namespace std;
13 14
14 namespace util { 15 namespace util {
15 16
16 /* 17 /*
17 * base64 18 * base64
18 */ 19 */
19 string encode_base64(const void *data,size_t length) { 20 string encode_base64(const void *data,size_t length) {
20 BIO *b64 = 0, *bmem = 0; 21 BIO *b64 = 0, *bmem = 0;
21 try { 22 try {
22 b64 = BIO_new(BIO_f_base64()); 23 b64 = BIO_new(BIO_f_base64());
23 if(!b64) 24 if(!b64)
24 throw exception_openssl(OPKELE_CP_ "failed to BIO_new() base64 encoder"); 25 throw exception_openssl(OPKELE_CP_ "failed to BIO_new() base64 encoder");
25 BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); 26 BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);
26 bmem = BIO_new(BIO_s_mem()); 27 bmem = BIO_new(BIO_s_mem());
27 BIO_set_flags(b64,BIO_CLOSE); 28 BIO_set_flags(b64,BIO_CLOSE);
28 if(!bmem) 29 if(!bmem)
29 throw exception_openssl(OPKELE_CP_ "failed to BIO_new() memory buffer"); 30 throw exception_openssl(OPKELE_CP_ "failed to BIO_new() memory buffer");
30 BIO_push(b64,bmem); 31 BIO_push(b64,bmem);
31 if(((size_t)BIO_write(b64,data,length))!=length) 32 if(((size_t)BIO_write(b64,data,length))!=length)
32 throw exception_openssl(OPKELE_CP_ "failed to BIO_write()"); 33 throw exception_openssl(OPKELE_CP_ "failed to BIO_write()");
33 if(BIO_flush(b64)!=1) 34 if(BIO_flush(b64)!=1)
34 throw exception_openssl(OPKELE_CP_ "failed to BIO_flush()"); 35 throw exception_openssl(OPKELE_CP_ "failed to BIO_flush()");
35 char *rvd; 36 char *rvd;
36 long rvl = BIO_get_mem_data(bmem,&rvd); 37 long rvl = BIO_get_mem_data(bmem,&rvd);
37 string rv(rvd,rvl); 38 string rv(rvd,rvl);
38 BIO_free_all(b64); 39 BIO_free_all(b64);
39 return rv; 40 return rv;
40 }catch(...) { 41 }catch(...) {
41 if(b64) BIO_free_all(b64); 42 if(b64) BIO_free_all(b64);
42 throw; 43 throw;
43 } 44 }
44 } 45 }
45 46
46 void decode_base64(const string& data,vector<unsigned char>& rv) { 47 void decode_base64(const string& data,vector<unsigned char>& rv) {
47 BIO *b64 = 0, *bmem = 0; 48 BIO *b64 = 0, *bmem = 0;
48 rv.clear(); 49 rv.clear();
49 try { 50 try {
50 bmem = BIO_new_mem_buf((void*)data.data(),data.size()); 51 bmem = BIO_new_mem_buf((void*)data.data(),data.size());
51 if(!bmem) 52 if(!bmem)
52 throw exception_openssl(OPKELE_CP_ "failed to BIO_new_mem_buf()"); 53 throw exception_openssl(OPKELE_CP_ "failed to BIO_new_mem_buf()");
53 b64 = BIO_new(BIO_f_base64()); 54 b64 = BIO_new(BIO_f_base64());
54 if(!b64) 55 if(!b64)
55 throw exception_openssl(OPKELE_CP_ "failed to BIO_new() base64 decoder"); 56 throw exception_openssl(OPKELE_CP_ "failed to BIO_new() base64 decoder");
56 BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); 57 BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);
57 BIO_push(b64,bmem); 58 BIO_push(b64,bmem);
58 unsigned char tmp[512]; 59 unsigned char tmp[512];
59 size_t rb = 0; 60 size_t rb = 0;
60 while((rb=BIO_read(b64,tmp,sizeof(tmp)))>0) 61 while((rb=BIO_read(b64,tmp,sizeof(tmp)))>0)
61 rv.insert(rv.end(),tmp,&tmp[rb]); 62 rv.insert(rv.end(),tmp,&tmp[rb]);
62 BIO_free_all(b64); 63 BIO_free_all(b64);
63 }catch(...) { 64 }catch(...) {
64 if(b64) BIO_free_all(b64); 65 if(b64) BIO_free_all(b64);
65 throw; 66 throw;
66 } 67 }
67 } 68 }
68 69
69 /* 70 /*
70 * big numerics 71 * big numerics
71 */ 72 */
72 73
73 BIGNUM *base64_to_bignum(const string& b64) { 74 BIGNUM *base64_to_bignum(const string& b64) {
74 vector<unsigned char> bin; 75 vector<unsigned char> bin;
75 decode_base64(b64,bin); 76 decode_base64(b64,bin);
76 BIGNUM *rv = BN_bin2bn(&(bin.front()),bin.size(),0); 77 BIGNUM *rv = BN_bin2bn(&(bin.front()),bin.size(),0);
77 if(!rv) 78 if(!rv)
78 throw failed_conversion(OPKELE_CP_ "failed to BN_bin2bn()"); 79 throw failed_conversion(OPKELE_CP_ "failed to BN_bin2bn()");
79 return rv; 80 return rv;
80 } 81 }
81 82
82 BIGNUM *dec_to_bignum(const string& dec) { 83 BIGNUM *dec_to_bignum(const string& dec) {
83 BIGNUM *rv = 0; 84 BIGNUM *rv = 0;
84 if(!BN_dec2bn(&rv,dec.c_str())) 85 if(!BN_dec2bn(&rv,dec.c_str()))
85 throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); 86 throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()");
86 return rv; 87 return rv;
87 } 88 }
88 89
89 string bignum_to_base64(const BIGNUM *bn) { 90 string bignum_to_base64(const BIGNUM *bn) {
90 vector<unsigned char> bin(BN_num_bytes(bn)+1); 91 vector<unsigned char> bin(BN_num_bytes(bn)+1);
91 unsigned char *binptr = &(bin.front())+1; 92 unsigned char *binptr = &(bin.front())+1;
92 int l = BN_bn2bin(bn,binptr); 93 int l = BN_bn2bin(bn,binptr);
93 if(l && (*binptr)&0x80){ 94 if(l && (*binptr)&0x80){
94 (*(--binptr)) = 0; ++l; 95 (*(--binptr)) = 0; ++l;
95 } 96 }
96 return encode_base64(binptr,l); 97 return encode_base64(binptr,l);
97 } 98 }
98 99