我目前正在尝试为一个开源服务器实现一个谷歌验证器,他们有这么一小段代码
if (securityFlags & 0x01) // PIN input
{
pkt << uint32(0);
pkt << uint64(0) << uint64(0); // 16 bytes hash?
// This triggers the 2 factor authenticator entry to popup on the client side
}
if (securityFlags & 0x02) // Matrix input
{
pkt << uint8(0);
pkt << uint8(0);
pkt << uint8(0);
pkt << uint8(0);
pkt << uint64(0);
}
if (securityFlags & 0x04) // Security token input
{
pkt << uint8(1);
}
我只是想弄清楚他们为什么使用 pkt << uint32(0)
,因为它们对我来说似乎完全多余。而且他们还多次使用它,这更没有意义。
知道为什么他们的代码是这样写的吗?
最佳答案
operator<< 为 ByteBuffer 重载(这是一个 pkt 类型),看起来如下:
ByteBuffer& operator<<(uint8 value)
{
append<uint8>(value);
return *this;
}
所以它不是移动 0,而是附加值 0。
关于c++ - 左移0有什么意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41837395/