Assert CPubKey::ValidLength to the pubkey's header-relevent size
Previously this was an inline test where the specificity was probably judged overly specific. As a class method it makes sense to maintain consistency. And replace some magic values with their constant equivalents.
This commit is contained in:
parent
4a62ddd018
commit
f8c249ab91
4 changed files with 12 additions and 7 deletions
src/script
|
@ -61,17 +61,17 @@ static inline void popstack(std::vector<valtype>& stack)
|
|||
}
|
||||
|
||||
bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
|
||||
if (vchPubKey.size() < 33) {
|
||||
if (vchPubKey.size() < CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
|
||||
// Non-canonical public key: too short
|
||||
return false;
|
||||
}
|
||||
if (vchPubKey[0] == 0x04) {
|
||||
if (vchPubKey.size() != 65) {
|
||||
if (vchPubKey.size() != CPubKey::PUBLIC_KEY_SIZE) {
|
||||
// Non-canonical public key: invalid length for uncompressed key
|
||||
return false;
|
||||
}
|
||||
} else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
|
||||
if (vchPubKey.size() != 33) {
|
||||
if (vchPubKey.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
|
||||
// Non-canonical public key: invalid length for compressed key
|
||||
return false;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
|
|||
}
|
||||
|
||||
bool static IsCompressedPubKey(const valtype &vchPubKey) {
|
||||
if (vchPubKey.size() != 33) {
|
||||
if (vchPubKey.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
|
||||
// Non-canonical public key: invalid length for compressed key
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue