/**
   Gets length of DER encoding of Printable STRING
   @param octets   The values you want to encode
   @param noctets  The number of octets in the string to encode
   @param outlen   [out] The length of the DER encoding for the given string
   @return CRYPT_OK if successful
 */
int der_length_printable_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen) {
    unsigned long x;

    LTC_ARGCHK(outlen != NULL);
    LTC_ARGCHK(octets != NULL);

    /* scan string for validity */
    for (x = 0; x < noctets; x++) {
        if (der_printable_char_encode(octets[x]) == -1) {
            return CRYPT_INVALID_ARG;
        }
    }

    if (noctets < 128) {
        /* 16 LL DD DD DD ... */
        *outlen = 2 + noctets;
    } else if (noctets < 256) {
        /* 16 81 LL DD DD DD ... */
        *outlen = 3 + noctets;
    } else if (noctets < 65536UL) {
        /* 16 82 LL LL DD DD DD ... */
        *outlen = 4 + noctets;
    } else if (noctets < 16777216UL) {
        /* 16 83 LL LL LL DD DD DD ... */
        *outlen = 5 + noctets;
    } else {
        return CRYPT_INVALID_ARG;
    }

    return CRYPT_OK;
}
/**
  Gets length of DER encoding of Printable STRING
  @param octets   The values you want to encode
  @param noctets  The number of octets in the string to encode
  @param outlen   [out] The length of the DER encoding for the given string
  @return CRYPT_OK if successful
*/
int der_length_printable_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen)
{
   unsigned long x;
   int err;

   LTC_ARGCHK(outlen != NULL);
   LTC_ARGCHK(octets != NULL);

   /* scan string for validity */
   for (x = 0; x < noctets; x++) {
       if (der_printable_char_encode(octets[x]) == -1) {
          return CRYPT_INVALID_ARG;
       }
   }

   if ((err = der_length_asn1_length(noctets, &x)) != CRYPT_OK) {
      return err;
   }
   *outlen = 1 + x + noctets;

   return CRYPT_OK;
}