{"record":{"id":"c29328384b159984","repo":"peass-ng/PEASS-ng","slug":"invalid-encoding-value-c29328","errorCode":null,"errorMessage":"invalid encoding value: ","messagePattern":"invalid encoding value: ","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerExternal.cs","lineNumber":166,"sourceCode":"\n\t\t/**\n\t\t* The encoding of the content. Valid values are\n\t\t* <ul>\n\t\t* <li><code>0</code> single-ASN1-type</li>\n\t\t* <li><code>1</code> OCTET STRING</li>\n\t\t* <li><code>2</code> BIT STRING</li>\n\t\t* </ul>\n\t\t*/\n\t\tpublic int Encoding\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\treturn encoding;\n\t\t\t}\n\t\t\tset\n\t\t\t{\n\t\t\t\tif (encoding < 0 || encoding > 2)\n\t\t\t\t\tthrow new InvalidOperationException(\"invalid encoding value: \" + encoding);\n\n\t\t\t\tthis.encoding = value;\n\t\t\t}\n\t\t}\n\n\t\tpublic Asn1Object ExternalContent\n\t\t{\n\t\t\tget { return externalContent; }\n\t\t\tset { this.externalContent = value; }\n\t\t}\n\n\t\tpublic DerInteger IndirectReference\n\t\t{\n\t\t\tget { return indirectReference; }\n\t\t\tset { this.indirectReference = value; }\n\t\t}\n\n\t\tprivate static Asn1Object GetObjFromVector(Asn1EncodableVector v, int index)","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerExternal.cs#L148-L184","documentation":"The Encoding property setter enforces the same constraint as the constructor: the External encoding value must be 0 (single-ASN1-type), 1 (octet-aligned), or 2 (arbitrary). Assigning any other value throws InvalidOperationException with the offending value appended to the message.","triggerScenarios":"Assigning external.Encoding = n where n < 0 or n > 2 in C# code that builds or mutates a DerExternal instance.","commonSituations":"Application code mapping its own protocol enum onto the Encoding property with out-of-range values; copy/paste code using a sentinel like -1 for 'unknown'; off-by-one constants (e.g. 3) for encodings.","solutions":["Clamp or validate the value before assignment: only 0, 1, or 2 are legal","Map your application's encoding enum to the correct 0-2 range before setting","If the encoding is unknown, don't assign a sentinel — construct a new DerExternal once the real value is known"],"exampleFix":"// before\nexternal.Encoding = encodingId; // may be -1 or 3\n// after\nif (encodingId < 0 || encodingId > 2)\n    throw new ArgumentOutOfRangeException(nameof(encodingId));\nexternal.Encoding = encodingId;","handlingStrategy":"validation","validationCode":"if (encodingValue < 0 || encodingValue > 2)\n    throw new ArgumentOutOfRangeException(nameof(encodingValue), \"External encoding must be 0, 1 or 2\");\nexternal.Encoding = encodingValue;","typeGuard":"static bool IsValidExternalEncoding(int v) => v == 0 || v == 1 || v == 2;","tryCatchPattern":"try { external.Encoding = value; }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"invalid encoding value\")) {\n    // clamp or map the value before retrying\n}","preventionTips":["Treat Encoding as an enum with exactly three members (0-2), not a free int","Map your app's encoding constants to the 0-2 range once, centrally","Never use sentinel values like -1 for 'unset' on this property"],"tags":["asn1","bouncycastle","invalid-operation","property-validation"],"backgroundTag":"invalid-asn1-encoding","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}