void set16BitCharSet (OOCTXT* pctxt, Asn116BitCharSet* pCharSet, Asn116BitCharSet* pAlphabet) { /* Permitted alphabet range can either be specified as a range of */ /* characters or as a discrete set.. */ if (pAlphabet->charSet.data) { int nocts = pAlphabet->charSet.nchars * 2; pCharSet->charSet.nchars = pAlphabet->charSet.nchars; pCharSet->charSet.data = (ASN116BITCHAR*) ASN1MALLOC (pctxt, nocts); if (pCharSet->charSet.data != NULL) memcpy (pCharSet->charSet.data, pAlphabet->charSet.data, nocts); } else { pCharSet->firstChar = pAlphabet->firstChar; pCharSet->lastChar = pAlphabet->lastChar; pCharSet->charSet.nchars = pCharSet->lastChar - pCharSet->firstChar; } pCharSet->unalignedBits = getUIntBitCount (pCharSet->charSet.nchars); pCharSet->alignedBits = 1; while (pCharSet->unalignedBits > pCharSet->alignedBits) pCharSet->alignedBits <<= 1; }
int encodeConsWholeNumber (OOCTXT* pctxt, ASN1UINT adjusted_value, ASN1UINT range_value) { ASN1UINT nocts, range_bitcnt = getUIntBitCount (range_value - 1); int stat; if (adjusted_value >= range_value && range_value != ASN1UINT_MAX) { return LOG_ASN1ERR (pctxt, ASN_E_RANGERR); } /* If range is <= 255, bit-field case (10.5.7a) */ if (range_value <= 255) { return encodeBits (pctxt, adjusted_value, range_bitcnt); } /* If range is exactly 256, one-octet case (10.5.7b) */ else if (range_value == 256) { stat = encodeByteAlign (pctxt); if (stat != ASN_OK) return LOG_ASN1ERR (pctxt, stat); return encodeBits (pctxt, adjusted_value, 8); } /* If range > 256 and <= 64k (65536), two-octet case (10.5.7c) */ else if (range_value <= 65536) { stat = encodeByteAlign (pctxt); if (stat != ASN_OK) return LOG_ASN1ERR (pctxt, stat); return encodeBits (pctxt, adjusted_value, 16); } /* If range > 64k, indefinite-length case (10.5.7d) */ else { /* Encode length determinant as a constrained whole number. */ /* Constraint is 1 to max number of bytes needed to hold */ /* the target integer value.. */ if (adjusted_value < 256) nocts = 1; else if (adjusted_value < 65536) nocts = 2; else if (adjusted_value < 0x1000000) nocts = 3; else nocts = 4; stat = encodeBits (pctxt, nocts - 1, 2); if (stat != ASN_OK) return LOG_ASN1ERR (pctxt, stat); stat = encodeByteAlign (pctxt); if (stat != ASN_OK) return LOG_ASN1ERR (pctxt, stat); return encodeNonNegBinInt (pctxt, adjusted_value); } }