Return true if S is a LEN-byte NUL-terminated string of hex or base64 digits and has the expected length. Otherwise, return false. */
| 779 | /* Return true if S is a LEN-byte NUL-terminated string of hex or base64 |
| 780 | digits and has the expected length. Otherwise, return false. */ |
| 781 | ATTRIBUTE_PURE |
| 782 | static bool |
| 783 | valid_digits (unsigned char const *s, idx_t len) |
| 784 | { |
| 785 | #if HASH_ALGO_CKSUM |
| 786 | if (len == BASE64_LENGTH (digest_length >> 3)) |
| 787 | { |
| 788 | idx_t i; |
| 789 | for (i = 0; i < len - digest_length % 3; i++) |
| 790 | { |
| 791 | if (!isbase64 (*s)) |
| 792 | return false; |
| 793 | ++s; |
| 794 | } |
| 795 | for ( ; i < len; i++) |
| 796 | { |
| 797 | if (*s != '=') |
| 798 | return false; |
| 799 | ++s; |
| 800 | } |
| 801 | } |
| 802 | else |
| 803 | #endif |
| 804 | if (len == digest_hex_bytes) |
| 805 | { |
| 806 | for (idx_t i = 0; i < digest_hex_bytes; i++) |
| 807 | { |
| 808 | if (!c_isxdigit (*s)) |
| 809 | return false; |
| 810 | ++s; |
| 811 | } |
| 812 | } |
| 813 | else |
| 814 | return false; |
| 815 | |
| 816 | return *s == '\0'; |
| 817 | } |
| 818 | |
| 819 | /* Split the checksum string S (of length S_LEN) from a BSD 'md5' or |
| 820 | 'sha1' command into two parts: a hexadecimal digest, and the file |
no outgoing calls
no test coverage detected