IsCanonicalPubKey method in Bitcoin Core source In my logs I see that I keep getting:


  ERROR: Non-canonical public key: compressed nor uncompressed


This error is thrown from inside the method:


  bool IsCanonicalPubKey(const valtype &amp;vchPubKey, unsigned int flags)


I can't understand what this method is checking. I understand it's checking if the Public Key is Canonical but, I don't understand what that means. 

Can you please explain?
bool IsCanonicalPubKey(const valtype &amp;vchPubKey) {
    if (vchPubKey.size() &lt; 33)
        return error("Non-canonical public key: too short");
    if (vchPubKey[0] == 0x04) {
        if (vchPubKey.size() != 65)
            return error("Non-canonical public key: invalid length for uncompressed key");
    } else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
        if (vchPubKey.size() != 33)
            return error("Non-canonical public key: invalid length for compressed key");
    } else {
        return error("Non-canonical public key: compressed nor uncompressed");
    }
    return true;
}



1) Public keys must be either 65 or 33 bytes long.
2a) 65 byte long public keys must start with one byte prefix 0x04
2b) 33 byte long public keys must start with one byte prefix 0x02 or
0x03
3) Any other byte sequences can not be treated as public key