checkPubKeyEncoding returns whether or not the passed public key adheres to the strict encoding requirements if enabled.
(pubKey []byte)
| 1246 | // checkPubKeyEncoding returns whether or not the passed public key adheres to |
| 1247 | // the strict encoding requirements if enabled. |
| 1248 | func (vm *Engine) checkPubKeyEncoding(pubKey []byte) error { |
| 1249 | if vm.hasFlag(ScriptVerifyWitnessPubKeyType) && |
| 1250 | vm.isWitnessVersionActive(BaseSegwitWitnessVersion) && |
| 1251 | !btcec.IsCompressedPubKey(pubKey) { |
| 1252 | |
| 1253 | str := "only compressed keys are accepted post-segwit" |
| 1254 | return scriptError(ErrWitnessPubKeyType, str) |
| 1255 | } |
| 1256 | |
| 1257 | if !vm.hasFlag(ScriptVerifyStrictEncoding) { |
| 1258 | return nil |
| 1259 | } |
| 1260 | |
| 1261 | if len(pubKey) == 33 && (pubKey[0] == 0x02 || pubKey[0] == 0x03) { |
| 1262 | // Compressed |
| 1263 | return nil |
| 1264 | } |
| 1265 | if len(pubKey) == 65 && pubKey[0] == 0x04 { |
| 1266 | // Uncompressed |
| 1267 | return nil |
| 1268 | } |
| 1269 | |
| 1270 | return scriptError(ErrPubKeyType, "unsupported public key type") |
| 1271 | } |
| 1272 | |
| 1273 | // checkSignatureEncoding returns whether or not the passed signature adheres to |
| 1274 | // the strict encoding requirements if enabled. |