forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hex-ll: separate out non-hash-algo functions
In order to further reduce all-in-one headers, separate out functions in hex.h that do not operate on object hashes into its own file, hex-ll.h, and update the include directives in the .c files that need only such functions accordingly. Signed-off-by: Calvin Wan <[email protected]> Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
- Loading branch information
1 parent
94e83dc
commit d88e810
Showing
10 changed files
with
83 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "git-compat-util.h" | ||
#include "hex-ll.h" | ||
|
||
const signed char hexval_table[256] = { | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 18-1f */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 20-27 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 28-2f */ | ||
0, 1, 2, 3, 4, 5, 6, 7, /* 30-37 */ | ||
8, 9, -1, -1, -1, -1, -1, -1, /* 38-3f */ | ||
-1, 10, 11, 12, 13, 14, 15, -1, /* 40-47 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 48-4f */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 50-57 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 58-5f */ | ||
-1, 10, 11, 12, 13, 14, 15, -1, /* 60-67 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 68-67 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 70-77 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 78-7f */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 80-87 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-8f */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 90-97 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* 98-9f */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* a0-a7 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* a8-af */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* b0-b7 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* b8-bf */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* c0-c7 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* c8-cf */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* d0-d7 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* d8-df */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* e0-e7 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* e8-ef */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* f0-f7 */ | ||
-1, -1, -1, -1, -1, -1, -1, -1, /* f8-ff */ | ||
}; | ||
|
||
int hex_to_bytes(unsigned char *binary, const char *hex, size_t len) | ||
{ | ||
for (; len; len--, hex += 2) { | ||
unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]); | ||
|
||
if (val & ~0xff) | ||
return -1; | ||
*binary++ = val; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef HEX_LL_H | ||
#define HEX_LL_H | ||
|
||
extern const signed char hexval_table[256]; | ||
static inline unsigned int hexval(unsigned char c) | ||
{ | ||
return hexval_table[c]; | ||
} | ||
|
||
/* | ||
* Convert two consecutive hexadecimal digits into a char. Return a | ||
* negative value on error. Don't run over the end of short strings. | ||
*/ | ||
static inline int hex2chr(const char *s) | ||
{ | ||
unsigned int val = hexval(s[0]); | ||
return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); | ||
} | ||
|
||
/* | ||
* Read `len` pairs of hexadecimal digits from `hex` and write the | ||
* values to `binary` as `len` bytes. Return 0 on success, or -1 if | ||
* the input does not consist of hex digits). | ||
*/ | ||
int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#include "git-compat-util.h" | ||
#include "hex.h" | ||
#include "hex-ll.h" | ||
#include "strbuf.h" | ||
#include "url.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters