MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / IsCompressedOrUncompressedPubKey

Function IsCompressedOrUncompressedPubKey

src/script/interpreter.cpp:74–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
75 if (vchPubKey.size() < CPubKey::COMPRESSED_SIZE) {
76 // Non-canonical public key: too short
77 return false;
78 }
79 if (vchPubKey[0] == 0x04) {
80 if (vchPubKey.size() != CPubKey::SIZE) {
81 // Non-canonical public key: invalid length for uncompressed key
82 return false;
83 }
84 } else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
85 if (vchPubKey.size() != CPubKey::COMPRESSED_SIZE) {
86 // Non-canonical public key: invalid length for compressed key
87 return false;
88 }
89 } else {
90 // Non-canonical public key: neither compressed nor uncompressed
91 return false;
92 }
93 return true;
94}
95
96bool static IsCompressedPubKey(const valtype &vchPubKey) {
97 if (vchPubKey.size() != CPubKey::COMPRESSED_SIZE) {

Callers 1

CheckPubKeyEncodingFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected