diff -r 509e9e1cbdcc -r 37fb12574acd libidav/utils.c --- a/libidav/utils.c Sat Oct 03 20:10:54 2015 +0200 +++ b/libidav/utils.c Sun Oct 04 15:57:40 2015 +0200 @@ -49,9 +49,6 @@ #include "crypto.h" #include "webdav.h" -#ifdef __sun -#include -#endif time_t util_parse_creationdate(char *str) { // example: 2012-11-29T21:35:35Z @@ -167,7 +164,7 @@ } int add_separator = 0; - if(base.ptr[base.length-1] == '/') { + if(base.length != 0 && base.ptr[base.length-1] == '/') { if(path.ptr[0] == '/') { base.length--; } @@ -268,7 +265,7 @@ size_t len = strlen(in); char *out = calloc(1, len); - BIO* b = BIO_new_mem_buf(in, len); + BIO *b = BIO_new_mem_buf(in, len); BIO *d = BIO_new(BIO_f_base64()); BIO_set_flags(d, BIO_FLAGS_BASE64_NO_NL); b = BIO_push(d, b); @@ -286,15 +283,16 @@ e = BIO_new(BIO_f_base64()); b = BIO_new(BIO_s_mem()); + BIO_set_flags(e, BIO_FLAGS_BASE64_NO_NL); e = BIO_push(e, b); BIO_write(e, in, len); BIO_flush(e); BIO_get_mem_ptr(e, &mem); - char *out = malloc(mem->length); - memcpy(out, mem->data, mem->length -1); - out[mem->length - 1] = '\0'; + char *out = malloc(mem->length + 1); + memcpy(out, mem->data, mem->length); + out[mem->length] = '\0'; BIO_free_all(e); @@ -312,7 +310,7 @@ } char* util_encrypt_str_k(DavSession *sn, char *str, DavKey *key) { - char *enc_str = aes_encrypt(str, key); + char *enc_str = aes_encrypt(str, strlen(str), key); char *ret_str = dav_session_strdup(sn, enc_str); free(enc_str); return ret_str; @@ -329,7 +327,8 @@ } char* util_decrypt_str_k(DavSession *sn, char *str, DavKey *key) { - char *dec_str = aes_decrypt(str, key); + size_t len = 0; + char *dec_str = aes_decrypt(str, &len, key); char *ret_str = dav_session_strdup(sn, dec_str); free(dec_str); return ret_str; @@ -478,3 +477,16 @@ free(prompt.ptr); return password; } + + +char* util_hexstr(unsigned char *data, size_t len) { + size_t buflen = 2*len + 4; + UcxBuffer *buf = ucx_buffer_new(malloc(buflen), buflen + 1, 0); + for(int i=0;ispace; + ucx_buffer_free(buf); + return str; +}