ext/xlsxwriter/libxlsxwriter/src/utility.c in xlsxwriter-0.0.5 vs ext/xlsxwriter/libxlsxwriter/src/utility.c in xlsxwriter-0.0.6

- old
+ new

@@ -10,18 +10,19 @@ #include <ctype.h> #include <stdio.h> #include <string.h> #include <stdint.h> #include <stdlib.h> -#include "xlsxwriter/utility.h" +#include "xlsxwriter.h" #include "xlsxwriter/third_party/tmpfileplus.h" char *error_strings[LXW_MAX_ERRNO + 1] = { "No error.", "Memory error, failed to malloc() required memory.", "Error creating output xlsx file. Usually a permissions error.", "Error encountered when creating a tmpfile during file assembly.", + "Error reading a tmpfile.", "Zlib error with a file operation while creating xlsx file.", "Zlib error when adding sub file to xlsx file.", "Zlib error when closing xlsx file.", "NULL function parameter ignored.", "Function parameter validation error.", @@ -551,5 +552,46 @@ *tmp = '.'; return 0; } #endif + +/* + * Retrieve runtime library version + */ +const char * +lxw_version(void) +{ + return LXW_VERSION; +} + +/* + * Hash a worksheet password. Based on the algorithm provided by Daniel Rentz + * of OpenOffice. + */ +uint16_t +lxw_hash_password(const char *password) +{ + size_t count; + uint8_t i; + uint16_t hash = 0x0000; + + count = strlen(password); + + for (i = 0; i < count; i++) { + uint32_t low_15; + uint32_t high_15; + uint32_t letter = password[i] << (i + 1); + + low_15 = letter & 0x7fff; + high_15 = letter & (0x7fff << 15); + high_15 = high_15 >> 15; + letter = low_15 | high_15; + + hash ^= letter; + } + + hash ^= count; + hash ^= 0xCE4B; + + return hash; +}