guodongxiaren edited a comment on pull request #1506:
URL: https://github.com/apache/incubator-brpc/pull/1506#issuecomment-892219453
>
自己转string为什么会多转一位呢,这个听起来是转化的问题,做完转化直接把Hex格式的数据追加到url应该不会有问题吧。或者把代码贴上来看看是什么问题
多一位是我这边使用openssl不当导致的问题。加这个检验主要是方便debug。后面如果其他人再有给URL不小心引入不可见字符的时候,可以通过错误信息,快速定位问题。
具体我那个问题是用openssl计算base64,用出了问题。调用的那个外部接口要求计算完hmac_sha256后,对结果做一次base64
```cpp
BIO *bmem, *b64;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, input, length); // input 是unsigned char* 类型,也就是待编码的二进制数据
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
// 这里,一开始我写成了std::string output(bptr->data, bptr->length); debug了很久
std::string output(bptr->data, bptr->length-1);
BIO_free_all(b64);
output 会作为签名追加到url中 &sign=output
```
我这个确实是我使用openssl不当造成的,但是我觉得brpc应该帮助做一些url字符合法性上的检验。我这个PR只是简单处理检验的可打印字符,我也可以再改下,严格起来排除一切不合法的URL字符
@zyearn
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]