{"record":{"id":"6d4f8cd674a3649d","repo":"peass-ng/PEASS-ng","slug":"must-be-in-the-range-0-to-7","errorCode":null,"errorMessage":"must be in the range 0 to 7","messagePattern":"must be in the range 0 to 7","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerBitString.cs","lineNumber":79,"sourceCode":"            {\n                return GetInstance(o);\n            }\n\n            return FromAsn1Octets(((Asn1OctetString)o).GetOctets());\n        }\n\n        /**\n\t\t * @param data the octets making up the bit string.\n\t\t * @param padBits the number of extra bits at the end of the string.\n\t\t */\n        public DerBitString(\n            byte[] data,\n            int padBits)\n        {\n            if (data == null)\n                throw new ArgumentNullException(\"data\");\n            if (padBits < 0 || padBits > 7)\n                throw new ArgumentException(\"must be in the range 0 to 7\", \"padBits\");\n            if (data.Length == 0 && padBits != 0)\n                throw new ArgumentException(\"if 'data' is empty, 'padBits' must be 0\");\n\n            this.mData = Arrays.Clone(data);\n            this.mPadBits = padBits;\n        }\n\n        public DerBitString(\n            byte[] data)\n            : this(data, 0)\n        {\n        }\n\n        public DerBitString(\n            int namedBits)\n        {\n            if (namedBits == 0)\n            {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerBitString.cs#L61-L97","documentation":"DerBitString's padBits parameter counts the number of unused (padding) bits in the final byte and must be between 0 and 7, since a byte can hold at most 7 unused bits. The constructor throws ArgumentException when padBits is negative or >= 8 to prevent producing an invalid DER BIT STRING encoding.","triggerScenarios":"Calling new DerBitString(data, n) where n < 0 or n > 7 — e.g. passing a bit count, a byte-length, or an unmasked value like data.Length * 8 as padBits.","commonSituations":"Hand-rolling ASN.1 encoders that confuse padBits with total bit length; computing padding from wrong endianness or forgetting to mask a length byte read from a stream.","solutions":["Pass only the number of unused bits in the LAST byte (0–7); for octet-aligned data pass 0.","Compute padBits as (8 - (bitCount % 8)) % 8 rather than passing the raw bit count.","If you have full bytes with no partial bits, use new DerBitString(data) / padBits 0."],"exampleFix":"// before\nint bits = data.Length * 8;\nvar bs = new DerBitString(data, bits); // always throws\n// after\nvar bs = new DerBitString(data, 0); // octet-aligned data uses 0 pad bits","handlingStrategy":"validation","validationCode":"if (padBits < 0 || padBits > 7) throw new ArgumentOutOfRangeException(nameof(padBits), padBits, \"must be 0-7\");","typeGuard":"static bool IsValidPadBits(int p) => p >= 0 && p <= 7;","tryCatchPattern":null,"preventionTips":["Remember padBits = unused bits in the LAST byte, not total bit count","Use (8 - (bits % 8)) % 8 to derive padBits; use 0 for octet-aligned data","Prefer the single-argument DerBitString(byte[]) overload when data is byte-aligned"],"tags":["csharp","asn1","argument-range","bouncycastle","der-encoding"],"backgroundTag":"argument-out-of-range","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}