Skip to content

Commit

Permalink
apply strict enum checking (neo-project#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje authored and Tommo-L committed Jun 22, 2020
1 parent 0be3125 commit 1c326ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/neo/Consensus/ConsensusMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public abstract class ConsensusMessage : ISerializable

protected ConsensusMessage(ConsensusMessageType type)
{
if (!Enum.IsDefined(typeof(ConsensusMessageType), type))
throw new ArgumentOutOfRangeException(nameof(type));
this.Type = type;
}

Expand Down
4 changes: 3 additions & 1 deletion src/neo/Network/P2P/Payloads/TransactionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public JObject ToJson()
public static TransactionAttribute FromJson(JObject json)
{
TransactionAttribute transactionAttribute = new TransactionAttribute();
transactionAttribute.Usage = (TransactionAttributeUsage)(byte.Parse(json["usage"].AsString()));
transactionAttribute.Usage = (TransactionAttributeUsage)byte.Parse(json["usage"].AsString());
if (!Enum.IsDefined(typeof(TransactionAttributeUsage), transactionAttribute.Usage))
throw new ArgumentException();
transactionAttribute.Data = Convert.FromBase64String(json["data"].AsString());
return transactionAttribute;
}
Expand Down
8 changes: 7 additions & 1 deletion src/neo/Wallets/SQLite/VerificationContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ public class VerificationContract : SmartContract.Contract, IEquatable<Verificat
public void Deserialize(BinaryReader reader)
{
reader.ReadSerializable<UInt160>();
ParameterList = reader.ReadVarBytes().Select(p => (ContractParameterType)p).ToArray();
ParameterList = reader.ReadVarBytes().Select(p =>
{
var ret = (ContractParameterType)p;
if (!Enum.IsDefined(typeof(ContractParameterType), ret))
throw new FormatException();
return ret;
}).ToArray();
Script = reader.ReadVarBytes();
}

Expand Down

0 comments on commit 1c326ca

Please sign in to comment.