Fix UB when deserializing enums

Some things of note:
1. Functions that check the value of enum must be kept in sync with enum
definitions, which are in a different project, namely, system/keymaster.
2. Deserializing enums from a buffer can leave the buffer in an
inconsistent state if an error is encountered. This should be OK though, since
we don't do anything with the buffer after failing deserialization.

Bug: 181172066
Change-Id: I87257da8faaaa2d34a39fd35553b16d5b1341cfa
1 file changed