ssl_des/inc/ft_base64.h

143 lines
2.9 KiB
C
Raw Normal View History

2019-01-19 18:16:00 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_base64.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/19 17:58:39 by gtertysh #+# #+# */
/* Updated: 2019/01/19 17:59:19 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_BASE64_H
# define FT_BASE64_H
# include <stdint.h>
2019-02-20 22:11:29 +02:00
# define FT_BASE64_READ_SIZE 1024
# define FT_BASE64_ENCODE_BLOCK_SIZE 3
# define FT_BASE64_DECODE_BLOCK_SIZE 4
2019-01-29 23:23:04 +02:00
# define FT_BASE64_ALPHABET_LENGTH 64
2019-01-19 18:16:00 +02:00
typedef uint64_t t_byte8;
typedef unsigned char t_byte1;
2019-02-20 22:11:29 +02:00
typedef struct s_base64_encode_buffer
{
t_byte1 block[FT_BASE64_ENCODE_BLOCK_SIZE];
2019-02-20 22:11:29 +02:00
t_byte8 readed;
} t_base64_encode_buffer;
typedef struct s_base64_decode_buffer
{
t_byte1 block[FT_BASE64_DECODE_BLOCK_SIZE];
t_byte8 readed;
} t_base64_decode_buffer;
2019-01-19 18:16:00 +02:00
typedef struct s_base64_ctx
{
2019-02-07 23:22:40 +02:00
int input_fd;
int output_fd;
2019-01-29 23:23:04 +02:00
t_byte1 alphabet[FT_BASE64_ALPHABET_LENGTH];
2019-01-19 18:16:00 +02:00
} t_base64_ctx;
2019-02-07 23:22:40 +02:00
typedef struct s_base64_flags
{
int decode;
} t_base64_flags;
void ft_base64
(
int argc,
char **argv
);
void ft_base64_init
(
t_base64_ctx *ctx
);
void ft_base64_decode
(
t_base64_ctx *ctx
);
void ft_base64_encode
(
t_base64_ctx *ctx
);
2019-02-10 23:11:01 +02:00
t_byte8 ft_base64_encode_step
(
t_base64_ctx *ctx,
t_byte1 *buff
);
void ft_base64_encode_finish
(
t_base64_ctx *ctx,
2019-02-20 22:11:29 +02:00
t_base64_encode_buffer *buff
2019-02-10 23:11:01 +02:00
);
2019-02-07 23:22:40 +02:00
void ft_base64_fill_buffer
(
t_base64_ctx *ctx,
t_byte1 *data,
t_byte8 size
);
2019-02-20 22:11:29 +02:00
void ft_base64_encode_transform
2019-02-07 23:22:40 +02:00
(
t_base64_ctx *ctx,
t_byte1 data[FT_BASE64_ENCODE_BLOCK_SIZE],
t_byte1 chars[FT_BASE64_DECODE_BLOCK_SIZE]
2019-02-07 23:22:40 +02:00
);
2019-01-19 18:16:00 +02:00
2019-02-20 22:11:29 +02:00
void ft_base64_encode_chunk
2019-02-10 23:11:01 +02:00
(
2019-02-20 22:11:29 +02:00
t_base64_ctx *ctx,
t_byte8 len,
t_byte1 *message,
t_base64_encode_buffer *enc_buff
2019-02-10 23:11:01 +02:00
);
2019-02-20 22:11:29 +02:00
void ft_base64_init_encode_buffer
2019-02-17 21:07:19 +02:00
(
2019-02-20 22:11:29 +02:00
t_base64_encode_buffer *buff
2019-02-17 21:07:19 +02:00
);
void ft_base64_init_decode_buffer
(
t_base64_decode_buffer *buff
);
void ft_base64_decode_chunk
(
t_base64_ctx *ctx,
t_byte8 len,
t_byte1 *message,
t_base64_decode_buffer *dec_buff
);
void ft_base64_decode_transform
(
t_base64_ctx *ctx,
t_byte1 *message,
t_byte1 decoded_block[FT_BASE64_ENCODE_BLOCK_SIZE]
);
void ft_base64_decode_finish
(
t_base64_decode_buffer *buff
);
t_byte8 ft_base64_decode_filter
(
t_byte8 readed,
t_byte1 *buff
);
2019-01-19 18:16:00 +02:00
#endif