Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of left shifting by 0?

Tags:

c++

I'm currently trying to implement a google authenticator for an open source server and they have this small bit of code

  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);
                }

I'm just trying to figure out why they use pkt << uint32(0), as they seem completely redundant to me. And they also use it a lot of times over, which makes even less sense.

Any ideas why their code was written like that?

like image 375
Datsik Avatar asked Dec 05 '25 06:12

Datsik


1 Answers

operator<< is overloaded for ByteBuffer (this is a pkt type), and it looks as follows:

https://github.com/mangostwo/server/blob/b8ce9508483375a36699c309bce36810c4548007/src/shared/ByteBuffer.h#L138

    ByteBuffer& operator<<(uint8 value)
    {
        append<uint8>(value);
        return *this;
    }

so its not a shift by 0, but appending of value 0.

like image 94
marcinj Avatar answered Dec 07 '25 20:12

marcinj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!