| 286 | } |
| 287 | |
| 288 | bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror) { |
| 289 | // Empty signature. Not strictly DER encoded, but allowed to provide a |
| 290 | // compact way to provide an invalid signature for use with CHECK(MULTI)SIG |
| 291 | if (vchSig.size() == 0) { |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | bool no_hash_byte = (flags & SCRIPT_NO_SIGHASH_BYTE) == SCRIPT_NO_SIGHASH_BYTE; |
| 296 | std::vector<unsigned char> vchSigCopy(vchSig.begin(), vchSig.begin() + vchSig.size()); |
| 297 | // Push a dummy sighash byte to pass checks |
| 298 | if (no_hash_byte) { |
| 299 | vchSigCopy.push_back(SIGHASH_ALL); |
| 300 | } |
| 301 | |
| 302 | if ((flags & (SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC)) != 0 && !IsValidSignatureEncoding(vchSigCopy)) { |
| 303 | return set_error(serror, SCRIPT_ERR_SIG_DER); |
| 304 | } else if ((flags & SCRIPT_VERIFY_LOW_S) != 0 && !IsLowDERSignature(vchSigCopy, serror)) { |
| 305 | // serror is set |
| 306 | return false; |
| 307 | } else if ((flags & SCRIPT_VERIFY_STRICTENC) != 0 && !IsDefinedHashtypeSignature(vchSigCopy, flags)) { |
| 308 | return set_error(serror, SCRIPT_ERR_SIG_HASHTYPE); |
| 309 | } |
| 310 | return true; |
| 311 | } |
| 312 | |
| 313 | bool static CheckPubKeyEncoding(const valtype &vchPubKey, unsigned int flags, const SigVersion &sigversion, ScriptError* serror) { |
| 314 | if ((flags & SCRIPT_VERIFY_STRICTENC) != 0 && !IsCompressedOrUncompressedPubKey(vchPubKey)) { |
no test coverage detected