diff --git a/inc/ft_base64.h b/inc/ft_base64.h index fcf9e7a7..336debfa 100644 --- a/inc/ft_base64.h +++ b/inc/ft_base64.h @@ -130,7 +130,6 @@ void ft_base64_decode_transform void ft_base64_decode_finish ( - t_base64_ctx *ctx, t_base64_decode_buffer *buff ); diff --git a/src/base64/ft_base64_decode.c b/src/base64/ft_base64_decode.c index 00ac0903..7c5acbc3 100644 --- a/src/base64/ft_base64_decode.c +++ b/src/base64/ft_base64_decode.c @@ -13,5 +13,5 @@ void ft_base64_decode(t_base64_ctx *ctx) readed = ft_base64_decode_filter(readed, read_buff); ft_base64_decode_chunk(ctx, readed, read_buff, &decode_buff); } - ft_base64_decode_finish(ctx, &decode_buff); + ft_base64_decode_finish(&decode_buff); } \ No newline at end of file diff --git a/src/base64/ft_base64_decode_finish.c b/src/base64/ft_base64_decode_finish.c index e72fa6bf..7b352c2b 100644 --- a/src/base64/ft_base64_decode_finish.c +++ b/src/base64/ft_base64_decode_finish.c @@ -3,27 +3,18 @@ void ft_base64_decode_finish ( - t_base64_ctx *ctx, t_base64_decode_buffer *buff ) { t_byte8 buffer_index; - t_byte8 padding_size; - // t_byte1 chars[FT_BASE64_ENCODE_BLOCK_SIZE]; buffer_index = buff->readed % FT_BASE64_DECODE_BLOCK_SIZE; - padding_size = FT_BASE64_DECODE_BLOCK_SIZE - buffer_index; if (!buff->readed) return ; - if (!buffer_index) + if (buffer_index != 0) { - write(ctx->output_fd, "\n", 1); - return ; + ft_putstr("\nbase64: invalid input: readed \ +bytes count isn't multiple of 4\n"); + exit(1); } - // ft_bzero(&buff->block[buffer_index], padding_size); - // ft_base64_encode_transform(ctx, buff->block, chars); - // ft_memset(chars + FT_BASE64_DECODE_BLOCK_SIZE - padding_size, '=', - // padding_size); - // write(ctx->output_fd, chars, FT_BASE64_DECODE_BLOCK_SIZE); - // write(ctx->output_fd, "\n", 1); } \ No newline at end of file diff --git a/src/base64/ft_base64_decode_transform.c b/src/base64/ft_base64_decode_transform.c index 53f1c118..b323e931 100644 --- a/src/base64/ft_base64_decode_transform.c +++ b/src/base64/ft_base64_decode_transform.c @@ -12,7 +12,9 @@ static t_byte1 get_alphabet_index alphabet_addr = ft_strchr((const char*)alphabet, ch); if (!alphabet_addr) { - ft_putstr("base64: invalid input\n"); + ft_putstr("base64: invalid input: \""); + ft_putchar(ch); + ft_putstr("\" char not in base64 alphabet\n"); exit(1); } return (alphabet_addr - (char *)alphabet); diff --git a/t/cases/invalid.decode.txt b/t/cases/invalid_char.decode.txt similarity index 100% rename from t/cases/invalid.decode.txt rename to t/cases/invalid_char.decode.txt diff --git a/t/cases/invalid_length.decode.txt b/t/cases/invalid_length.decode.txt new file mode 100644 index 00000000..b3139738 --- /dev/null +++ b/t/cases/invalid_length.decode.txt @@ -0,0 +1 @@ +TWFFu