P.M.
He sounds like a bright little guy who is scientifically testing the rules. Do they apply to everybody? Do they apply every time? You handled it well. The more clear and unemotional you can be in your response, the more quickly he'll be convinced that the limits are real, and not some arbitrary reaction based on your feelings at the moment.
Another thing you can do is to put a positive spin on the rules: "No hitting – let's do some sweet, happy touching instead!" And use his hand to tenderly stroke yours, or vice versa.
Most littles get through this stage (and on to some other puzzling behavior) fairly quickly. But he will need to hear how consistent the rules are until he is convinced. For some toddlers, that is hourly repetition for many days or weeks.
And most children are most likely to engage in negative behaviors when they are tired, hungry, overstimulated, sick, or already frustrated. At some point, his behaviors may be connected with genuine anger or frustration. It is helpful to give him words for the feelings, and still prohibit the hit or pinch. "Oh, sweetie, you feel so mad. Yes, I understand. You can tell me that any time. And no hitting!"
It is often possible to physically punish a child for his behaviors and discourage it that way. But if he's not being shown alternatives, or allowed to have the legitimate feelings we all have, that approach can eventually backfire.