summaryrefslogtreecommitdiffabout
path: root/lib/util.cc
Unidiff
Diffstat (limited to 'lib/util.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/util.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/util.cc b/lib/util.cc
index d9abca7..94f6f53 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -77,27 +77,31 @@ namespace opkele {
77 throw failed_conversion(OPKELE_CP_ "failed to BN_bin2bn()"); 77 throw failed_conversion(OPKELE_CP_ "failed to BN_bin2bn()");
78 return rv; 78 return rv;
79 } 79 }
80 80
81 BIGNUM *dec_to_bignum(const string& dec) { 81 BIGNUM *dec_to_bignum(const string& dec) {
82 BIGNUM *rv = 0; 82 BIGNUM *rv = 0;
83 if(!BN_dec2bn(&rv,dec.c_str())) 83 if(!BN_dec2bn(&rv,dec.c_str()))
84 throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); 84 throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()");
85 return rv; 85 return rv;
86 } 86 }
87 87
88 string bignum_to_base64(const BIGNUM *bn) { 88 string bignum_to_base64(const BIGNUM *bn) {
89 vector<unsigned char> bin(BN_num_bytes(bn)); 89 vector<unsigned char> bin(BN_num_bytes(bn)+1);
90 int l = BN_bn2bin(bn,&(bin.front())); 90 unsigned char *binptr = &(bin.front())+1;
91 return encode_base64(&(bin.front()),l); 91 int l = BN_bn2bin(bn,binptr);
92 if(l && (*binptr)&0x80){
93 (*(--binptr)) = 0; ++l;
94 }
95 return encode_base64(binptr,l);
92 } 96 }
93 97
94 /* 98 /*
95 * w3c times 99 * w3c times
96 */ 100 */
97 101
98 string time_to_w3c(time_t t) { 102 string time_to_w3c(time_t t) {
99 struct tm tm_t; 103 struct tm tm_t;
100 if(!gmtime_r(&t,&tm_t)) 104 if(!gmtime_r(&t,&tm_t))
101 throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); 105 throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()");
102 char rv[25]; 106 char rv[25];
103 if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t)) 107 if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t))