summaryrefslogtreecommitdiffabout
path: root/lib/util.cc
Side-by-side diff
Diffstat (limited to 'lib/util.cc') (more/less context) (show 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 {
throw failed_conversion(OPKELE_CP_ "failed to BN_bin2bn()");
return rv;
}
BIGNUM *dec_to_bignum(const string& dec) {
BIGNUM *rv = 0;
if(!BN_dec2bn(&rv,dec.c_str()))
throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()");
return rv;
}
string bignum_to_base64(const BIGNUM *bn) {
- vector<unsigned char> bin(BN_num_bytes(bn));
- int l = BN_bn2bin(bn,&(bin.front()));
- return encode_base64(&(bin.front()),l);
+ vector<unsigned char> bin(BN_num_bytes(bn)+1);
+ unsigned char *binptr = &(bin.front())+1;
+ int l = BN_bn2bin(bn,binptr);
+ if(l && (*binptr)&0x80){
+ (*(--binptr)) = 0; ++l;
+ }
+ return encode_base64(binptr,l);
}
/*
* w3c times
*/
string time_to_w3c(time_t t) {
struct tm tm_t;
if(!gmtime_r(&t,&tm_t))
throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()");
char rv[25];
if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t))