{"record":{"id":"332f3ee1fc3ef98e","repo":"peass-ng/PEASS-ng","slug":"enumerated-must-be-non-negative","errorCode":null,"errorMessage":"enumerated must be non-negative","messagePattern":"enumerated must be non-negative","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs","lineNumber":55,"sourceCode":"         */\n        public static DerEnumerated GetInstance(\n            Asn1TaggedObject obj,\n            bool isExplicit)\n        {\n            Asn1Object o = obj.GetObject();\n\n            if (isExplicit || o is DerEnumerated)\n            {\n                return GetInstance(o);\n            }\n\n            return FromOctetString(((Asn1OctetString)o).GetOctets());\n        }\n\n        public DerEnumerated(int val)\n        {\n            if (val < 0)\n                throw new ArgumentException(\"enumerated must be non-negative\", \"val\");\n\n            this.bytes = BigInteger.ValueOf(val).ToByteArray();\n            this.start = 0;\n        }\n\n        public DerEnumerated(long val)\n        {\n            if (val < 0L)\n                throw new ArgumentException(\"enumerated must be non-negative\", \"val\");\n\n            this.bytes = BigInteger.ValueOf(val).ToByteArray();\n            this.start = 0;\n        }\n\n        public DerEnumerated(BigInteger val)\n        {\n            if (val.SignValue < 0)\n                throw new ArgumentException(\"enumerated must be non-negative\", \"val\");","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs#L37-L73","documentation":"ASN.1 ENUMERATED values are defined as non-negative. This constructor overload taking an int rejects negative values with an ArgumentException before encoding, because a negative enumerated has no valid DER representation here.","triggerScenarios":"new DerEnumerated(someInt) where someInt < 0, typically when mapping application enums/status codes that use -1 as a sentinel into ASN.1.","commonSituations":"Sending CRL entry reasons, cert status codes, or protocol enumerations where a 'not set' value of -1 is passed straight through; subtracting values that can underflow below zero.","solutions":["Clamp or map negative sentinels to a valid non-negative enumerated value before constructing","Validate val >= 0 at the application boundary and reject earlier with a clearer message","If signed semantics are needed, the type is wrong - use DerInteger instead","Catch ArgumentException to surface which input was negative"],"exampleFix":"// before\nvar e = new DerEnumerated(statusCode);\n// after\nvar e = statusCode >= 0 ? new DerEnumerated(statusCode) : new DerEnumerated(0);","handlingStrategy":"validation","validationCode":"if (val < 0) throw new ArgumentOutOfRangeException(nameof(val), \"enumerated must be non-negative\");","typeGuard":null,"tryCatchPattern":"try { var e = new DerEnumerated(val); }\ncatch (ArgumentException) { /* clamp or reject negative input */ }","preventionTips":["Map -1/-2 sentinels to defined enumerated constants before encoding","Validate enum values at API boundaries","Use DerInteger when signed semantics are needed","Add unit tests for negative status codes"],"tags":["asn1","bouncycastle","enumerated","argumentexception"],"backgroundTag":"asn1-enumerated-negative","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}