Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
ead21189
Commit
ead21189
authored
Jul 19, 2006
by
Juan Lang
Committed by
Alexandre Julliard
Jul 19, 2006
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypt32: Implement X509_UNICODE_NAME_VALUE encoding/decoding.
parent
0042c010
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
385 additions
and
0 deletions
+385
-0
crypt32_private.h
dlls/crypt32/crypt32_private.h
+7
-0
decode.c
dlls/crypt32/decode.c
+177
-0
encode.c
dlls/crypt32/encode.c
+0
-0
encode.c
dlls/crypt32/tests/encode.c
+201
-0
No files found.
dlls/crypt32/crypt32_private.h
View file @
ead21189
...
...
@@ -23,13 +23,20 @@
#define ASN_BOOL (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x01)
#define ASN_BITSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x03)
#define ASN_ENUMERATED (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x0a)
#define ASN_UTF8STRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x0c)
#define ASN_SETOF (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x11)
#define ASN_NUMERICSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x12)
#define ASN_PRINTABLESTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x13)
#define ASN_T61STRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x14)
#define ASN_VIDEOTEXSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x15)
#define ASN_IA5STRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x16)
#define ASN_UTCTIME (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x17)
#define ASN_GENERALTIME (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x18)
#define ASN_GRAPHICSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x19)
#define ASN_VISIBLESTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x1a)
#define ASN_GENERALSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x1b)
#define ASN_UNIVERSALSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x1c)
#define ASN_BMPSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x1e)
/* The following aren't defined in wincrypt.h, as they're "reserved" */
#define CERT_CERT_PROP_ID 32
...
...
dlls/crypt32/decode.c
View file @
ead21189
...
...
@@ -42,6 +42,7 @@
#include "winbase.h"
#include "excpt.h"
#include "wincrypt.h"
#include "winnls.h"
#include "winreg.h"
#include "snmp.h"
#include "wine/debug.h"
...
...
@@ -1395,6 +1396,179 @@ static BOOL WINAPI CRYPT_AsnDecodeNameValue(DWORD dwCertEncodingType,
return
ret
;
}
static
BOOL
WINAPI
CRYPT_AsnDecodeUnicodeNameValueInternal
(
DWORD
dwCertEncodingType
,
LPCSTR
lpszStructType
,
const
BYTE
*
pbEncoded
,
DWORD
cbEncoded
,
DWORD
dwFlags
,
PCRYPT_DECODE_PARA
pDecodePara
,
void
*
pvStructInfo
,
DWORD
*
pcbStructInfo
)
{
BOOL
ret
=
TRUE
;
DWORD
dataLen
;
CERT_NAME_VALUE
*
value
=
(
CERT_NAME_VALUE
*
)
pvStructInfo
;
if
((
ret
=
CRYPT_GetLen
(
pbEncoded
,
cbEncoded
,
&
dataLen
)))
{
BYTE
lenBytes
=
GET_LEN_BYTES
(
pbEncoded
[
1
]);
DWORD
bytesNeeded
=
sizeof
(
CERT_NAME_VALUE
),
valueType
;
switch
(
pbEncoded
[
0
])
{
case
ASN_NUMERICSTRING
:
valueType
=
CERT_RDN_NUMERIC_STRING
;
bytesNeeded
+=
(
dataLen
+
1
)
*
2
;
break
;
case
ASN_PRINTABLESTRING
:
valueType
=
CERT_RDN_PRINTABLE_STRING
;
bytesNeeded
+=
(
dataLen
+
1
)
*
2
;
break
;
case
ASN_IA5STRING
:
valueType
=
CERT_RDN_IA5_STRING
;
bytesNeeded
+=
(
dataLen
+
1
)
*
2
;
break
;
case
ASN_T61STRING
:
valueType
=
CERT_RDN_T61_STRING
;
bytesNeeded
+=
(
dataLen
+
1
)
*
2
;
break
;
case
ASN_VIDEOTEXSTRING
:
valueType
=
CERT_RDN_VIDEOTEX_STRING
;
bytesNeeded
+=
(
dataLen
+
1
)
*
2
;
break
;
case
ASN_GRAPHICSTRING
:
valueType
=
CERT_RDN_GRAPHIC_STRING
;
bytesNeeded
+=
(
dataLen
+
1
)
*
2
;
break
;
case
ASN_VISIBLESTRING
:
valueType
=
CERT_RDN_VISIBLE_STRING
;
bytesNeeded
+=
(
dataLen
+
1
)
*
2
;
break
;
case
ASN_GENERALSTRING
:
valueType
=
CERT_RDN_GENERAL_STRING
;
bytesNeeded
+=
(
dataLen
+
1
)
*
2
;
break
;
case
ASN_UNIVERSALSTRING
:
valueType
=
CERT_RDN_UNIVERSAL_STRING
;
bytesNeeded
+=
dataLen
/
2
+
2
;
break
;
case
ASN_BMPSTRING
:
valueType
=
CERT_RDN_BMP_STRING
;
bytesNeeded
+=
dataLen
+
2
;
break
;
case
ASN_UTF8STRING
:
valueType
=
CERT_RDN_UTF8_STRING
;
bytesNeeded
+=
MultiByteToWideChar
(
CP_UTF8
,
0
,
(
LPSTR
)
pbEncoded
+
1
+
lenBytes
,
dataLen
,
NULL
,
0
)
*
2
+
2
;
break
;
default:
SetLastError
(
CRYPT_E_ASN1_BADTAG
);
ret
=
FALSE
;
}
if
(
ret
)
{
if
(
!
value
)
*
pcbStructInfo
=
bytesNeeded
;
else
if
(
*
pcbStructInfo
<
bytesNeeded
)
{
*
pcbStructInfo
=
bytesNeeded
;
SetLastError
(
ERROR_MORE_DATA
);
ret
=
FALSE
;
}
else
{
*
pcbStructInfo
=
bytesNeeded
;
value
->
dwValueType
=
valueType
;
if
(
dataLen
)
{
DWORD
i
;
LPWSTR
str
=
(
LPWSTR
)
value
->
Value
.
pbData
;
assert
(
value
->
Value
.
pbData
);
switch
(
pbEncoded
[
0
])
{
case
ASN_NUMERICSTRING
:
case
ASN_PRINTABLESTRING
:
case
ASN_IA5STRING
:
case
ASN_T61STRING
:
case
ASN_VIDEOTEXSTRING
:
case
ASN_GRAPHICSTRING
:
case
ASN_VISIBLESTRING
:
case
ASN_GENERALSTRING
:
value
->
Value
.
cbData
=
dataLen
*
2
+
2
;
for
(
i
=
0
;
i
<
dataLen
;
i
++
)
str
[
i
]
=
pbEncoded
[
1
+
lenBytes
+
i
];
str
[
i
]
=
0
;
break
;
case
ASN_UNIVERSALSTRING
:
value
->
Value
.
cbData
=
dataLen
/
2
+
2
;
for
(
i
=
0
;
i
<
dataLen
/
4
;
i
++
)
str
[
i
]
=
(
pbEncoded
[
1
+
lenBytes
+
2
*
i
+
2
]
<<
8
)
|
pbEncoded
[
1
+
lenBytes
+
2
*
i
+
3
];
str
[
i
]
=
0
;
break
;
case
ASN_BMPSTRING
:
value
->
Value
.
cbData
=
dataLen
+
2
;
for
(
i
=
0
;
i
<
dataLen
/
2
;
i
++
)
str
[
i
]
=
(
pbEncoded
[
1
+
lenBytes
+
2
*
i
]
<<
8
)
|
pbEncoded
[
1
+
lenBytes
+
2
*
i
+
1
];
str
[
i
]
=
0
;
break
;
case
ASN_UTF8STRING
:
value
->
Value
.
cbData
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
(
LPSTR
)
pbEncoded
+
1
+
lenBytes
,
dataLen
,
str
,
bytesNeeded
-
sizeof
(
CERT_NAME_VALUE
))
*
2
;
str
[
value
->
Value
.
cbData
/
2
]
=
0
;
value
->
Value
.
cbData
+=
2
;
break
;
}
}
else
{
value
->
Value
.
cbData
=
0
;
value
->
Value
.
pbData
=
NULL
;
}
}
}
}
return
ret
;
}
static
BOOL
WINAPI
CRYPT_AsnDecodeUnicodeNameValue
(
DWORD
dwCertEncodingType
,
LPCSTR
lpszStructType
,
const
BYTE
*
pbEncoded
,
DWORD
cbEncoded
,
DWORD
dwFlags
,
PCRYPT_DECODE_PARA
pDecodePara
,
void
*
pvStructInfo
,
DWORD
*
pcbStructInfo
)
{
BOOL
ret
=
TRUE
;
__TRY
{
ret
=
CRYPT_AsnDecodeUnicodeNameValueInternal
(
dwCertEncodingType
,
lpszStructType
,
pbEncoded
,
cbEncoded
,
dwFlags
&
~
CRYPT_DECODE_ALLOC_FLAG
,
NULL
,
NULL
,
pcbStructInfo
);
if
(
ret
&&
pvStructInfo
)
{
ret
=
CRYPT_DecodeEnsureSpace
(
dwFlags
,
pDecodePara
,
pvStructInfo
,
pcbStructInfo
,
*
pcbStructInfo
);
if
(
ret
)
{
CERT_NAME_VALUE
*
value
;
if
(
dwFlags
&
CRYPT_DECODE_ALLOC_FLAG
)
pvStructInfo
=
*
(
BYTE
**
)
pvStructInfo
;
value
=
(
CERT_NAME_VALUE
*
)
pvStructInfo
;
value
->
Value
.
pbData
=
((
BYTE
*
)
value
+
sizeof
(
CERT_NAME_VALUE
));
ret
=
CRYPT_AsnDecodeUnicodeNameValueInternal
(
dwCertEncodingType
,
lpszStructType
,
pbEncoded
,
cbEncoded
,
dwFlags
&
~
CRYPT_DECODE_ALLOC_FLAG
,
NULL
,
pvStructInfo
,
pcbStructInfo
);
}
}
}
__EXCEPT_PAGE_FAULT
{
SetLastError
(
STATUS_ACCESS_VIOLATION
);
ret
=
FALSE
;
}
__ENDTRY
return
ret
;
}
static
BOOL
WINAPI
CRYPT_AsnDecodeRdnAttr
(
DWORD
dwCertEncodingType
,
LPCSTR
lpszStructType
,
const
BYTE
*
pbEncoded
,
DWORD
cbEncoded
,
DWORD
dwFlags
,
PCRYPT_DECODE_PARA
pDecodePara
,
void
*
pvStructInfo
,
DWORD
*
pcbStructInfo
)
...
...
@@ -3190,6 +3364,9 @@ BOOL WINAPI CryptDecodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType,
case
(
WORD
)
RSA_CSP_PUBLICKEYBLOB
:
decodeFunc
=
CRYPT_AsnDecodeRsaPubKey
;
break
;
case
(
WORD
)
X509_UNICODE_NAME_VALUE
:
decodeFunc
=
CRYPT_AsnDecodeUnicodeNameValue
;
break
;
case
(
WORD
)
X509_OCTET_STRING
:
decodeFunc
=
CRYPT_AsnDecodeOctets
;
break
;
...
...
dlls/crypt32/encode.c
View file @
ead21189
This diff is collapsed.
Click to expand it.
dlls/crypt32/tests/encode.c
View file @
ead21189
...
...
@@ -1199,6 +1199,205 @@ static void test_decodeAltName(DWORD dwEncoding)
}
}
struct
UnicodeExpectedError
{
DWORD
valueType
;
LPCWSTR
str
;
DWORD
errorIndex
;
DWORD
error
;
};
static
const
WCHAR
oneW
[]
=
{
'1'
,
0
};
static
const
WCHAR
aW
[]
=
{
'a'
,
0
};
static
const
WCHAR
quoteW
[]
=
{
'"'
,
0
};
static
struct
UnicodeExpectedError
unicodeErrors
[]
=
{
{
CERT_RDN_ANY_TYPE
,
oneW
,
0
,
CRYPT_E_NOT_CHAR_STRING
},
{
CERT_RDN_ENCODED_BLOB
,
oneW
,
0
,
CRYPT_E_NOT_CHAR_STRING
},
{
CERT_RDN_OCTET_STRING
,
oneW
,
0
,
CRYPT_E_NOT_CHAR_STRING
},
{
14
,
oneW
,
0
,
CRYPT_E_ASN1_CHOICE
},
{
CERT_RDN_NUMERIC_STRING
,
aW
,
0
,
CRYPT_E_INVALID_NUMERIC_STRING
},
{
CERT_RDN_PRINTABLE_STRING
,
quoteW
,
0
,
CRYPT_E_INVALID_PRINTABLE_STRING
},
{
CERT_RDN_IA5_STRING
,
nihongoURL
,
7
,
CRYPT_E_INVALID_IA5_STRING
},
};
struct
UnicodeExpectedResult
{
DWORD
valueType
;
LPCWSTR
str
;
CRYPT_DATA_BLOB
encoded
;
};
static
BYTE
oneNumeric
[]
=
{
0x12
,
0x01
,
0x31
};
static
BYTE
onePrintable
[]
=
{
0x13
,
0x01
,
0x31
};
static
BYTE
oneTeletex
[]
=
{
0x14
,
0x01
,
0x31
};
static
BYTE
oneVideotex
[]
=
{
0x15
,
0x01
,
0x31
};
static
BYTE
oneIA5
[]
=
{
0x16
,
0x01
,
0x31
};
static
BYTE
oneGraphic
[]
=
{
0x19
,
0x01
,
0x31
};
static
BYTE
oneVisible
[]
=
{
0x1a
,
0x01
,
0x31
};
static
BYTE
oneUniversal
[]
=
{
0x1c
,
0x04
,
0x00
,
0x00
,
0x00
,
0x31
};
static
BYTE
oneGeneral
[]
=
{
0x1b
,
0x01
,
0x31
};
static
BYTE
oneBMP
[]
=
{
0x1e
,
0x02
,
0x00
,
0x31
};
static
BYTE
oneUTF8
[]
=
{
0x0c
,
0x01
,
0x31
};
static
BYTE
nihongoT61
[]
=
{
0x14
,
0x09
,
0x68
,
0x74
,
0x74
,
0x70
,
0x3a
,
0x2f
,
0x2f
,
0x6f
,
0x5b
};
static
BYTE
nihongoGeneral
[]
=
{
0x1b
,
0x09
,
0x68
,
0x74
,
0x74
,
0x70
,
0x3a
,
0x2f
,
0x2f
,
0x6f
,
0x5b
};
static
BYTE
nihongoBMP
[]
=
{
0x1e
,
0x12
,
0x00
,
0x68
,
0x00
,
0x74
,
0x00
,
0x74
,
0x00
,
0x70
,
0x00
,
0x3a
,
0x00
,
0x2f
,
0x00
,
0x2f
,
0x22
,
0x6f
,
0x57
,
0x5b
};
static
BYTE
nihongoUTF8
[]
=
{
0x0c
,
0x0d
,
0x68
,
0x74
,
0x74
,
0x70
,
0x3a
,
0x2f
,
0x2f
,
0xe2
,
0x89
,
0xaf
,
0xe5
,
0x9d
,
0x9b
};
static
struct
UnicodeExpectedResult
unicodeResults
[]
=
{
{
CERT_RDN_NUMERIC_STRING
,
oneW
,
{
sizeof
(
oneNumeric
),
oneNumeric
}
},
{
CERT_RDN_PRINTABLE_STRING
,
oneW
,
{
sizeof
(
onePrintable
),
onePrintable
}
},
{
CERT_RDN_TELETEX_STRING
,
oneW
,
{
sizeof
(
oneTeletex
),
oneTeletex
}
},
{
CERT_RDN_VIDEOTEX_STRING
,
oneW
,
{
sizeof
(
oneVideotex
),
oneVideotex
}
},
{
CERT_RDN_IA5_STRING
,
oneW
,
{
sizeof
(
oneIA5
),
oneIA5
}
},
{
CERT_RDN_GRAPHIC_STRING
,
oneW
,
{
sizeof
(
oneGraphic
),
oneGraphic
}
},
{
CERT_RDN_VISIBLE_STRING
,
oneW
,
{
sizeof
(
oneVisible
),
oneVisible
}
},
{
CERT_RDN_UNIVERSAL_STRING
,
oneW
,
{
sizeof
(
oneUniversal
),
oneUniversal
}
},
{
CERT_RDN_GENERAL_STRING
,
oneW
,
{
sizeof
(
oneGeneral
),
oneGeneral
}
},
{
CERT_RDN_BMP_STRING
,
oneW
,
{
sizeof
(
oneBMP
),
oneBMP
}
},
{
CERT_RDN_UTF8_STRING
,
oneW
,
{
sizeof
(
oneUTF8
),
oneUTF8
}
},
{
CERT_RDN_BMP_STRING
,
nihongoURL
,
{
sizeof
(
nihongoBMP
),
nihongoBMP
}
},
{
CERT_RDN_UTF8_STRING
,
nihongoURL
,
{
sizeof
(
nihongoUTF8
),
nihongoUTF8
}
},
};
static
struct
UnicodeExpectedResult
unicodeWeirdness
[]
=
{
{
CERT_RDN_TELETEX_STRING
,
nihongoURL
,
{
sizeof
(
nihongoT61
),
nihongoT61
}
},
{
CERT_RDN_GENERAL_STRING
,
nihongoURL
,
{
sizeof
(
nihongoGeneral
),
nihongoGeneral
}
},
};
static
void
test_encodeUnicodeNameValue
(
DWORD
dwEncoding
)
{
BYTE
*
buf
=
NULL
;
DWORD
size
=
0
,
i
;
BOOL
ret
;
CERT_NAME_VALUE
value
;
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
NULL
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
!
ret
&&
GetLastError
()
==
STATUS_ACCESS_VIOLATION
,
"Expected STATUS_ACCESS_VIOLATION, got %08lx
\n
"
,
GetLastError
());
/* Have to have a string of some sort */
value
.
dwValueType
=
0
;
/* aka CERT_RDN_ANY_TYPE */
value
.
Value
.
pbData
=
NULL
;
value
.
Value
.
cbData
=
0
;
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
&
value
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
!
ret
&&
GetLastError
()
==
CRYPT_E_NOT_CHAR_STRING
,
"Expected CRYPT_E_NOT_CHAR_STRING, got %08lx
\n
"
,
GetLastError
());
value
.
dwValueType
=
CERT_RDN_ENCODED_BLOB
;
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
&
value
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
!
ret
&&
GetLastError
()
==
CRYPT_E_NOT_CHAR_STRING
,
"Expected CRYPT_E_NOT_CHAR_STRING, got %08lx
\n
"
,
GetLastError
());
value
.
dwValueType
=
CERT_RDN_ANY_TYPE
;
value
.
Value
.
pbData
=
(
LPBYTE
)
oneW
;
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
&
value
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
!
ret
&&
GetLastError
()
==
CRYPT_E_NOT_CHAR_STRING
,
"Expected CRYPT_E_NOT_CHAR_STRING, got %08lx
\n
"
,
GetLastError
());
value
.
Value
.
cbData
=
sizeof
(
oneW
);
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
&
value
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
!
ret
&&
GetLastError
()
==
CRYPT_E_NOT_CHAR_STRING
,
"Expected CRYPT_E_NOT_CHAR_STRING, got %08lx
\n
"
,
GetLastError
());
/* An encoded string with specified length isn't good enough either */
value
.
dwValueType
=
CERT_RDN_ENCODED_BLOB
;
value
.
Value
.
pbData
=
oneUniversal
;
value
.
Value
.
cbData
=
sizeof
(
oneUniversal
);
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
&
value
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
!
ret
&&
GetLastError
()
==
CRYPT_E_NOT_CHAR_STRING
,
"Expected CRYPT_E_NOT_CHAR_STRING, got %08lx
\n
"
,
GetLastError
());
/* More failure checking */
value
.
Value
.
cbData
=
0
;
for
(
i
=
0
;
i
<
sizeof
(
unicodeErrors
)
/
sizeof
(
unicodeErrors
[
0
]);
i
++
)
{
value
.
Value
.
pbData
=
(
LPBYTE
)
unicodeErrors
[
i
].
str
;
value
.
dwValueType
=
unicodeErrors
[
i
].
valueType
;
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
&
value
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
!
ret
&&
GetLastError
()
==
unicodeErrors
[
i
].
error
,
"Value type %ld: expected %08lx, got %08lx
\n
"
,
value
.
dwValueType
,
unicodeErrors
[
i
].
error
,
GetLastError
());
ok
(
size
==
unicodeErrors
[
i
].
errorIndex
,
"Expected error index %ld, got %ld
\n
"
,
unicodeErrors
[
i
].
errorIndex
,
size
);
}
/* cbData can be zero if the string is NULL-terminated */
value
.
Value
.
cbData
=
0
;
for
(
i
=
0
;
i
<
sizeof
(
unicodeResults
)
/
sizeof
(
unicodeResults
[
0
]);
i
++
)
{
value
.
Value
.
pbData
=
(
LPBYTE
)
unicodeResults
[
i
].
str
;
value
.
dwValueType
=
unicodeResults
[
i
].
valueType
;
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
&
value
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
ret
,
"CryptEncodeObjectEx failed: %08lx
\n
"
,
GetLastError
());
if
(
buf
)
{
ok
(
size
==
unicodeResults
[
i
].
encoded
.
cbData
,
"Value type %ld: expected size %ld, got %ld
\n
"
,
value
.
dwValueType
,
unicodeResults
[
i
].
encoded
.
cbData
,
size
);
ok
(
!
memcmp
(
unicodeResults
[
i
].
encoded
.
pbData
,
buf
,
size
),
"Value type %ld: unexpected value
\n
"
,
value
.
dwValueType
);
LocalFree
(
buf
);
}
}
/* These "encode," but they do so by truncating each unicode character
* rather than properly encoding it. Kept separate from the proper results,
* because the encoded forms won't decode to their original strings.
*/
for
(
i
=
0
;
i
<
sizeof
(
unicodeWeirdness
)
/
sizeof
(
unicodeWeirdness
[
0
]);
i
++
)
{
value
.
Value
.
pbData
=
(
LPBYTE
)
unicodeWeirdness
[
i
].
str
;
value
.
dwValueType
=
unicodeWeirdness
[
i
].
valueType
;
ret
=
CryptEncodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
&
value
,
CRYPT_ENCODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
ret
,
"CryptEncodeObjectEx failed: %08lx
\n
"
,
GetLastError
());
if
(
buf
)
{
ok
(
size
==
unicodeWeirdness
[
i
].
encoded
.
cbData
,
"Value type %ld: expected size %ld, got %ld
\n
"
,
value
.
dwValueType
,
unicodeWeirdness
[
i
].
encoded
.
cbData
,
size
);
ok
(
!
memcmp
(
unicodeWeirdness
[
i
].
encoded
.
pbData
,
buf
,
size
),
"Value type %ld: unexpected value
\n
"
,
value
.
dwValueType
);
LocalFree
(
buf
);
}
}
}
static
void
test_decodeUnicodeNameValue
(
DWORD
dwEncoding
)
{
DWORD
i
;
for
(
i
=
0
;
i
<
sizeof
(
unicodeResults
)
/
sizeof
(
unicodeResults
[
0
]);
i
++
)
{
BYTE
*
buf
=
NULL
;
BOOL
ret
;
DWORD
size
=
0
;
ret
=
CryptDecodeObjectEx
(
dwEncoding
,
X509_UNICODE_NAME_VALUE
,
unicodeResults
[
i
].
encoded
.
pbData
,
unicodeResults
[
i
].
encoded
.
cbData
,
CRYPT_DECODE_ALLOC_FLAG
,
NULL
,
(
BYTE
*
)
&
buf
,
&
size
);
ok
(
ret
,
"CryptDecodeObjectEx failed: %08lx
\n
"
,
GetLastError
());
if
(
ret
&&
buf
)
{
PCERT_NAME_VALUE
value
=
(
PCERT_NAME_VALUE
)
buf
;
ok
(
value
->
dwValueType
==
unicodeResults
[
i
].
valueType
,
"Expected value type %ld, got %ld
\n
"
,
unicodeResults
[
i
].
valueType
,
value
->
dwValueType
);
ok
(
!
lstrcmpW
((
LPWSTR
)
value
->
Value
.
pbData
,
unicodeResults
[
i
].
str
),
"Unexpected decoded value for index %ld (value type %ld)
\n
"
,
i
,
unicodeResults
[
i
].
valueType
);
LocalFree
(
buf
);
}
}
}
struct
encodedOctets
{
const
BYTE
*
val
;
...
...
@@ -3392,6 +3591,8 @@ START_TEST(encode)
test_decodeName
(
encodings
[
i
]);
test_encodeNameValue
(
encodings
[
i
]);
test_decodeNameValue
(
encodings
[
i
]);
test_encodeUnicodeNameValue
(
encodings
[
i
]);
test_decodeUnicodeNameValue
(
encodings
[
i
]);
test_encodeAltName
(
encodings
[
i
]);
test_decodeAltName
(
encodings
[
i
]);
test_encodeOctets
(
encodings
[
i
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment