Codebase list libcryptx-perl / 58c1540
tpc sync Karel Miko 7 years ago
4 changed file(s) with 21 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
678678 int der_decode_utf8_string(const unsigned char *in, unsigned long inlen,
679679 wchar_t *out, unsigned long *outlen);
680680 unsigned long der_utf8_charsize(const wchar_t c);
681 int der_utf8_valid_char(const wchar_t c);
681682 int der_length_utf8_string(const wchar_t *in, unsigned long noctets, unsigned long *outlen);
682683
683684
7070
7171 /* this includes the internal hash ID and optional params (NULL in this case) */
7272 LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, tmpoid, sizeof(tmpoid)/sizeof(tmpoid[0]));
73 LTC_SET_ASN1(alg_id, 1, parameters_type, parameters, parameters_len);
73 LTC_SET_ASN1(alg_id, 1, (ltc_asn1_type)parameters_type, parameters, parameters_len);
7474
7575 /* the actual format of the SSL DER key is odd, it stores a RSAPublicKey
7676 * in a **BIT** string ... so we have to extract it then proceed to convert bit to octet
3636
3737 /* get the size */
3838 for (x = len = 0; x < inlen; x++) {
39 #if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ > 0xFFFF
40 if (in[x] > 0x10FFFF) return CRYPT_INVALID_ARG;
41 #endif
42 #if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ != 0xFFFF && __WCHAR_MAX__ != 0xFFFFFFFF
43 if (in[x] < 0) return CRYPT_INVALID_ARG;
44 #endif
39 if (!der_utf8_valid_char(in[x])) return CRYPT_INVALID_ARG;
4540 len += der_utf8_charsize(in[x]);
4641 }
4742
4040 }
4141
4242 /**
43 Test whether the given code point is valid character
44 @param c The UTF-8 character to test
45 @return 1 - valid, 0 - invalid
46 */
47 int der_utf8_valid_char(const wchar_t c)
48 {
49 LTC_UNUSED_PARAM(c);
50 #if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ > 0xFFFF
51 if (c > 0x10FFFF) return 0;
52 #endif
53 #if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ != 0xFFFF && __WCHAR_MAX__ != 0xFFFFFFFF
54 if (c < 0) return 0;
55 #endif
56 return 1;
57 }
58
59 /**
4360 Gets length of DER encoding of UTF8 STRING
4461 @param in The characters to measure the length of
4562 @param noctets The number of octets in the string to encode
5572
5673 len = 0;
5774 for (x = 0; x < noctets; x++) {
58 #if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ > 0xFFFF
59 if (in[x] > 0x10FFFF) return CRYPT_INVALID_ARG;
60 #endif
61 #if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ != 0xFFFF && __WCHAR_MAX__ != 0xFFFFFFFF
62 if (in[x] < 0) return CRYPT_INVALID_ARG;
63 #endif
75 if (!der_utf8_valid_char(in[x])) return CRYPT_INVALID_ARG;
6476 len += der_utf8_charsize(in[x]);
6577 }
6678