4
私は与えられたこのバッファを持っている:OpenSSLでバッファを適切にbase64エンコードしていますか?
unsigned char *buffer;
int buffer_length;
これは私が現在、base64エンコードバッファに変換する方法である:
BIO *mem = BIO_new(BIO_s_mem());
BIO *b64 = BIO_new(BIO_f_base64());
mem = BIO_push(b64, mem);
int write_length = BIO_write(mem, buffer, buffer_length);
if (write_length != buffer_length) //*
return -1;
int flush_result = BIO_flush(mem);
if (flush_result != 1)
return -1;
unsigned char *result; //**
int result_length = BIO_get_mem_data(mem, &result);
//use the base64-encoded result to do whatever I need to do
BIO_free_all(mem);
return 0;
これまでのところ、これは動作しているようです。しかし、この良いと堅牢なコードですか?私は上記のアスタリスクでマークされたコード片について質問があります。
- (
//*
)はそれが正しいBIO_write()
は、常に全体を一度base64でエンコードされた文字列を書き出し、または私はループを作成しなければならないのだろうと想定することですここに? - (
//**
)タイプunsigned char*
が正しいのですか、代わりにchar *
を使用する必要がありますか?