Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1380 lines
46 KiB

  1. /* Copyright (C) Microsoft Corporation, 1996-1999. All rights reserved. */
  2. /* ASN.1 definitions for X509 v3 certificates */
  3. //
  4. // ASN1C needs to be defined so that the compiler does not pickup the ASN1 routines from
  5. // the import table
  6. //
  7. #ifdef _X86_
  8. #define ASN1C
  9. #endif
  10. #pragma warning(disable:4201) // nonstandard extension used : nameless struct/union
  11. #include <windows.h>
  12. #include "xmsasn.h"
  13. ASN1module_t XMSASN_Module = NULL;
  14. static int ASN1CALL ASN1Enc_EnhancedKeyUsage(ASN1encoding_t enc, ASN1uint32_t tag, EnhancedKeyUsage *val);
  15. static int ASN1CALL ASN1Enc_RequestFlags(ASN1encoding_t enc, ASN1uint32_t tag, RequestFlags *val);
  16. static int ASN1CALL ASN1Enc_CSPProvider(ASN1encoding_t enc, ASN1uint32_t tag, CSPProvider *val);
  17. static int ASN1CALL ASN1Enc_EnrollmentNameValuePair(ASN1encoding_t enc, ASN1uint32_t tag, EnrollmentNameValuePair *val);
  18. static int ASN1CALL ASN1Enc_Extensions(ASN1encoding_t enc, ASN1uint32_t tag, Extensions *val);
  19. static int ASN1CALL ASN1Enc_Extension(ASN1encoding_t enc, ASN1uint32_t tag, Extension *val);
  20. static int ASN1CALL ASN1Enc_AttributeSetValue(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValue *val);
  21. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val);
  22. static int ASN1CALL ASN1Enc_ControlSequence(ASN1encoding_t enc, ASN1uint32_t tag, ControlSequence *val);
  23. static int ASN1CALL ASN1Enc_ReqSequence(ASN1encoding_t enc, ASN1uint32_t tag, ReqSequence *val);
  24. static int ASN1CALL ASN1Enc_CmsSequence(ASN1encoding_t enc, ASN1uint32_t tag, CmsSequence *val);
  25. static int ASN1CALL ASN1Enc_OtherMsgSequence(ASN1encoding_t enc, ASN1uint32_t tag, OtherMsgSequence *val);
  26. static int ASN1CALL ASN1Enc_BodyPartIDSequence(ASN1encoding_t enc, ASN1uint32_t tag, BodyPartIDSequence *val);
  27. static int ASN1CALL ASN1Enc_TaggedAttribute(ASN1encoding_t enc, ASN1uint32_t tag, TaggedAttribute *val);
  28. static int ASN1CALL ASN1Enc_TaggedCertificationRequest(ASN1encoding_t enc, ASN1uint32_t tag, TaggedCertificationRequest *val);
  29. static int ASN1CALL ASN1Enc_TaggedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, TaggedContentInfo *val);
  30. static int ASN1CALL ASN1Enc_TaggedOtherMsg(ASN1encoding_t enc, ASN1uint32_t tag, TaggedOtherMsg *val);
  31. static int ASN1CALL ASN1Enc_PendInfo(ASN1encoding_t enc, ASN1uint32_t tag, PendInfo *val);
  32. static int ASN1CALL ASN1Enc_CmcAddExtensions(ASN1encoding_t enc, ASN1uint32_t tag, CmcAddExtensions *val);
  33. static int ASN1CALL ASN1Enc_CmcAddAttributes(ASN1encoding_t enc, ASN1uint32_t tag, CmcAddAttributes *val);
  34. static int ASN1CALL ASN1Enc_CmcStatusInfo_otherInfo(ASN1encoding_t enc, ASN1uint32_t tag, CmcStatusInfo_otherInfo *val);
  35. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val);
  36. static int ASN1CALL ASN1Enc_CmcData(ASN1encoding_t enc, ASN1uint32_t tag, CmcData *val);
  37. static int ASN1CALL ASN1Enc_CmcResponseBody(ASN1encoding_t enc, ASN1uint32_t tag, CmcResponseBody *val);
  38. static int ASN1CALL ASN1Enc_TaggedRequest(ASN1encoding_t enc, ASN1uint32_t tag, TaggedRequest *val);
  39. static int ASN1CALL ASN1Enc_CmcStatusInfo(ASN1encoding_t enc, ASN1uint32_t tag, CmcStatusInfo *val);
  40. static int ASN1CALL ASN1Dec_EnhancedKeyUsage(ASN1decoding_t dec, ASN1uint32_t tag, EnhancedKeyUsage *val);
  41. static int ASN1CALL ASN1Dec_RequestFlags(ASN1decoding_t dec, ASN1uint32_t tag, RequestFlags *val);
  42. static int ASN1CALL ASN1Dec_CSPProvider(ASN1decoding_t dec, ASN1uint32_t tag, CSPProvider *val);
  43. static int ASN1CALL ASN1Dec_EnrollmentNameValuePair(ASN1decoding_t dec, ASN1uint32_t tag, EnrollmentNameValuePair *val);
  44. static int ASN1CALL ASN1Dec_Extensions(ASN1decoding_t dec, ASN1uint32_t tag, Extensions *val);
  45. static int ASN1CALL ASN1Dec_Extension(ASN1decoding_t dec, ASN1uint32_t tag, Extension *val);
  46. static int ASN1CALL ASN1Dec_AttributeSetValue(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValue *val);
  47. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val);
  48. static int ASN1CALL ASN1Dec_ControlSequence(ASN1decoding_t dec, ASN1uint32_t tag, ControlSequence *val);
  49. static int ASN1CALL ASN1Dec_ReqSequence(ASN1decoding_t dec, ASN1uint32_t tag, ReqSequence *val);
  50. static int ASN1CALL ASN1Dec_CmsSequence(ASN1decoding_t dec, ASN1uint32_t tag, CmsSequence *val);
  51. static int ASN1CALL ASN1Dec_OtherMsgSequence(ASN1decoding_t dec, ASN1uint32_t tag, OtherMsgSequence *val);
  52. static int ASN1CALL ASN1Dec_BodyPartIDSequence(ASN1decoding_t dec, ASN1uint32_t tag, BodyPartIDSequence *val);
  53. static int ASN1CALL ASN1Dec_TaggedAttribute(ASN1decoding_t dec, ASN1uint32_t tag, TaggedAttribute *val);
  54. static int ASN1CALL ASN1Dec_TaggedCertificationRequest(ASN1decoding_t dec, ASN1uint32_t tag, TaggedCertificationRequest *val);
  55. static int ASN1CALL ASN1Dec_TaggedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, TaggedContentInfo *val);
  56. static int ASN1CALL ASN1Dec_TaggedOtherMsg(ASN1decoding_t dec, ASN1uint32_t tag, TaggedOtherMsg *val);
  57. static int ASN1CALL ASN1Dec_PendInfo(ASN1decoding_t dec, ASN1uint32_t tag, PendInfo *val);
  58. static int ASN1CALL ASN1Dec_CmcAddExtensions(ASN1decoding_t dec, ASN1uint32_t tag, CmcAddExtensions *val);
  59. static int ASN1CALL ASN1Dec_CmcAddAttributes(ASN1decoding_t dec, ASN1uint32_t tag, CmcAddAttributes *val);
  60. static int ASN1CALL ASN1Dec_CmcStatusInfo_otherInfo(ASN1decoding_t dec, ASN1uint32_t tag, CmcStatusInfo_otherInfo *val);
  61. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val);
  62. static int ASN1CALL ASN1Dec_CmcData(ASN1decoding_t dec, ASN1uint32_t tag, CmcData *val);
  63. static int ASN1CALL ASN1Dec_CmcResponseBody(ASN1decoding_t dec, ASN1uint32_t tag, CmcResponseBody *val);
  64. static int ASN1CALL ASN1Dec_TaggedRequest(ASN1decoding_t dec, ASN1uint32_t tag, TaggedRequest *val);
  65. static int ASN1CALL ASN1Dec_CmcStatusInfo(ASN1decoding_t dec, ASN1uint32_t tag, CmcStatusInfo *val);
  66. static void ASN1CALL ASN1Free_EnhancedKeyUsage(EnhancedKeyUsage *val);
  67. static void ASN1CALL ASN1Free_CSPProvider(CSPProvider *val);
  68. static void ASN1CALL ASN1Free_EnrollmentNameValuePair(EnrollmentNameValuePair *val);
  69. static void ASN1CALL ASN1Free_Extensions(Extensions *val);
  70. static void ASN1CALL ASN1Free_Extension(Extension *val);
  71. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val);
  72. static void ASN1CALL ASN1Free_Attributes(Attributes *val);
  73. static void ASN1CALL ASN1Free_ControlSequence(ControlSequence *val);
  74. static void ASN1CALL ASN1Free_ReqSequence(ReqSequence *val);
  75. static void ASN1CALL ASN1Free_CmsSequence(CmsSequence *val);
  76. static void ASN1CALL ASN1Free_OtherMsgSequence(OtherMsgSequence *val);
  77. static void ASN1CALL ASN1Free_BodyPartIDSequence(BodyPartIDSequence *val);
  78. static void ASN1CALL ASN1Free_TaggedAttribute(TaggedAttribute *val);
  79. static void ASN1CALL ASN1Free_TaggedCertificationRequest(TaggedCertificationRequest *val);
  80. static void ASN1CALL ASN1Free_TaggedContentInfo(TaggedContentInfo *val);
  81. static void ASN1CALL ASN1Free_TaggedOtherMsg(TaggedOtherMsg *val);
  82. static void ASN1CALL ASN1Free_PendInfo(PendInfo *val);
  83. static void ASN1CALL ASN1Free_CmcAddExtensions(CmcAddExtensions *val);
  84. static void ASN1CALL ASN1Free_CmcAddAttributes(CmcAddAttributes *val);
  85. static void ASN1CALL ASN1Free_CmcStatusInfo_otherInfo(CmcStatusInfo_otherInfo *val);
  86. static void ASN1CALL ASN1Free_Attribute(Attribute *val);
  87. static void ASN1CALL ASN1Free_CmcData(CmcData *val);
  88. static void ASN1CALL ASN1Free_CmcResponseBody(CmcResponseBody *val);
  89. static void ASN1CALL ASN1Free_TaggedRequest(TaggedRequest *val);
  90. static void ASN1CALL ASN1Free_CmcStatusInfo(CmcStatusInfo *val);
  91. typedef ASN1BerEncFun_t ASN1EncFun_t;
  92. static const ASN1EncFun_t encfntab[9] = {
  93. (ASN1EncFun_t) ASN1Enc_EnhancedKeyUsage,
  94. (ASN1EncFun_t) ASN1Enc_RequestFlags,
  95. (ASN1EncFun_t) ASN1Enc_CSPProvider,
  96. (ASN1EncFun_t) ASN1Enc_EnrollmentNameValuePair,
  97. (ASN1EncFun_t) ASN1Enc_CmcAddExtensions,
  98. (ASN1EncFun_t) ASN1Enc_CmcAddAttributes,
  99. (ASN1EncFun_t) ASN1Enc_CmcData,
  100. (ASN1EncFun_t) ASN1Enc_CmcResponseBody,
  101. (ASN1EncFun_t) ASN1Enc_CmcStatusInfo,
  102. };
  103. typedef ASN1BerDecFun_t ASN1DecFun_t;
  104. static const ASN1DecFun_t decfntab[9] = {
  105. (ASN1DecFun_t) ASN1Dec_EnhancedKeyUsage,
  106. (ASN1DecFun_t) ASN1Dec_RequestFlags,
  107. (ASN1DecFun_t) ASN1Dec_CSPProvider,
  108. (ASN1DecFun_t) ASN1Dec_EnrollmentNameValuePair,
  109. (ASN1DecFun_t) ASN1Dec_CmcAddExtensions,
  110. (ASN1DecFun_t) ASN1Dec_CmcAddAttributes,
  111. (ASN1DecFun_t) ASN1Dec_CmcData,
  112. (ASN1DecFun_t) ASN1Dec_CmcResponseBody,
  113. (ASN1DecFun_t) ASN1Dec_CmcStatusInfo,
  114. };
  115. static const ASN1FreeFun_t freefntab[9] = {
  116. (ASN1FreeFun_t) ASN1Free_EnhancedKeyUsage,
  117. (ASN1FreeFun_t) NULL,
  118. (ASN1FreeFun_t) ASN1Free_CSPProvider,
  119. (ASN1FreeFun_t) ASN1Free_EnrollmentNameValuePair,
  120. (ASN1FreeFun_t) ASN1Free_CmcAddExtensions,
  121. (ASN1FreeFun_t) ASN1Free_CmcAddAttributes,
  122. (ASN1FreeFun_t) ASN1Free_CmcData,
  123. (ASN1FreeFun_t) ASN1Free_CmcResponseBody,
  124. (ASN1FreeFun_t) ASN1Free_CmcStatusInfo,
  125. };
  126. static const ULONG sizetab[9] = {
  127. SIZE_XMSASN_Module_PDU_0,
  128. SIZE_XMSASN_Module_PDU_1,
  129. SIZE_XMSASN_Module_PDU_2,
  130. SIZE_XMSASN_Module_PDU_3,
  131. SIZE_XMSASN_Module_PDU_4,
  132. SIZE_XMSASN_Module_PDU_5,
  133. SIZE_XMSASN_Module_PDU_6,
  134. SIZE_XMSASN_Module_PDU_7,
  135. SIZE_XMSASN_Module_PDU_8,
  136. };
  137. /* forward declarations of values: */
  138. /* definitions of value components: */
  139. /* definitions of values: */
  140. ASN1bool_t Extension_critical_default = 0;
  141. void ASN1CALL XMSASN_Module_Startup(void)
  142. {
  143. XMSASN_Module = ASN1_CreateModule(0x10000, ASN1_BER_RULE_DER, ASN1FLAGS_NOASSERT, 9, (const ASN1GenericFun_t *) encfntab, (const ASN1GenericFun_t *) decfntab, freefntab, sizetab, 0x726e6578);
  144. }
  145. void ASN1CALL XMSASN_Module_Cleanup(void)
  146. {
  147. ASN1_CloseModule(XMSASN_Module);
  148. XMSASN_Module = NULL;
  149. }
  150. static int ASN1CALL ASN1Enc_EnhancedKeyUsage(ASN1encoding_t enc, ASN1uint32_t tag, EnhancedKeyUsage *val)
  151. {
  152. ASN1uint32_t nLenOff;
  153. ASN1uint32_t i;
  154. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  155. return 0;
  156. for (i = 0; i < (val)->count; i++) {
  157. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &((val)->value)[i]))
  158. return 0;
  159. }
  160. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  161. return 0;
  162. return 1;
  163. }
  164. static int ASN1CALL ASN1Dec_EnhancedKeyUsage(ASN1decoding_t dec, ASN1uint32_t tag, EnhancedKeyUsage *val)
  165. {
  166. ASN1decoding_t dd;
  167. ASN1octet_t *di;
  168. ASN1uint32_t t;
  169. ASN1uint32_t n;
  170. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  171. return 0;
  172. (val)->count = n = 0;
  173. (val)->value = NULL;
  174. while (ASN1BERDecNotEndOfContents(dd, di)) {
  175. if (!ASN1BERDecPeekTag(dd, &t))
  176. return 0;
  177. if ((val)->count >= n) {
  178. n = n ? (n << 1) : 16;
  179. (val)->value = (UsageIdentifier *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  180. if (!(val)->value)
  181. return 0;
  182. }
  183. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &((val)->value)[(val)->count]))
  184. return 0;
  185. ((val)->count)++;
  186. }
  187. if (!ASN1BERDecEndOfContents(dec, dd, di))
  188. return 0;
  189. return 1;
  190. }
  191. static void ASN1CALL ASN1Free_EnhancedKeyUsage(EnhancedKeyUsage *val)
  192. {
  193. ASN1uint32_t i;
  194. if (val) {
  195. for (i = 1; i < (val)->count; i++) {
  196. }
  197. ASN1Free((val)->value);
  198. }
  199. }
  200. static int ASN1CALL ASN1Enc_RequestFlags(ASN1encoding_t enc, ASN1uint32_t tag, RequestFlags *val)
  201. {
  202. ASN1uint32_t nLenOff;
  203. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  204. return 0;
  205. if (!ASN1BEREncBool(enc, 0x1, (val)->fWriteToCSP))
  206. return 0;
  207. if (!ASN1BEREncBool(enc, 0x1, (val)->fWriteToDS))
  208. return 0;
  209. if (!ASN1BEREncS32(enc, 0x2, (val)->openFlags))
  210. return 0;
  211. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  212. return 0;
  213. return 1;
  214. }
  215. static int ASN1CALL ASN1Dec_RequestFlags(ASN1decoding_t dec, ASN1uint32_t tag, RequestFlags *val)
  216. {
  217. ASN1decoding_t dd;
  218. ASN1octet_t *di;
  219. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  220. return 0;
  221. if (!ASN1BERDecBool(dd, 0x1, &(val)->fWriteToCSP))
  222. return 0;
  223. if (!ASN1BERDecBool(dd, 0x1, &(val)->fWriteToDS))
  224. return 0;
  225. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->openFlags))
  226. return 0;
  227. if (!ASN1BERDecEndOfContents(dec, dd, di))
  228. return 0;
  229. return 1;
  230. }
  231. static int ASN1CALL ASN1Enc_CSPProvider(ASN1encoding_t enc, ASN1uint32_t tag, CSPProvider *val)
  232. {
  233. ASN1uint32_t nLenOff;
  234. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  235. return 0;
  236. if (!ASN1BEREncS32(enc, 0x2, (val)->keySpec))
  237. return 0;
  238. if (!ASN1DEREncChar16String(enc, 0x1e, ((val)->cspName).length, ((val)->cspName).value))
  239. return 0;
  240. if (!ASN1DEREncBitString(enc, 0x3, ((val)->signature).length, ((val)->signature).value))
  241. return 0;
  242. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  243. return 0;
  244. return 1;
  245. }
  246. static int ASN1CALL ASN1Dec_CSPProvider(ASN1decoding_t dec, ASN1uint32_t tag, CSPProvider *val)
  247. {
  248. ASN1decoding_t dd;
  249. ASN1octet_t *di;
  250. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  251. return 0;
  252. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->keySpec))
  253. return 0;
  254. if (!ASN1BERDecChar16String(dd, 0x1e, &(val)->cspName))
  255. return 0;
  256. if (!ASN1BERDecBitString2(dd, 0x3, &(val)->signature))
  257. return 0;
  258. if (!ASN1BERDecEndOfContents(dec, dd, di))
  259. return 0;
  260. return 1;
  261. }
  262. static void ASN1CALL ASN1Free_CSPProvider(CSPProvider *val)
  263. {
  264. if (val) {
  265. ASN1char16string_free(&(val)->cspName);
  266. }
  267. }
  268. static int ASN1CALL ASN1Enc_EnrollmentNameValuePair(ASN1encoding_t enc, ASN1uint32_t tag, EnrollmentNameValuePair *val)
  269. {
  270. ASN1uint32_t nLenOff;
  271. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  272. return 0;
  273. if (!ASN1DEREncChar16String(enc, 0x1e, ((val)->name).length, ((val)->name).value))
  274. return 0;
  275. if (!ASN1DEREncChar16String(enc, 0x1e, ((val)->value).length, ((val)->value).value))
  276. return 0;
  277. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  278. return 0;
  279. return 1;
  280. }
  281. static int ASN1CALL ASN1Dec_EnrollmentNameValuePair(ASN1decoding_t dec, ASN1uint32_t tag, EnrollmentNameValuePair *val)
  282. {
  283. ASN1decoding_t dd;
  284. ASN1octet_t *di;
  285. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  286. return 0;
  287. if (!ASN1BERDecChar16String(dd, 0x1e, &(val)->name))
  288. return 0;
  289. if (!ASN1BERDecChar16String(dd, 0x1e, &(val)->value))
  290. return 0;
  291. if (!ASN1BERDecEndOfContents(dec, dd, di))
  292. return 0;
  293. return 1;
  294. }
  295. static void ASN1CALL ASN1Free_EnrollmentNameValuePair(EnrollmentNameValuePair *val)
  296. {
  297. if (val) {
  298. ASN1char16string_free(&(val)->name);
  299. ASN1char16string_free(&(val)->value);
  300. }
  301. }
  302. static int ASN1CALL ASN1Enc_Extensions(ASN1encoding_t enc, ASN1uint32_t tag, Extensions *val)
  303. {
  304. ASN1uint32_t nLenOff;
  305. ASN1uint32_t i;
  306. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  307. return 0;
  308. for (i = 0; i < (val)->count; i++) {
  309. if (!ASN1Enc_Extension(enc, 0, &((val)->value)[i]))
  310. return 0;
  311. }
  312. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  313. return 0;
  314. return 1;
  315. }
  316. static int ASN1CALL ASN1Dec_Extensions(ASN1decoding_t dec, ASN1uint32_t tag, Extensions *val)
  317. {
  318. ASN1decoding_t dd;
  319. ASN1octet_t *di;
  320. ASN1uint32_t t;
  321. ASN1uint32_t n;
  322. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  323. return 0;
  324. (val)->count = n = 0;
  325. (val)->value = NULL;
  326. while (ASN1BERDecNotEndOfContents(dd, di)) {
  327. if (!ASN1BERDecPeekTag(dd, &t))
  328. return 0;
  329. if ((val)->count >= n) {
  330. n = n ? (n << 1) : 16;
  331. (val)->value = (Extension *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  332. if (!(val)->value)
  333. return 0;
  334. }
  335. if (!ASN1Dec_Extension(dd, 0, &((val)->value)[(val)->count]))
  336. return 0;
  337. ((val)->count)++;
  338. }
  339. if (!ASN1BERDecEndOfContents(dec, dd, di))
  340. return 0;
  341. return 1;
  342. }
  343. static void ASN1CALL ASN1Free_Extensions(Extensions *val)
  344. {
  345. ASN1uint32_t i;
  346. if (val) {
  347. ASN1Free_Extension(&(val)->value[0]);
  348. for (i = 1; i < (val)->count; i++) {
  349. ASN1Free_Extension(&(val)->value[i]);
  350. }
  351. ASN1Free((val)->value);
  352. }
  353. }
  354. static int ASN1CALL ASN1Enc_Extension(ASN1encoding_t enc, ASN1uint32_t tag, Extension *val)
  355. {
  356. ASN1uint32_t nLenOff;
  357. ASN1octet_t o[1];
  358. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  359. return 0;
  360. CopyMemory(o, (val)->o, 1);
  361. if (!(val)->critical)
  362. o[0] &= ~0x80;
  363. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->extnId))
  364. return 0;
  365. if (o[0] & 0x80) {
  366. if (!ASN1BEREncBool(enc, 0x1, (val)->critical))
  367. return 0;
  368. }
  369. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->extnValue).length, ((val)->extnValue).value))
  370. return 0;
  371. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  372. return 0;
  373. return 1;
  374. }
  375. static int ASN1CALL ASN1Dec_Extension(ASN1decoding_t dec, ASN1uint32_t tag, Extension *val)
  376. {
  377. ASN1decoding_t dd;
  378. ASN1octet_t *di;
  379. ASN1uint32_t t;
  380. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  381. return 0;
  382. ZeroMemory((val)->o, 1);
  383. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->extnId))
  384. return 0;
  385. ASN1BERDecPeekTag(dd, &t);
  386. if (t == 0x1) {
  387. (val)->o[0] |= 0x80;
  388. if (!ASN1BERDecBool(dd, 0x1, &(val)->critical))
  389. return 0;
  390. }
  391. if (!ASN1BERDecOctetString2(dd, 0x4, &(val)->extnValue))
  392. return 0;
  393. if (!((val)->o[0] & 0x80))
  394. (val)->critical = 0;
  395. if (!ASN1BERDecEndOfContents(dec, dd, di))
  396. return 0;
  397. return 1;
  398. }
  399. static void ASN1CALL ASN1Free_Extension(Extension *val)
  400. {
  401. if (val) {
  402. }
  403. }
  404. static int ASN1CALL ASN1Enc_AttributeSetValue(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValue *val)
  405. {
  406. ASN1uint32_t nLenOff;
  407. void *pBlk;
  408. ASN1uint32_t i;
  409. ASN1encoding_t enc2;
  410. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  411. return 0;
  412. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  413. return 0;
  414. for (i = 0; i < (val)->count; i++) {
  415. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  416. return 0;
  417. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  418. return 0;
  419. if (!ASN1DEREncFlushBlkElement(pBlk))
  420. return 0;
  421. }
  422. if (!ASN1DEREncEndBlk(pBlk))
  423. return 0;
  424. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  425. return 0;
  426. return 1;
  427. }
  428. static int ASN1CALL ASN1Dec_AttributeSetValue(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValue *val)
  429. {
  430. ASN1decoding_t dd;
  431. ASN1octet_t *di;
  432. ASN1uint32_t t;
  433. ASN1uint32_t n;
  434. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  435. return 0;
  436. (val)->count = n = 0;
  437. (val)->value = NULL;
  438. while (ASN1BERDecNotEndOfContents(dd, di)) {
  439. if (!ASN1BERDecPeekTag(dd, &t))
  440. return 0;
  441. if ((val)->count >= n) {
  442. n = n ? (n << 1) : 16;
  443. (val)->value = (NOCOPYANY *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  444. if (!(val)->value)
  445. return 0;
  446. }
  447. if (!ASN1BERDecOpenType2(dd, &((val)->value)[(val)->count]))
  448. return 0;
  449. ((val)->count)++;
  450. }
  451. if (!ASN1BERDecEndOfContents(dec, dd, di))
  452. return 0;
  453. return 1;
  454. }
  455. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val)
  456. {
  457. ASN1uint32_t i;
  458. if (val) {
  459. for (i = 1; i < (val)->count; i++) {
  460. }
  461. ASN1Free((val)->value);
  462. }
  463. }
  464. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val)
  465. {
  466. ASN1uint32_t nLenOff;
  467. void *pBlk;
  468. ASN1uint32_t i;
  469. ASN1encoding_t enc2;
  470. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  471. return 0;
  472. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  473. return 0;
  474. for (i = 0; i < (val)->count; i++) {
  475. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  476. return 0;
  477. if (!ASN1Enc_Attribute(enc2, 0, &((val)->value)[i]))
  478. return 0;
  479. if (!ASN1DEREncFlushBlkElement(pBlk))
  480. return 0;
  481. }
  482. if (!ASN1DEREncEndBlk(pBlk))
  483. return 0;
  484. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  485. return 0;
  486. return 1;
  487. }
  488. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val)
  489. {
  490. ASN1decoding_t dd;
  491. ASN1octet_t *di;
  492. ASN1uint32_t t;
  493. ASN1uint32_t n;
  494. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  495. return 0;
  496. (val)->count = n = 0;
  497. (val)->value = NULL;
  498. while (ASN1BERDecNotEndOfContents(dd, di)) {
  499. if (!ASN1BERDecPeekTag(dd, &t))
  500. return 0;
  501. if ((val)->count >= n) {
  502. n = n ? (n << 1) : 16;
  503. (val)->value = (Attribute *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  504. if (!(val)->value)
  505. return 0;
  506. }
  507. if (!ASN1Dec_Attribute(dd, 0, &((val)->value)[(val)->count]))
  508. return 0;
  509. ((val)->count)++;
  510. }
  511. if (!ASN1BERDecEndOfContents(dec, dd, di))
  512. return 0;
  513. return 1;
  514. }
  515. static void ASN1CALL ASN1Free_Attributes(Attributes *val)
  516. {
  517. ASN1uint32_t i;
  518. if (val) {
  519. ASN1Free_Attribute(&(val)->value[0]);
  520. for (i = 1; i < (val)->count; i++) {
  521. ASN1Free_Attribute(&(val)->value[i]);
  522. }
  523. ASN1Free((val)->value);
  524. }
  525. }
  526. static int ASN1CALL ASN1Enc_ControlSequence(ASN1encoding_t enc, ASN1uint32_t tag, ControlSequence *val)
  527. {
  528. ASN1uint32_t nLenOff;
  529. ASN1uint32_t i;
  530. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  531. return 0;
  532. for (i = 0; i < (val)->count; i++) {
  533. if (!ASN1Enc_TaggedAttribute(enc, 0, &((val)->value)[i]))
  534. return 0;
  535. }
  536. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  537. return 0;
  538. return 1;
  539. }
  540. static int ASN1CALL ASN1Dec_ControlSequence(ASN1decoding_t dec, ASN1uint32_t tag, ControlSequence *val)
  541. {
  542. ASN1decoding_t dd;
  543. ASN1octet_t *di;
  544. ASN1uint32_t t;
  545. ASN1uint32_t n;
  546. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  547. return 0;
  548. (val)->count = n = 0;
  549. (val)->value = NULL;
  550. while (ASN1BERDecNotEndOfContents(dd, di)) {
  551. if (!ASN1BERDecPeekTag(dd, &t))
  552. return 0;
  553. if ((val)->count >= n) {
  554. n = n ? (n << 1) : 16;
  555. (val)->value = (TaggedAttribute *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  556. if (!(val)->value)
  557. return 0;
  558. }
  559. if (!ASN1Dec_TaggedAttribute(dd, 0, &((val)->value)[(val)->count]))
  560. return 0;
  561. ((val)->count)++;
  562. }
  563. if (!ASN1BERDecEndOfContents(dec, dd, di))
  564. return 0;
  565. return 1;
  566. }
  567. static void ASN1CALL ASN1Free_ControlSequence(ControlSequence *val)
  568. {
  569. ASN1uint32_t i;
  570. if (val) {
  571. ASN1Free_TaggedAttribute(&(val)->value[0]);
  572. for (i = 1; i < (val)->count; i++) {
  573. ASN1Free_TaggedAttribute(&(val)->value[i]);
  574. }
  575. ASN1Free((val)->value);
  576. }
  577. }
  578. static int ASN1CALL ASN1Enc_ReqSequence(ASN1encoding_t enc, ASN1uint32_t tag, ReqSequence *val)
  579. {
  580. ASN1uint32_t nLenOff;
  581. ASN1uint32_t i;
  582. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  583. return 0;
  584. for (i = 0; i < (val)->count; i++) {
  585. if (!ASN1Enc_TaggedRequest(enc, 0, &((val)->value)[i]))
  586. return 0;
  587. }
  588. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  589. return 0;
  590. return 1;
  591. }
  592. static int ASN1CALL ASN1Dec_ReqSequence(ASN1decoding_t dec, ASN1uint32_t tag, ReqSequence *val)
  593. {
  594. ASN1decoding_t dd;
  595. ASN1octet_t *di;
  596. ASN1uint32_t t;
  597. ASN1uint32_t n;
  598. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  599. return 0;
  600. (val)->count = n = 0;
  601. (val)->value = NULL;
  602. while (ASN1BERDecNotEndOfContents(dd, di)) {
  603. if (!ASN1BERDecPeekTag(dd, &t))
  604. return 0;
  605. if ((val)->count >= n) {
  606. n = n ? (n << 1) : 16;
  607. (val)->value = (TaggedRequest *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  608. if (!(val)->value)
  609. return 0;
  610. }
  611. if (!ASN1Dec_TaggedRequest(dd, 0, &((val)->value)[(val)->count]))
  612. return 0;
  613. ((val)->count)++;
  614. }
  615. if (!ASN1BERDecEndOfContents(dec, dd, di))
  616. return 0;
  617. return 1;
  618. }
  619. static void ASN1CALL ASN1Free_ReqSequence(ReqSequence *val)
  620. {
  621. ASN1uint32_t i;
  622. if (val) {
  623. ASN1Free_TaggedRequest(&(val)->value[0]);
  624. for (i = 1; i < (val)->count; i++) {
  625. ASN1Free_TaggedRequest(&(val)->value[i]);
  626. }
  627. ASN1Free((val)->value);
  628. }
  629. }
  630. static int ASN1CALL ASN1Enc_CmsSequence(ASN1encoding_t enc, ASN1uint32_t tag, CmsSequence *val)
  631. {
  632. ASN1uint32_t nLenOff;
  633. ASN1uint32_t i;
  634. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  635. return 0;
  636. for (i = 0; i < (val)->count; i++) {
  637. if (!ASN1Enc_TaggedContentInfo(enc, 0, &((val)->value)[i]))
  638. return 0;
  639. }
  640. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  641. return 0;
  642. return 1;
  643. }
  644. static int ASN1CALL ASN1Dec_CmsSequence(ASN1decoding_t dec, ASN1uint32_t tag, CmsSequence *val)
  645. {
  646. ASN1decoding_t dd;
  647. ASN1octet_t *di;
  648. ASN1uint32_t t;
  649. ASN1uint32_t n;
  650. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  651. return 0;
  652. (val)->count = n = 0;
  653. (val)->value = NULL;
  654. while (ASN1BERDecNotEndOfContents(dd, di)) {
  655. if (!ASN1BERDecPeekTag(dd, &t))
  656. return 0;
  657. if ((val)->count >= n) {
  658. n = n ? (n << 1) : 16;
  659. (val)->value = (TaggedContentInfo *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  660. if (!(val)->value)
  661. return 0;
  662. }
  663. if (!ASN1Dec_TaggedContentInfo(dd, 0, &((val)->value)[(val)->count]))
  664. return 0;
  665. ((val)->count)++;
  666. }
  667. if (!ASN1BERDecEndOfContents(dec, dd, di))
  668. return 0;
  669. return 1;
  670. }
  671. static void ASN1CALL ASN1Free_CmsSequence(CmsSequence *val)
  672. {
  673. ASN1uint32_t i;
  674. if (val) {
  675. ASN1Free_TaggedContentInfo(&(val)->value[0]);
  676. for (i = 1; i < (val)->count; i++) {
  677. ASN1Free_TaggedContentInfo(&(val)->value[i]);
  678. }
  679. ASN1Free((val)->value);
  680. }
  681. }
  682. static int ASN1CALL ASN1Enc_OtherMsgSequence(ASN1encoding_t enc, ASN1uint32_t tag, OtherMsgSequence *val)
  683. {
  684. ASN1uint32_t nLenOff;
  685. ASN1uint32_t i;
  686. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  687. return 0;
  688. for (i = 0; i < (val)->count; i++) {
  689. if (!ASN1Enc_TaggedOtherMsg(enc, 0, &((val)->value)[i]))
  690. return 0;
  691. }
  692. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  693. return 0;
  694. return 1;
  695. }
  696. static int ASN1CALL ASN1Dec_OtherMsgSequence(ASN1decoding_t dec, ASN1uint32_t tag, OtherMsgSequence *val)
  697. {
  698. ASN1decoding_t dd;
  699. ASN1octet_t *di;
  700. ASN1uint32_t t;
  701. ASN1uint32_t n;
  702. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  703. return 0;
  704. (val)->count = n = 0;
  705. (val)->value = NULL;
  706. while (ASN1BERDecNotEndOfContents(dd, di)) {
  707. if (!ASN1BERDecPeekTag(dd, &t))
  708. return 0;
  709. if ((val)->count >= n) {
  710. n = n ? (n << 1) : 16;
  711. (val)->value = (TaggedOtherMsg *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  712. if (!(val)->value)
  713. return 0;
  714. }
  715. if (!ASN1Dec_TaggedOtherMsg(dd, 0, &((val)->value)[(val)->count]))
  716. return 0;
  717. ((val)->count)++;
  718. }
  719. if (!ASN1BERDecEndOfContents(dec, dd, di))
  720. return 0;
  721. return 1;
  722. }
  723. static void ASN1CALL ASN1Free_OtherMsgSequence(OtherMsgSequence *val)
  724. {
  725. ASN1uint32_t i;
  726. if (val) {
  727. ASN1Free_TaggedOtherMsg(&(val)->value[0]);
  728. for (i = 1; i < (val)->count; i++) {
  729. ASN1Free_TaggedOtherMsg(&(val)->value[i]);
  730. }
  731. ASN1Free((val)->value);
  732. }
  733. }
  734. static int ASN1CALL ASN1Enc_BodyPartIDSequence(ASN1encoding_t enc, ASN1uint32_t tag, BodyPartIDSequence *val)
  735. {
  736. ASN1uint32_t nLenOff;
  737. ASN1uint32_t i;
  738. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  739. return 0;
  740. for (i = 0; i < (val)->count; i++) {
  741. if (!ASN1BEREncU32(enc, 0x2, ((val)->value)[i]))
  742. return 0;
  743. }
  744. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  745. return 0;
  746. return 1;
  747. }
  748. static int ASN1CALL ASN1Dec_BodyPartIDSequence(ASN1decoding_t dec, ASN1uint32_t tag, BodyPartIDSequence *val)
  749. {
  750. ASN1decoding_t dd;
  751. ASN1octet_t *di;
  752. ASN1uint32_t t;
  753. ASN1uint32_t n;
  754. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  755. return 0;
  756. (val)->count = n = 0;
  757. (val)->value = NULL;
  758. while (ASN1BERDecNotEndOfContents(dd, di)) {
  759. if (!ASN1BERDecPeekTag(dd, &t))
  760. return 0;
  761. if ((val)->count >= n) {
  762. n = n ? (n << 1) : 16;
  763. (val)->value = (BodyPartID *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value));
  764. if (!(val)->value)
  765. return 0;
  766. }
  767. if (!ASN1BERDecU32Val(dd, 0x2, (ASN1uint32_t *) &((val)->value)[(val)->count]))
  768. return 0;
  769. ((val)->count)++;
  770. }
  771. if (!ASN1BERDecEndOfContents(dec, dd, di))
  772. return 0;
  773. return 1;
  774. }
  775. static void ASN1CALL ASN1Free_BodyPartIDSequence(BodyPartIDSequence *val)
  776. {
  777. if (val) {
  778. ASN1Free((val)->value);
  779. }
  780. }
  781. static int ASN1CALL ASN1Enc_TaggedAttribute(ASN1encoding_t enc, ASN1uint32_t tag, TaggedAttribute *val)
  782. {
  783. ASN1uint32_t nLenOff;
  784. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  785. return 0;
  786. if (!ASN1BEREncU32(enc, 0x2, (val)->bodyPartID))
  787. return 0;
  788. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->type))
  789. return 0;
  790. if (!ASN1Enc_AttributeSetValue(enc, 0, &(val)->values))
  791. return 0;
  792. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  793. return 0;
  794. return 1;
  795. }
  796. static int ASN1CALL ASN1Dec_TaggedAttribute(ASN1decoding_t dec, ASN1uint32_t tag, TaggedAttribute *val)
  797. {
  798. ASN1decoding_t dd;
  799. ASN1octet_t *di;
  800. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  801. return 0;
  802. if (!ASN1BERDecU32Val(dd, 0x2, (ASN1uint32_t *) &(val)->bodyPartID))
  803. return 0;
  804. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->type))
  805. return 0;
  806. if (!ASN1Dec_AttributeSetValue(dd, 0, &(val)->values))
  807. return 0;
  808. if (!ASN1BERDecEndOfContents(dec, dd, di))
  809. return 0;
  810. return 1;
  811. }
  812. static void ASN1CALL ASN1Free_TaggedAttribute(TaggedAttribute *val)
  813. {
  814. if (val) {
  815. ASN1Free_AttributeSetValue(&(val)->values);
  816. }
  817. }
  818. static int ASN1CALL ASN1Enc_TaggedCertificationRequest(ASN1encoding_t enc, ASN1uint32_t tag, TaggedCertificationRequest *val)
  819. {
  820. ASN1uint32_t nLenOff;
  821. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  822. return 0;
  823. if (!ASN1BEREncU32(enc, 0x2, (val)->bodyPartID))
  824. return 0;
  825. if (!ASN1BEREncOpenType(enc, &(val)->certificationRequest))
  826. return 0;
  827. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  828. return 0;
  829. return 1;
  830. }
  831. static int ASN1CALL ASN1Dec_TaggedCertificationRequest(ASN1decoding_t dec, ASN1uint32_t tag, TaggedCertificationRequest *val)
  832. {
  833. ASN1decoding_t dd;
  834. ASN1octet_t *di;
  835. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  836. return 0;
  837. if (!ASN1BERDecU32Val(dd, 0x2, (ASN1uint32_t *) &(val)->bodyPartID))
  838. return 0;
  839. if (!ASN1BERDecOpenType2(dd, &(val)->certificationRequest))
  840. return 0;
  841. if (!ASN1BERDecEndOfContents(dec, dd, di))
  842. return 0;
  843. return 1;
  844. }
  845. static void ASN1CALL ASN1Free_TaggedCertificationRequest(TaggedCertificationRequest *val)
  846. {
  847. if (val) {
  848. }
  849. }
  850. static int ASN1CALL ASN1Enc_TaggedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, TaggedContentInfo *val)
  851. {
  852. ASN1uint32_t nLenOff;
  853. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  854. return 0;
  855. if (!ASN1BEREncU32(enc, 0x2, (val)->bodyPartID))
  856. return 0;
  857. if (!ASN1BEREncOpenType(enc, &(val)->contentInfo))
  858. return 0;
  859. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  860. return 0;
  861. return 1;
  862. }
  863. static int ASN1CALL ASN1Dec_TaggedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, TaggedContentInfo *val)
  864. {
  865. ASN1decoding_t dd;
  866. ASN1octet_t *di;
  867. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  868. return 0;
  869. if (!ASN1BERDecU32Val(dd, 0x2, (ASN1uint32_t *) &(val)->bodyPartID))
  870. return 0;
  871. if (!ASN1BERDecOpenType2(dd, &(val)->contentInfo))
  872. return 0;
  873. if (!ASN1BERDecEndOfContents(dec, dd, di))
  874. return 0;
  875. return 1;
  876. }
  877. static void ASN1CALL ASN1Free_TaggedContentInfo(TaggedContentInfo *val)
  878. {
  879. if (val) {
  880. }
  881. }
  882. static int ASN1CALL ASN1Enc_TaggedOtherMsg(ASN1encoding_t enc, ASN1uint32_t tag, TaggedOtherMsg *val)
  883. {
  884. ASN1uint32_t nLenOff;
  885. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  886. return 0;
  887. if (!ASN1BEREncU32(enc, 0x2, (val)->bodyPartID))
  888. return 0;
  889. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->otherMsgType))
  890. return 0;
  891. if (!ASN1BEREncOpenType(enc, &(val)->otherMsgValue))
  892. return 0;
  893. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  894. return 0;
  895. return 1;
  896. }
  897. static int ASN1CALL ASN1Dec_TaggedOtherMsg(ASN1decoding_t dec, ASN1uint32_t tag, TaggedOtherMsg *val)
  898. {
  899. ASN1decoding_t dd;
  900. ASN1octet_t *di;
  901. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  902. return 0;
  903. if (!ASN1BERDecU32Val(dd, 0x2, (ASN1uint32_t *) &(val)->bodyPartID))
  904. return 0;
  905. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->otherMsgType))
  906. return 0;
  907. if (!ASN1BERDecOpenType2(dd, &(val)->otherMsgValue))
  908. return 0;
  909. if (!ASN1BERDecEndOfContents(dec, dd, di))
  910. return 0;
  911. return 1;
  912. }
  913. static void ASN1CALL ASN1Free_TaggedOtherMsg(TaggedOtherMsg *val)
  914. {
  915. if (val) {
  916. }
  917. }
  918. static int ASN1CALL ASN1Enc_PendInfo(ASN1encoding_t enc, ASN1uint32_t tag, PendInfo *val)
  919. {
  920. ASN1uint32_t nLenOff;
  921. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  922. return 0;
  923. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->pendToken).length, ((val)->pendToken).value))
  924. return 0;
  925. if (!ASN1DEREncGeneralizedTime(enc, 0x18, &(val)->pendTime))
  926. return 0;
  927. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  928. return 0;
  929. return 1;
  930. }
  931. static int ASN1CALL ASN1Dec_PendInfo(ASN1decoding_t dec, ASN1uint32_t tag, PendInfo *val)
  932. {
  933. ASN1decoding_t dd;
  934. ASN1octet_t *di;
  935. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  936. return 0;
  937. if (!ASN1BERDecOctetString2(dd, 0x4, &(val)->pendToken))
  938. return 0;
  939. if (!ASN1BERDecGeneralizedTime(dd, 0x18, &(val)->pendTime))
  940. return 0;
  941. if (!ASN1BERDecEndOfContents(dec, dd, di))
  942. return 0;
  943. return 1;
  944. }
  945. static void ASN1CALL ASN1Free_PendInfo(PendInfo *val)
  946. {
  947. if (val) {
  948. }
  949. }
  950. static int ASN1CALL ASN1Enc_CmcAddExtensions(ASN1encoding_t enc, ASN1uint32_t tag, CmcAddExtensions *val)
  951. {
  952. ASN1uint32_t nLenOff;
  953. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  954. return 0;
  955. if (!ASN1BEREncU32(enc, 0x2, (val)->pkiDataReference))
  956. return 0;
  957. if (!ASN1Enc_BodyPartIDSequence(enc, 0, &(val)->certReferences))
  958. return 0;
  959. if (!ASN1Enc_Extensions(enc, 0, &(val)->extensions))
  960. return 0;
  961. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  962. return 0;
  963. return 1;
  964. }
  965. static int ASN1CALL ASN1Dec_CmcAddExtensions(ASN1decoding_t dec, ASN1uint32_t tag, CmcAddExtensions *val)
  966. {
  967. ASN1decoding_t dd;
  968. ASN1octet_t *di;
  969. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  970. return 0;
  971. if (!ASN1BERDecU32Val(dd, 0x2, (ASN1uint32_t *) &(val)->pkiDataReference))
  972. return 0;
  973. if (!ASN1Dec_BodyPartIDSequence(dd, 0, &(val)->certReferences))
  974. return 0;
  975. if (!ASN1Dec_Extensions(dd, 0, &(val)->extensions))
  976. return 0;
  977. if (!ASN1BERDecEndOfContents(dec, dd, di))
  978. return 0;
  979. return 1;
  980. }
  981. static void ASN1CALL ASN1Free_CmcAddExtensions(CmcAddExtensions *val)
  982. {
  983. if (val) {
  984. ASN1Free_BodyPartIDSequence(&(val)->certReferences);
  985. ASN1Free_Extensions(&(val)->extensions);
  986. }
  987. }
  988. static int ASN1CALL ASN1Enc_CmcAddAttributes(ASN1encoding_t enc, ASN1uint32_t tag, CmcAddAttributes *val)
  989. {
  990. ASN1uint32_t nLenOff;
  991. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  992. return 0;
  993. if (!ASN1BEREncU32(enc, 0x2, (val)->pkiDataReference))
  994. return 0;
  995. if (!ASN1Enc_BodyPartIDSequence(enc, 0, &(val)->certReferences))
  996. return 0;
  997. if (!ASN1Enc_Attributes(enc, 0, &(val)->attributes))
  998. return 0;
  999. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1000. return 0;
  1001. return 1;
  1002. }
  1003. static int ASN1CALL ASN1Dec_CmcAddAttributes(ASN1decoding_t dec, ASN1uint32_t tag, CmcAddAttributes *val)
  1004. {
  1005. ASN1decoding_t dd;
  1006. ASN1octet_t *di;
  1007. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1008. return 0;
  1009. if (!ASN1BERDecU32Val(dd, 0x2, (ASN1uint32_t *) &(val)->pkiDataReference))
  1010. return 0;
  1011. if (!ASN1Dec_BodyPartIDSequence(dd, 0, &(val)->certReferences))
  1012. return 0;
  1013. if (!ASN1Dec_Attributes(dd, 0, &(val)->attributes))
  1014. return 0;
  1015. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1016. return 0;
  1017. return 1;
  1018. }
  1019. static void ASN1CALL ASN1Free_CmcAddAttributes(CmcAddAttributes *val)
  1020. {
  1021. if (val) {
  1022. ASN1Free_BodyPartIDSequence(&(val)->certReferences);
  1023. ASN1Free_Attributes(&(val)->attributes);
  1024. }
  1025. }
  1026. static int ASN1CALL ASN1Enc_CmcStatusInfo_otherInfo(ASN1encoding_t enc, ASN1uint32_t tag, CmcStatusInfo_otherInfo *val)
  1027. {
  1028. switch ((val)->choice) {
  1029. case 1:
  1030. if (!ASN1BEREncU32(enc, 0x2, (val)->u.failInfo))
  1031. return 0;
  1032. break;
  1033. case 2:
  1034. if (!ASN1Enc_PendInfo(enc, 0, &(val)->u.pendInfo))
  1035. return 0;
  1036. break;
  1037. }
  1038. return 1;
  1039. UNREFERENCED_PARAMETER(tag);
  1040. }
  1041. static int ASN1CALL ASN1Dec_CmcStatusInfo_otherInfo(ASN1decoding_t dec, ASN1uint32_t tag, CmcStatusInfo_otherInfo *val)
  1042. {
  1043. ASN1uint32_t t;
  1044. if (!ASN1BERDecPeekTag(dec, &t))
  1045. return 0;
  1046. switch (t) {
  1047. case 0x2:
  1048. (val)->choice = 1;
  1049. if (!ASN1BERDecU32Val(dec, 0x2, (ASN1uint32_t *) &(val)->u.failInfo))
  1050. return 0;
  1051. break;
  1052. case 0x10:
  1053. (val)->choice = 2;
  1054. if (!ASN1Dec_PendInfo(dec, 0, &(val)->u.pendInfo))
  1055. return 0;
  1056. break;
  1057. default:
  1058. ASN1DecSetError(dec, ASN1_ERR_CORRUPT);
  1059. return 0;
  1060. }
  1061. return 1;
  1062. UNREFERENCED_PARAMETER(tag);
  1063. }
  1064. static void ASN1CALL ASN1Free_CmcStatusInfo_otherInfo(CmcStatusInfo_otherInfo *val)
  1065. {
  1066. if (val) {
  1067. switch ((val)->choice) {
  1068. case 2:
  1069. ASN1Free_PendInfo(&(val)->u.pendInfo);
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val)
  1075. {
  1076. ASN1uint32_t nLenOff;
  1077. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1078. return 0;
  1079. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->type))
  1080. return 0;
  1081. if (!ASN1Enc_AttributeSetValue(enc, 0, &(val)->values))
  1082. return 0;
  1083. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1084. return 0;
  1085. return 1;
  1086. }
  1087. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val)
  1088. {
  1089. ASN1decoding_t dd;
  1090. ASN1octet_t *di;
  1091. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1092. return 0;
  1093. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->type))
  1094. return 0;
  1095. if (!ASN1Dec_AttributeSetValue(dd, 0, &(val)->values))
  1096. return 0;
  1097. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1098. return 0;
  1099. return 1;
  1100. }
  1101. static void ASN1CALL ASN1Free_Attribute(Attribute *val)
  1102. {
  1103. if (val) {
  1104. ASN1Free_AttributeSetValue(&(val)->values);
  1105. }
  1106. }
  1107. static int ASN1CALL ASN1Enc_CmcData(ASN1encoding_t enc, ASN1uint32_t tag, CmcData *val)
  1108. {
  1109. ASN1uint32_t nLenOff;
  1110. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1111. return 0;
  1112. if (!ASN1Enc_ControlSequence(enc, 0, &(val)->controlSequence))
  1113. return 0;
  1114. if (!ASN1Enc_ReqSequence(enc, 0, &(val)->reqSequence))
  1115. return 0;
  1116. if (!ASN1Enc_CmsSequence(enc, 0, &(val)->cmsSequence))
  1117. return 0;
  1118. if (!ASN1Enc_OtherMsgSequence(enc, 0, &(val)->otherMsgSequence))
  1119. return 0;
  1120. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1121. return 0;
  1122. return 1;
  1123. }
  1124. static int ASN1CALL ASN1Dec_CmcData(ASN1decoding_t dec, ASN1uint32_t tag, CmcData *val)
  1125. {
  1126. ASN1decoding_t dd;
  1127. ASN1octet_t *di;
  1128. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1129. return 0;
  1130. if (!ASN1Dec_ControlSequence(dd, 0, &(val)->controlSequence))
  1131. return 0;
  1132. if (!ASN1Dec_ReqSequence(dd, 0, &(val)->reqSequence))
  1133. return 0;
  1134. if (!ASN1Dec_CmsSequence(dd, 0, &(val)->cmsSequence))
  1135. return 0;
  1136. if (!ASN1Dec_OtherMsgSequence(dd, 0, &(val)->otherMsgSequence))
  1137. return 0;
  1138. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1139. return 0;
  1140. return 1;
  1141. }
  1142. static void ASN1CALL ASN1Free_CmcData(CmcData *val)
  1143. {
  1144. if (val) {
  1145. ASN1Free_ControlSequence(&(val)->controlSequence);
  1146. ASN1Free_ReqSequence(&(val)->reqSequence);
  1147. ASN1Free_CmsSequence(&(val)->cmsSequence);
  1148. ASN1Free_OtherMsgSequence(&(val)->otherMsgSequence);
  1149. }
  1150. }
  1151. static int ASN1CALL ASN1Enc_CmcResponseBody(ASN1encoding_t enc, ASN1uint32_t tag, CmcResponseBody *val)
  1152. {
  1153. ASN1uint32_t nLenOff;
  1154. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1155. return 0;
  1156. if (!ASN1Enc_ControlSequence(enc, 0, &(val)->controlSequence))
  1157. return 0;
  1158. if (!ASN1Enc_CmsSequence(enc, 0, &(val)->cmsSequence))
  1159. return 0;
  1160. if (!ASN1Enc_OtherMsgSequence(enc, 0, &(val)->otherMsgSequence))
  1161. return 0;
  1162. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1163. return 0;
  1164. return 1;
  1165. }
  1166. static int ASN1CALL ASN1Dec_CmcResponseBody(ASN1decoding_t dec, ASN1uint32_t tag, CmcResponseBody *val)
  1167. {
  1168. ASN1decoding_t dd;
  1169. ASN1octet_t *di;
  1170. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1171. return 0;
  1172. if (!ASN1Dec_ControlSequence(dd, 0, &(val)->controlSequence))
  1173. return 0;
  1174. if (!ASN1Dec_CmsSequence(dd, 0, &(val)->cmsSequence))
  1175. return 0;
  1176. if (!ASN1Dec_OtherMsgSequence(dd, 0, &(val)->otherMsgSequence))
  1177. return 0;
  1178. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1179. return 0;
  1180. return 1;
  1181. }
  1182. static void ASN1CALL ASN1Free_CmcResponseBody(CmcResponseBody *val)
  1183. {
  1184. if (val) {
  1185. ASN1Free_ControlSequence(&(val)->controlSequence);
  1186. ASN1Free_CmsSequence(&(val)->cmsSequence);
  1187. ASN1Free_OtherMsgSequence(&(val)->otherMsgSequence);
  1188. }
  1189. }
  1190. static int ASN1CALL ASN1Enc_TaggedRequest(ASN1encoding_t enc, ASN1uint32_t tag, TaggedRequest *val)
  1191. {
  1192. switch ((val)->choice) {
  1193. case 1:
  1194. if (!ASN1Enc_TaggedCertificationRequest(enc, 0x80000000, &(val)->u.tcr))
  1195. return 0;
  1196. break;
  1197. }
  1198. return 1;
  1199. UNREFERENCED_PARAMETER(tag);
  1200. }
  1201. static int ASN1CALL ASN1Dec_TaggedRequest(ASN1decoding_t dec, ASN1uint32_t tag, TaggedRequest *val)
  1202. {
  1203. ASN1uint32_t t;
  1204. if (!ASN1BERDecPeekTag(dec, &t))
  1205. return 0;
  1206. switch (t) {
  1207. case 0x80000000:
  1208. (val)->choice = 1;
  1209. if (!ASN1Dec_TaggedCertificationRequest(dec, 0x80000000, &(val)->u.tcr))
  1210. return 0;
  1211. break;
  1212. default:
  1213. ASN1DecSetError(dec, ASN1_ERR_CORRUPT);
  1214. return 0;
  1215. }
  1216. return 1;
  1217. UNREFERENCED_PARAMETER(tag);
  1218. }
  1219. static void ASN1CALL ASN1Free_TaggedRequest(TaggedRequest *val)
  1220. {
  1221. if (val) {
  1222. switch ((val)->choice) {
  1223. case 1:
  1224. ASN1Free_TaggedCertificationRequest(&(val)->u.tcr);
  1225. break;
  1226. }
  1227. }
  1228. }
  1229. static int ASN1CALL ASN1Enc_CmcStatusInfo(ASN1encoding_t enc, ASN1uint32_t tag, CmcStatusInfo *val)
  1230. {
  1231. ASN1uint32_t nLenOff;
  1232. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1233. return 0;
  1234. if (!ASN1BEREncU32(enc, 0x2, (val)->cmcStatus))
  1235. return 0;
  1236. if (!ASN1Enc_BodyPartIDSequence(enc, 0, &(val)->bodyList))
  1237. return 0;
  1238. if ((val)->o[0] & 0x80) {
  1239. if (!ASN1DEREncUTF8String(enc, 0xc, ((val)->statusString).length, ((val)->statusString).value))
  1240. return 0;
  1241. }
  1242. if ((val)->o[0] & 0x40) {
  1243. if (!ASN1Enc_CmcStatusInfo_otherInfo(enc, 0, &(val)->otherInfo))
  1244. return 0;
  1245. }
  1246. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1247. return 0;
  1248. return 1;
  1249. }
  1250. static int ASN1CALL ASN1Dec_CmcStatusInfo(ASN1decoding_t dec, ASN1uint32_t tag, CmcStatusInfo *val)
  1251. {
  1252. ASN1decoding_t dd;
  1253. ASN1octet_t *di;
  1254. ASN1uint32_t t;
  1255. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1256. return 0;
  1257. ZeroMemory((val)->o, 1);
  1258. if (!ASN1BERDecU32Val(dd, 0x2, (ASN1uint32_t *) &(val)->cmcStatus))
  1259. return 0;
  1260. if (!ASN1Dec_BodyPartIDSequence(dd, 0, &(val)->bodyList))
  1261. return 0;
  1262. ASN1BERDecPeekTag(dd, &t);
  1263. if (t == 0xc) {
  1264. (val)->o[0] |= 0x80;
  1265. if (!ASN1BERDecUTF8String(dd, 0xc, &(val)->statusString))
  1266. return 0;
  1267. }
  1268. ASN1BERDecPeekTag(dd, &t);
  1269. if (t == 0x2 || t == 0x10) {
  1270. (val)->o[0] |= 0x40;
  1271. if (!ASN1Dec_CmcStatusInfo_otherInfo(dd, 0, &(val)->otherInfo))
  1272. return 0;
  1273. }
  1274. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1275. return 0;
  1276. return 1;
  1277. }
  1278. static void ASN1CALL ASN1Free_CmcStatusInfo(CmcStatusInfo *val)
  1279. {
  1280. if (val) {
  1281. ASN1Free_BodyPartIDSequence(&(val)->bodyList);
  1282. if ((val)->o[0] & 0x80) {
  1283. ASN1utf8string_free(&(val)->statusString);
  1284. }
  1285. if ((val)->o[0] & 0x40) {
  1286. ASN1Free_CmcStatusInfo_otherInfo(&(val)->otherInfo);
  1287. }
  1288. }
  1289. }