implemented SHA1 encrypted passwords for manager

This commit is contained in:
Martin Willi
2007-09-27 07:15:47 +00:00
parent 324abae2ef
commit 93720075df
5 changed files with 57 additions and 7 deletions
+31 -4
View File
@@ -248,6 +248,35 @@ bool chunk_write(chunk_t chunk, const char *path, const char *label, mode_t mask
}
}
/** hex conversion digits */
static char hexdig_upper[] = "0123456789ABCDEF";
static char hexdig_lower[] = "0123456789abcdef";
/**
* Described in header.
*/
char *chunk_to_hex(chunk_t chunk, bool uppercase)
{
int i;
char *str;
char *hexdig = hexdig_lower;
if (uppercase)
{
hexdig = hexdig_upper;
}
str = malloc(chunk.len * 2 + 1);
str[chunk.len * 2] = '\0';
for (i = 0; i < chunk.len; i ++)
{
str[i*2] = hexdig[(chunk.ptr[i] >> 4) & 0xF];
str[i*2+1] = hexdig[(chunk.ptr[i] ) & 0xF];
}
return str;
}
/**
* Described in header.
*/
@@ -354,10 +383,8 @@ static int print_bytes(FILE *stream, const struct printf_info *info,
while (bytes_pos < bytes_roof)
{
static char hexdig[] = "0123456789ABCDEF";
*buffer_pos++ = hexdig[(*bytes_pos >> 4) & 0xF];
*buffer_pos++ = hexdig[ *bytes_pos & 0xF];
*buffer_pos++ = hexdig_upper[(*bytes_pos >> 4) & 0xF];
*buffer_pos++ = hexdig_upper[ *bytes_pos & 0xF];
ascii_buffer[i++] =
(*bytes_pos > 31 && *bytes_pos < 127) ? *bytes_pos : '.';
+5
View File
@@ -83,6 +83,11 @@ void chunk_split(chunk_t chunk, const char *mode, ...);
*/
bool chunk_write(chunk_t chunk, const char *path, const char *label, mode_t mask, bool force);
/**
* convert a chunk to an allocated hex string
*/
char *chunk_to_hex(chunk_t chunk, bool uppercase);
/**
* Free contents of a chunk
*/