サマリ:base64のソースコードリーディング7回目
base64を読もう⑦〜base_decode_ctx編〜
前回まででbase64.cのdecode部分は読み終えたのですが、核となる部分はgnulibを呼んでいたので、ここも少し触っておきたいと思った次第。(私の知識では)どこまでいけるかは未知数。
/* Decode base64-encoded input array IN of length INLEN to output array
OUT that can hold *OUTLEN bytes. The input data may be interspersed
with newlines. Return true if decoding was successful, i.e. if the
input was valid base64 data, false otherwise. If *OUTLEN is too
small, as many bytes as possible will be written to OUT. On return,
*OUTLEN holds the length of decoded bytes in OUT. Note that as soon
as any non-alphabet, non-newline character is encountered, decoding
is stopped and false is returned. If INLEN is zero, then process
only whatever data is stored in CTX.
Initially, CTX must have been initialized via base64_decode_ctx_init.
Subsequent calls to this function must reuse whatever state is recorded
in that buffer. It is necessary for when a quadruple of base64 input
bytes spans two input buffers.
If CTX is NULL then newlines are treated as garbage and the input
buffer is processed as a unit. */
bool
base64_decode_ctx (struct base64_decode_context *ctx,
const char *restrict in, size_t inlen,
char *restrict out, size_t *outlen)
『base64エンコードされたINLENの長さの配列INをデコードし、配列OUTに*OUTLENバイトだけ保持することができる。入力データは改行が含まれていることもある。デコードが成功した場合はtrueを返す。それは入力データがbase64でエンコードされていることを示し、そうでない場合はデータが誤っている。*OUTLENが小さすぎる場合、最大長のバイト数をOUTに書き込む。この処理から返った場合、*OUTLENにはデコード済みデータのOUTの長さが保持される。アルファベット及び改行以外が出現した場合、すぐにデコードをストップし、falseを返す。もしINLENが0の場合、どのようなデータであったとしてもコンテキストに保持し続ける。』
『コンテキストはbase64_decode_ctx_initを通して初期化されていなければならない。 続く処理では、バッファに記録されている状態を再利用する必要がある。 これは、base64エンコードされた入力データが4倍となるため、2つの入力バッファをまたぐために必要となります。』
『コンテキストがNULLの場合、改行は無視され、入力バッファは単一処理されます。 』
処理概要を理解した(?)ところで、今日はここまで。
###理解したこと ###宿題
以上。今日は雨です。でも仕事には関係ないので頑張ります(当たり前か・・)。でも止んでほしいなー!