MCPcopy Create free account
hub / github.com/ElementsProject/elements / IsCompressedOrUncompressedPubKey

Function IsCompressedOrUncompressedPubKey

src/script/interpreter.cpp:145–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
146 if (vchPubKey.size() < CPubKey::COMPRESSED_SIZE) {
147 // Non-canonical public key: too short
148 return false;
149 }
150 if (vchPubKey[0] == 0x04) {
151 if (vchPubKey.size() != CPubKey::SIZE) {
152 // Non-canonical public key: invalid length for uncompressed key
153 return false;
154 }
155 } else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
156 if (vchPubKey.size() != CPubKey::COMPRESSED_SIZE) {
157 // Non-canonical public key: invalid length for compressed key
158 return false;
159 }
160 } else {
161 // Non-canonical public key: neither compressed nor uncompressed
162 return false;
163 }
164 return true;
165}
166
167bool static IsCompressedPubKey(const valtype &vchPubKey) {
168 if (vchPubKey.size() != CPubKey::COMPRESSED_SIZE) {

Callers 1

CheckPubKeyEncodingFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected