Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/signing.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-08-14 20:47:08 -0500
committerDan McGee <dan@archlinux.org>2011-08-15 12:11:59 -0500
commitfa4aad5b509946f947d9b2553d09f5f35be24915 (patch)
treed588e93fb9d3d41c6e582f625eaed82c19ff3109 /lib/libalpm/signing.c
parentf3f39cef84330b734c36a60e48cf26a3f3e1f76c (diff)
decode_signature: guess signature data length for efficiency
We may end up allocating 1 or 2 extra bytes this way, but it is worth it to simplify the method and not have to call base64_decode() a second time. Use the hueristic that base64 encoding produces 3 bytes of decoded data for every 4 bytes of encoded data. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/signing.c')
-rw-r--r--lib/libalpm/signing.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 6ca32fd5..7521e3ad 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -169,22 +169,12 @@ error:
*/
static int decode_signature(const char *base64_data,
unsigned char **data, size_t *data_len) {
- unsigned char *usline;
- size_t len;
-
- len = strlen(base64_data);
- usline = (unsigned char *)base64_data;
- int ret;
- size_t destlen = 0;
- /* get the necessary size for the buffer by passing 0 */
- ret = base64_decode(NULL, &destlen, usline, len);
- if(ret != 0 && ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) {
- goto error;
- }
- /* alloc our memory and repeat the call to decode */
+ size_t len = strlen(base64_data);
+ unsigned char *usline = (unsigned char *)base64_data;
+ /* reasonable allocation of expected length is 3/4 of encoded length */
+ size_t destlen = len * 3 / 4;
MALLOC(*data, destlen, goto error);
- ret = base64_decode(*data, &destlen, usline, len);
- if(ret != 0) {
+ if(base64_decode(*data, &destlen, usline, len)) {
goto error;
}
*data_len = destlen;