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

Function IsCompressedOrUncompressedPubKey

src/script/interpreter.cpp:66–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
67 if (vchPubKey.size() < 33) {
68 // Non-canonical public key: too short
69 return false;
70 }
71 if (vchPubKey[0] == 0x04) {
72 if (vchPubKey.size() != 65) {
73 // Non-canonical public key: invalid length for uncompressed key
74 return false;
75 }
76 } else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
77 if (vchPubKey.size() != 33) {
78 // Non-canonical public key: invalid length for compressed key
79 return false;
80 }
81 } else {
82 // Non-canonical public key: neither compressed nor uncompressed
83 return false;
84 }
85 return true;
86}
87
88/**
89 * A canonical signature exists of: <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>

Callers 1

CheckPubKeyEncodingFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected